forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tool_converter.py
More file actions
54 lines (38 loc) · 1.67 KB
/
test_tool_converter.py
File metadata and controls
54 lines (38 loc) · 1.67 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from pydantic import BaseModel
from agents import Agent, Handoff, function_tool, handoff
from agents.exceptions import UserError
from agents.models.chatcmpl_converter import Converter
from agents.tool import FileSearchTool, WebSearchTool
def some_function(a: str, b: list[int]) -> str:
return "hello"
def test_to_openai_with_function_tool():
some_function(a="foo", b=[1, 2, 3])
tool = function_tool(some_function)
result = Converter.tool_to_openai(tool)
assert result["type"] == "function"
assert result["function"]["name"] == "some_function"
params = result.get("function", {}).get("parameters")
assert params is not None
properties = params.get("properties", {})
assert isinstance(properties, dict)
assert properties.keys() == {"a", "b"}
class Foo(BaseModel):
a: str
b: list[int]
def test_convert_handoff_tool():
agent = Agent(name="test_1", handoff_description="test_2")
handoff_obj = handoff(agent=agent)
result = Converter.convert_handoff_tool(handoff_obj)
assert result["type"] == "function"
assert result["function"]["name"] == Handoff.default_tool_name(agent)
assert result["function"].get("description") == Handoff.default_tool_description(agent)
params = result.get("function", {}).get("parameters")
assert params is not None
for key, value in handoff_obj.input_json_schema.items():
assert params[key] == value
def test_tool_converter_hosted_tools_errors():
with pytest.raises(UserError):
Converter.tool_to_openai(WebSearchTool())
with pytest.raises(UserError):
Converter.tool_to_openai(FileSearchTool(vector_store_ids=["abc"], max_num_results=1))