class_docstr: Enables text generation using HuggingFace Hub hosted chat-based LLMs. This component is designed to seamlessly
  inference chat-based models deployed on the Text Generation Inference (TGI) backend.
  
  You can use this component for chat LLMs hosted on Hugging Face inference endpoints, the rate-limited
  Inference API tier:
  
  ```python
  from haystack.components.generators.chat import HuggingFaceTGIChatGenerator
  from haystack.dataclasses import ChatMessage
  
  messages = [ChatMessage.from_system("\nYou are a helpful, respectful and honest assistant"),
              ChatMessage.from_user("What's Natural Language Processing?")]
  
  
  client = HuggingFaceTGIChatGenerator(model="meta-llama/Llama-2-70b-chat-hf", token="<your-token>")
  client.warm_up()
  response = client.run(messages, generation_kwargs={"max_new_tokens": 120})
  print(response)
  ```
  
  For chat LLMs hosted on paid https://huggingface.co/inference-endpoints endpoint and/or your own custom TGI
  endpoint, you'll need to provide the URL of the endpoint as well as a valid token:
  
  ```python
  from haystack.components.generators.chat import HuggingFaceTGIChatGenerator
  from haystack.dataclasses import ChatMessage
  
  messages = [ChatMessage.from_system("\nYou are a helpful, respectful and honest assistant"),
              ChatMessage.from_user("What's Natural Language Processing?")]
  
  client = HuggingFaceTGIChatGenerator(model="meta-llama/Llama-2-70b-chat-hf",
                                       url="<your-tgi-endpoint-url>",
                                       token="<your-token>")
  client.warm_up()
  response = client.run(messages, generation_kwargs={"max_new_tokens": 120})
  print(response)
  ```
  
   Key Features and Compatibility:
       - **Primary Compatibility**: Designed to work seamlessly with any chat-based 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 chat LLMs hosted on the rate-limited Inference
         API tier. Learn more about the Inference API at https://huggingface.co/inference-api.
         Discover available chat models using the following command:
         ```
         wget -qO- https://api-inference.huggingface.co/framework/text-generation-inference | grep chat
         ```
         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 TGI chat 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:
       - **ChatMessage Format**: This component uses the ChatMessage format to structure both input and output,
         ensuring coherent and contextually relevant responses in chat-based text generation scenarios. Details on the
         ChatMessage format can be found at https://github.com/openai/openai-python/blob/main/chatml.md.
class_docstr_tok: ["Enables","text","generation","using","HuggingFace","Hub","hosted","chat-based","LLMs",".","This","component","is","designed","to","seamlessly","inference","chat-based","models","deployed","on","the","Text","Generation","Inference","(","TGI",")","backend",".","You","can","use","this","component","for","chat","LLMs","hosted","on","Hugging","Face","inference","endpoints",",","the","rate-limited","Inference","API","tier",":","``","`","python","from","haystack.components.generators.chat","import","HuggingFaceTGIChatGenerator","from","haystack.dataclasses","import","ChatMessage","messages","=","[","ChatMessage.from_system","(","``","\\nYou","are","a","helpful",",","respectful","and","honest","assistant","''",")",",","ChatMessage.from_user","(","``","What","'s","Natural","Language","Processing","?","''",")","]","client","=","HuggingFaceTGIChatGenerator","(","model=","''","meta-llama\/Llama-2-70b-chat-hf","''",",","token=","''","<","your-token",">","''",")","client.warm_up","(",")","response","=","client.run","(","messages",",","generation_kwargs=","{","``","max_new_tokens","''",":","120","}",")","print","(","response",")","``","`","For","chat","LLMs","hosted","on","paid","https",":","\/\/huggingface.co\/inference-endpoints","endpoint","and\/or","your","own","custom","TGI","endpoint",",","you","'ll","need","to","provide","the","URL","of","the","endpoint","as","well","as","a","valid","token",":","``","`","python","from","haystack.components.generators.chat","import","HuggingFaceTGIChatGenerator","from","haystack.dataclasses","import","ChatMessage","messages","=","[","ChatMessage.from_system","(","``","\\nYou","are","a","helpful",",","respectful","and","honest","assistant","''",")",",","ChatMessage.from_user","(","``","What","'s","Natural","Language","Processing","?","''",")","]","client","=","HuggingFaceTGIChatGenerator","(","model=","''","meta-llama\/Llama-2-70b-chat-hf","''",",","url=","''","<","your-tgi-endpoint-url",">","''",",","token=","''","<","your-token",">","''",")","client.warm_up","(",")","response","=","client.run","(","messages",",","generation_kwargs=","{","``","max_new_tokens","''",":","120","}",")","print","(","response",")","``","`","Key","Features","and","Compatibility",":","-","*","*","Primary","Compatibility","*","*",":","Designed","to","work","seamlessly","with","any","chat-based","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","chat","LLMs","hosted","on","the","rate-limited","Inference","API","tier",".","Learn","more","about","the","Inference","API","at","https",":","\/\/huggingface.co\/inference-api",".","Discover","available","chat","models","using","the","following","command",":","``","`","wget","-qO-","https",":","\/\/api-inference.huggingface.co\/framework\/text-generation-inference","|","grep","chat","``","`","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","TGI","chat","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",":","-","*","*","ChatMessage","Format","*","*",":","This","component","uses","the","ChatMessage","format","to","structure","both","input","and","output",",","ensuring","coherent","and","contextually","relevant","responses","in","chat-based","text","generation","scenarios",".","Details","on","the","ChatMessage","format","can","be","found","at","https",":","\/\/github.com\/openai\/openai-python\/blob\/main\/chatml.md","."]
docstr: Data that is sent to Posthog for usage analytics.
docstr_tok: ["Data","that","is","sent","to","Posthog","for","usage","analytics","."]
code: def _get_telemetry_data(self) -> Dict[str, Any]:
      """
      Data that is sent to Posthog for usage analytics.
      """
      # Don't send URL as it is sensitive information
      return {"model": self.model}
  
file_path: haystack/haystack/components/generators/chat/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 ChatMessage, StreamingChunk
  from haystack.components.generators.hf_utils import check_valid_model, check_generation_params
  from haystack.lazy_imports import LazyImport
label_desc: Use image node_id 5 for calling the HuggingFaceTGIChatGenerator obj's underlying member method code with example usage: obj._get_telemetry_data() and returns: dict