class_docstr: Enables text generation using HuggingFace Hub hosted non-chat LLMs. This component is designed to seamlessly
  inference models deployed on the Text Generation Inference (TGI) backend.
  
  You can use this component for LLMs hosted on Hugging Face inference endpoints, the rate-limited
  Inference API tier:
  
  ```python
  from haystack.components.generators import HuggingFaceTGIGenerator
  client = HuggingFaceTGIGenerator(model="mistralai/Mistral-7B-v0.1", token="<your-token>")
  client.warm_up()
  response = client.run("What's Natural Language Processing?", max_new_tokens=120)
  print(response)
  ```
  
  Or for LLMs hosted on paid https://huggingface.co/inference-endpoints endpoint, and/or your own custom TGI endpoint.
  In these two cases, you'll need to provide the URL of the endpoint as well as a valid token:
  
  ```python
  from haystack.components.generators import HuggingFaceTGIGenerator
  client = HuggingFaceTGIGenerator(model="mistralai/Mistral-7B-v0.1",
                                   url="<your-tgi-endpoint-url>",
                                   token="<your-token>")
  client.warm_up()
  response = client.run("What's Natural Language Processing?")
  print(response)
  ```
  
  
   Key Features and Compatibility:
       - **Primary Compatibility**: Designed to work seamlessly with any non-chat model deployed using the TGI
         framework. For more information on TGI, visit https://github.com/huggingface/text-generation-inference.
       - **Hugging Face Inference Endpoints**: Supports inference of TGI chat LLMs deployed on Hugging Face
         inference endpoints. For more details refer to https://huggingface.co/inference-endpoints.
       - **Inference API Support**: Supports inference of TGI LLMs hosted on the rate-limited Inference
         API tier. Learn more about the Inference API at: https://huggingface.co/inference-api
         Discover available LLMs using the following command:
         ```
         wget -qO- https://api-inference.huggingface.co/framework/text-generation-inference
         ```
         And simply use the model ID as the model parameter for this component. You'll also need to provide a valid
         Hugging Face API token as the token parameter.
       - **Custom TGI Endpoints**: Supports inference of LLMs deployed on custom TGI endpoints. Anyone can
         deploy their own TGI endpoint using the TGI framework. For more details refer
         to https://huggingface.co/inference-endpoints.
   Input and Output Format:
       - **String Format**: This component uses the str format for structuring both input and output,
         ensuring coherent and contextually relevant responses in text generation scenarios.
class_docstr_tok: ["Enables","text","generation","using","HuggingFace","Hub","hosted","non-chat","LLMs",".","This","component","is","designed","to","seamlessly","inference","models","deployed","on","the","Text","Generation","Inference","(","TGI",")","backend",".","You","can","use","this","component","for","LLMs","hosted","on","Hugging","Face","inference","endpoints",",","the","rate-limited","Inference","API","tier",":","``","`","python","from","haystack.components.generators","import","HuggingFaceTGIGenerator","client","=","HuggingFaceTGIGenerator","(","model=","''","mistralai\/Mistral-7B-v0.1","''",",","token=","''","<","your-token",">","''",")","client.warm_up","(",")","response","=","client.run","(","``","What","'s","Natural","Language","Processing","?","``",",","max_new_tokens=120",")","print","(","response",")","``","`","Or","for","LLMs","hosted","on","paid","https",":","\/\/huggingface.co\/inference-endpoints","endpoint",",","and\/or","your","own","custom","TGI","endpoint",".","In","these","two","cases",",","you","'ll","need","to","provide","the","URL","of","the","endpoint","as","well","as","a","valid","token",":","``","`","python","from","haystack.components.generators","import","HuggingFaceTGIGenerator","client","=","HuggingFaceTGIGenerator","(","model=","''","mistralai\/Mistral-7B-v0.1","''",",","url=","''","<","your-tgi-endpoint-url",">","''",",","token=","''","<","your-token",">","''",")","client.warm_up","(",")","response","=","client.run","(","``","What","'s","Natural","Language","Processing","?","''",")","print","(","response",")","``","`","Key","Features","and","Compatibility",":","-","*","*","Primary","Compatibility","*","*",":","Designed","to","work","seamlessly","with","any","non-chat","model","deployed","using","the","TGI","framework",".","For","more","information","on","TGI",",","visit","https",":","\/\/github.com\/huggingface\/text-generation-inference",".","-","*","*","Hugging","Face","Inference","Endpoints","*","*",":","Supports","inference","of","TGI","chat","LLMs","deployed","on","Hugging","Face","inference","endpoints",".","For","more","details","refer","to","https",":","\/\/huggingface.co\/inference-endpoints",".","-","*","*","Inference","API","Support","*","*",":","Supports","inference","of","TGI","LLMs","hosted","on","the","rate-limited","Inference","API","tier",".","Learn","more","about","the","Inference","API","at",":","https",":","\/\/huggingface.co\/inference-api","Discover","available","LLMs","using","the","following","command",":","``","`","wget","-qO-","https",":","\/\/api-inference.huggingface.co\/framework\/text-generation-inference","``","`","And","simply","use","the","model","ID","as","the","model","parameter","for","this","component",".","You","'ll","also","need","to","provide","a","valid","Hugging","Face","API","token","as","the","token","parameter",".","-","*","*","Custom","TGI","Endpoints","*","*",":","Supports","inference","of","LLMs","deployed","on","custom","TGI","endpoints",".","Anyone","can","deploy","their","own","TGI","endpoint","using","the","TGI","framework",".","For","more","details","refer","to","https",":","\/\/huggingface.co\/inference-endpoints",".","Input","and","Output","Format",":","-","*","*","String","Format","*","*",":","This","component","uses","the","str","format","for","structuring","both","input","and","output",",","ensuring","coherent","and","contextually","relevant","responses","in","text","generation","scenarios","."]
docstr: Deserialize this component from a dictionary.
docstr_tok: ["Deserialize","this","component","from","a","dictionary","."]
code: def from_dict(cls, data: Dict[str, Any]) -> "HuggingFaceTGIGenerator":
      """
      Deserialize this component from a dictionary.
      """
      init_params = data.get("init_parameters", {})
      serialized_callback_handler = init_params.get(
          "streaming_callback"
      )
      if serialized_callback_handler:
          data["init_parameters"][
              "streaming_callback"
          ] = deserialize_callback_handler(serialized_callback_handler)
      return default_from_dict(cls, data)
  
file_path: haystack/haystack/components/generators/hugging_face_tgi.py
imports: import logging
  from dataclasses import asdict
  from typing import Any, Dict, List, Optional, Iterable, Callable
  from urllib.parse import urlparse
  from haystack import component, default_to_dict, default_from_dict
  from haystack.components.generators.utils import serialize_callback_handler, deserialize_callback_handler
  from haystack.dataclasses import StreamingChunk
  from haystack.components.generators.hf_utils import check_generation_params, check_valid_model
  from haystack.lazy_imports import LazyImport
label_desc: Use image node_id 4 for calling the HuggingFaceTGIGenerator obj's underlying member method code with example usage: obj.from_dict(cls, data) and returns: default_from_dict