o
    c۷i                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 G dd de	Z
G dd	 d	eeZG d
d deeZG dd de	ZG dd de	ZG dd de	ZededZdS )    N)Enum)AnyTypeVar)field_validator)MistralBasec                   @   sB   e Zd ZU dZeed< dZeed< eeef ed< dZ	e
ed< dS )	Functiona  Function definition for tools.

    Attributes:
        name: The name of the function.
        description: A description of what the function does.
        parameters: The parameters the functions accepts, described as a JSON Schema object.
        strict: Whether to enforce strict function calling.

    Examples:
        >>> function = Function(
        ...     name="get_current_weather",
        ...     description="Get the current weather in a given location",
        ...     parameters={
        ...         "type": "object",
        ...         "properties": {
        ...             "location": {
        ...                 "type": "string",
        ...                 "description": "The city and state, e.g. San Francisco, CA",
        ...             },
        ...             "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
        ...         },
        ...         "required": ["location"],
        ...     },
        ... )
    name description
parametersFstrictN)__name__
__module____qualname____doc__str__annotations__r
   dictr   r   bool r   r   a/home/ubuntu/vllm_env/lib/python3.10/site-packages/mistral_common/protocol/instruct/tool_calls.pyr   
   s   
 r   c                   @   s   e Zd ZdZdZdS )	ToolTypeszEnum of tool types.

    Attributes:
       function: A function tool.

    Examples:
        >>> tool_type = ToolTypes.function
    functionN)r   r   r   r   r   r   r   r   r   r   +   s    	r   c                   @   s   e Zd ZdZdZdZdZdS )
ToolChoicezEnum of tool choice types.

    Attributes:
        auto: Automatically choose the tool.
        none: Do not use any tools.
        any: Use any tool.

    Examples:
        >>> tool_choice = ToolChoice.auto
    autononeanyN)r   r   r   r   r   r   r   r   r   r   r   r   8   s
    r   c                   @   s\   e Zd ZU dZejZeed< eed< de	e
ef fddZede	e
ef dd fdd	Zd
S )Toolaj  Tool definition.

    Attributes:
        type: The type of the tool.
        function: The function definition.

    Examples:
        >>> tool = Tool(
        ...     function=Function(
        ...         name="get_current_weather",
        ...         description="Get the current weather in a given location",
        ...         parameters={
        ...             "type": "object",
        ...             "properties": {
        ...                 "location": {
        ...                     "type": "string",
        ...                     "description": "The city and state, e.g. San Francisco, CA",
        ...                 },
        ...                 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
        ...             },
        ...             "required": ["location"],
        ...         },
        ...     ),
        ... )
    typer   returnc                 C      |   S N
model_dumpselfr   r   r   	to_openaig      zTool.to_openaiopenai_toolc                 C   s
   |  |S r!   )model_validate)clsr(   r   r   r   from_openaij   s   
zTool.from_openaiN)r   r   r   r   r   r   r   r   r   r   r   r   r&   classmethodr+   r   r   r   r   r   I   s   
  r   c                   @   sL   e Zd ZU dZeed< eed< eddddeeeef B defdd	Z	d
S )FunctionCallaQ  Function call.

    Attributes:
        name: The name of the function to call.
        arguments: The arguments to pass to the function.

    Examples:
        >>> function_call = FunctionCall(
        ...     name="get_current_weather",
        ...     arguments={"location": "San Francisco, CA", "unit": "celsius"},
        ... )
    r   	argumentsbefore)modevr   c                 C   s   t |tr
t|S |S )zConvert arguments to a JSON string if they are a dictionary.

        Args:
            v: The arguments to validate.

        Returns:
            The arguments as a JSON string.
        )
isinstancer   jsondumps)r*   r1   r   r   r   validate_arguments   s   


zFunctionCall.validate_argumentsN)
r   r   r   r   r   r   r   r   r   r5   r   r   r   r   r-   o   s   
 
$r-   c                   @   sh   e Zd ZU dZdZeed< ejZ	eed< e
ed< deeef fddZed	eeef dd fd
dZdS )ToolCalla  Tool call.

    Attributes:
        id: The ID of the tool call. Required for V3+ tokenization
        type: The type of the tool call.
        function: The function call.

    Examples:
        >>> tool_call = ToolCall(
        ...     id="call_abc123",
        ...     function=FunctionCall(
        ...         name="get_current_weather",
        ...         arguments={"location": "San Francisco, CA", "unit": "celsius"},
        ...     ),
        ... )
    nullidr   r   r   c                 C   r    r!   r"   r$   r   r   r   r&      r'   zToolCall.to_openai	tool_callc                 C   s   t |}|dd  | |S )Nindex)r   popr)   )r*   r9   openai_tool_callr   r   r   r+      s   
zToolCall.from_openaiN)r   r   r   r   r8   r   r   r   r   r   r-   r   r   r&   r,   r+   r   r   r   r   r6      s   
  r6   ToolType)bound)r3   enumr   typingr   r   pydanticr   mistral_common.baser   r   r   r   r   r   r-   r6   r=   r   r   r   r   <module>   s    !& !