-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_pydantic_ai.py
28 lines (19 loc) · 1.13 KB
/
test_pydantic_ai.py
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
28
import pytest
from thirdweb_ai.tools.tool import Tool
def test_get_pydantic_ai_tools(test_tools: list[Tool]):
"""Test converting thirdweb tools to Pydantic AI tools."""
pytest.importorskip("pydantic_ai")
from pydantic_ai import Tool as PydanticTool # type: ignore[import]
from thirdweb_ai.adapters.pydantic_ai import get_pydantic_ai_tools
# Convert tools to Pydantic AI tools
pydantic_ai_tools = get_pydantic_ai_tools(test_tools)
# Assert we got the correct number of tools
assert len(pydantic_ai_tools) == len(test_tools)
# Check all tools were properly converted
assert all(isinstance(tool, PydanticTool) for tool in pydantic_ai_tools)
# Check properties were preserved
assert [tool.name for tool in pydantic_ai_tools] == [tool.name for tool in test_tools]
assert [tool.description for tool in pydantic_ai_tools] == [tool.description for tool in test_tools]
# Check all tools have function and prepare methods
assert all(callable(getattr(tool, "function", None)) for tool in pydantic_ai_tools)
assert all(callable(getattr(tool, "prepare", None)) for tool in pydantic_ai_tools)