stopping criteria for TextGenerationPipeline
Author: geronimi73
Pull request: no

### Feature request

pass stopping criteria or string to TextGenerationPipeline

### Motivation

it does not exist, have not found any way to do it at least, but would be _very_ useful

### Your contribution

none

Comments:
Hey! You can pass `generation_kwargs` to the pipeline, which are usually used for stopping criteria such as `max_length, max_new_tokens, max_time` . You can also pass some `stopping_criteria` argument to the generate function using `generation_kwargs = {stopping_criteria = StoppingCriteriaList: [MaxTimeCriteria(32)] }.

```python
from transformers import pipeline, StoppingCriteriaList, MaxTimeCriteria

# Initialize the text generation pipeline
generator = pipeline("text-generation")

# Define the stopping criteria using MaxTimeCriteria
stopping_criteria = StoppingCriteriaList([MaxTimeCriteria(32)])

# Define the generation_kwargs with stopping criteria
generation_kwargs = {
    "max_length": 100,  # Maximum length of the generated text
    "max_new_tokens": 10,  # Maximum number of new tokens to generate
    "generation_kwargs": {"stopping_criteria": stopping_criteria}  # Add stopping criteria to generation_kwargs
}

# Pass the generation_kwargs to the pipeline
generated_text = generator(
    "Hey!  How are you able.",
    **generation_kwargs
)

# Print the generated text
print(generated_text[0]["generated_text"])
>>> Hey!  How are you able.  Do you have a job or do you have
```

This should probably be added to the documentation! 

cc @MKhalusova who is currently working on the `generate` docs!

The `max_length` and `max_new_tokens` are mentioned in nearly every doc on text generation:
- https://huggingface.co/docs/transformers/llm_tutorial#generated-output-is-too-shortlong
- https://huggingface.co/docs/transformers/generation_strategies#customize-text-generation
- https://huggingface.co/docs/transformers/main_classes/text_generation
- upcoming [LLM prompting doc](https://github.com/huggingface/transformers/pull/26274) as well

However, I see a couple of issues: 
- the `MaxTimeCriteria` is much less discoverable, as it is only mentioned in the [Utilities for Generation](https://huggingface.co/docs/transformers/internal/generation_utils#transformers.StoppingCriteria). 
- A more critical issue from my point of view is the lack of connection between the pipeline documentation and the text generation docs. The [`TextGenerationPipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TextGenerationPipeline) API doc lists parameters that control how pipeline is instantiated, but doesn't link to text generation docs. 

I can address these. 


Is this a duplicate of #17562?

If so, it seems the only reason that older issue is still open is because of the missing documentation. If the documentation is fixed then both can be closed.

According to my experiments, setting
```python
generation_kwargs = {
    "max_new_tokens": 1000,  # Maximum number of new tokens to generate
    "generation_kwargs": {"stopping_criteria": stopping_criteria}  # Add stopping criteria to generation_kwargs
}
``` 
is not feasible for passing a stopping criteria into a pipeline. Instead, if we let "stopping_criteria" out of "generation_kwargs", it then works well. As below:

```python
generation_kwargs = {
    "max_new_tokens": 1000,  # Maximum number of new tokens to generate
    "stopping_criteria": stopping_criteria,
}
```