chat_template.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from pydantic import BaseModel, Field
  2. from typing import List, Dict, Optional, Any, Union
  3. from typing_extensions import Literal # Import Literal from typing_extensions for stricter typing
  4. class Query(BaseModel):
  5. """
  6. Query class represents the input structure for performing various actions.
  7. Attributes:
  8. messages (List[Dict[str, Union[str, Any]]]): A list of dictionaries where each dictionary
  9. represents a message containing 'role' and 'content' or other key-value pairs.
  10. tools (Optional[List[Dict[str, Any]]]): An optional list of JSON-like objects (dictionaries)
  11. representing tools and their parameters. Default is an empty list.
  12. action_type (Literal): A string that must be one of "message_llm", "call_tool", or "operate_file".
  13. This restricts the type of action the query performs.
  14. message_return_type (str): The type of the response message. Default is "text".
  15. """
  16. messages: List[Dict[str, Union[str, Any]]] # List of message dictionaries, each containing role and content.
  17. tools: Optional[List[Dict[str, Any]]] = Field(default_factory=list) # List of JSON-like objects (dictionaries) representing tools.
  18. action_type: Literal["message_llm", "call_tool", "operate_file"] = Field(default="message_llm") # Restrict the action_type to specific choices.
  19. message_return_type: str = Field(default="text") # Type of the return message, default is "text".
  20. class Config:
  21. arbitrary_types_allowed = True # Allows the use of arbitrary types such as Any and Dict.
  22. class Response(BaseModel):
  23. """
  24. Response class represents the output structure after performing actions.
  25. Attributes:
  26. response_message (Optional[str]): The generated response message. Default is None.
  27. tool_calls (Optional[List[Dict[str, Any]]]): An optional list of JSON-like objects (dictionaries)
  28. representing the tool calls made during processing. Default is None.
  29. """
  30. response_message: Optional[str] = None # The generated response message, default is None.
  31. tool_calls: Optional[List[Dict[str, Any]]] = None # List of JSON-like objects representing tool calls, default is None.
  32. class Config:
  33. arbitrary_types_allowed = True # Allows arbitrary types in validation.