-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpydantic_ai.py
More file actions
27 lines (21 loc) · 898 Bytes
/
pydantic_ai.py
File metadata and controls
27 lines (21 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import Any
from pydantic_ai import RunContext
from pydantic_ai import Tool as PydanticTool
from pydantic_ai.tools import ToolDefinition
from thirdweb_ai import Tool
def get_pydantic_ai_tools(tools: list[Tool]) -> list[PydanticTool]:
def _get_tool(tool: Tool):
async def execute(**kwargs: Any) -> Any:
return tool.run_json(kwargs)
async def prepare(ctx: RunContext, tool_def: ToolDefinition) -> ToolDefinition:
if "parameters" not in tool.schema:
raise ValueError("Tool schema must contain 'parameters'.")
tool_def.parameters_json_schema = tool.schema["parameters"]
return tool_def
return PydanticTool(
function=execute,
prepare=prepare,
name=tool.name,
description=tool.description,
)
return [_get_tool(tool) for tool in tools]