core[patch]: support labeled json schema as tools (#18935)

This commit is contained in:
Bagatur
2024-03-11 19:51:35 -07:00
committed by GitHub
parent 950ab056eb
commit 19721246f5
3 changed files with 49 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, List, Literal, Optional, Type
from typing import Any, Callable, Dict, List, Literal, Optional, Type
import pytest
@@ -49,8 +49,29 @@ def dummy_tool() -> BaseTool:
return DummyFunction()
@pytest.fixture()
def json_schema() -> Dict:
return {
"title": "dummy_function",
"description": "dummy function",
"type": "object",
"properties": {
"arg1": {"description": "foo", "type": "integer"},
"arg2": {
"description": "one of 'bar', 'baz'",
"enum": ["bar", "baz"],
"type": "string",
},
},
"required": ["arg1", "arg2"],
}
def test_convert_to_openai_function(
pydantic: Type[BaseModel], function: Callable, dummy_tool: BaseTool
pydantic: Type[BaseModel],
function: Callable,
dummy_tool: BaseTool,
json_schema: Dict,
) -> None:
expected = {
"name": "dummy_function",
@@ -69,7 +90,7 @@ def test_convert_to_openai_function(
},
}
for fn in (pydantic, function, dummy_tool, expected):
for fn in (pydantic, function, dummy_tool, json_schema, expected):
actual = convert_to_openai_function(fn) # type: ignore
assert actual == expected