Skip to content

Commit

Permalink
Merge pull request #679 from mmikita95/chore-type-assist-function-defs
Browse files Browse the repository at this point in the history
chore: add a TypedDict to parameters definition
  • Loading branch information
ramedina86 authored Dec 16, 2024
2 parents a953ee9 + 00244b1 commit 3baf732
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/writer/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,31 @@ class GraphTool(Tool):
subqueries: bool


class FunctionToolParameterMeta(TypedDict):
type: Union[
Literal["string"],
Literal["number"],
Literal["integer"],
Literal["float"],
Literal["boolean"],
Literal["array"],
Literal["object"],
Literal["null"]
]
description: str


class FunctionTool(Tool):
callable: Callable
name: str
description: Optional[str]
parameters: Dict[str, Dict[str, str]]
parameters: Dict[str, FunctionToolParameterMeta]


def create_function_tool(
callable: Callable,
name: str,
parameters: Optional[Dict[str, Dict[str, str]]] = None,
parameters: Optional[Dict[str, FunctionToolParameterMeta]] = None,
description: Optional[str] = None
) -> FunctionTool:
parameters = parameters or {}
Expand Down Expand Up @@ -1196,7 +1210,7 @@ def _register_callable(
self,
callable_to_register: Callable,
name: str,
parameters: Dict[str, Dict[str, str]]
parameters: Dict[str, FunctionToolParameterMeta]
):
"""
Internal helper function to store a provided callable
Expand Down Expand Up @@ -1266,7 +1280,9 @@ def _prepare_tool(
Internal helper function to process a tool instance
into the required format.
"""
def validate_parameters(parameters: Dict[str, Dict[str, str]]) -> bool:
def validate_parameters(
parameters: Dict[str, FunctionToolParameterMeta]
) -> bool:
"""
Validates the `parameters` dictionary to ensure that each key
is a parameter name, and each value is a dictionary containing
Expand Down

0 comments on commit 3baf732

Please sign in to comment.