from typing import *
from pydantic import BaseModel
from typing import List, Dict, Optional


__all__ = [
    "ToolParameters",
    "ToolFunction",
    "ToolItem",
    "Function",
]


class ToolParameters(BaseModel):
    """"""
    type: str = "object"
    properties: Dict[str, Dict]
    required: List[str]


class ToolFunction(BaseModel):
    """"""
    name: str
    description: str
    parameters: ToolParameters


class ToolItem(BaseModel):
    type: str = "function"
    function: ToolFunction


class Function(BaseModel):
    arguments: Optional[Union[str, Dict]] = None
    """
    The arguments to call the function with, as generated by the model in JSON
    format. Note that the model does not always generate valid JSON, and may
    hallucinate parameters not defined by your function schema. Validate the
    arguments in your code before calling your function.
    """

    name: str
    """The name of the function to call."""

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        if isinstance(self.arguments, str):
            self.arguments = eval(self.arguments)
