mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 17:08:47 +00:00
core[patch]: fix empty OpenAI tools when strict=True (#26287)
Fix #26232 --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
d87feb1b04
commit
feb351737c
@ -605,9 +605,13 @@ def _recursive_set_additional_properties_false(
|
|||||||
schema: Dict[str, Any],
|
schema: Dict[str, Any],
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
if isinstance(schema, dict):
|
if isinstance(schema, dict):
|
||||||
# Check if 'required' is a key at the current level
|
# Check if 'required' is a key at the current level or if the schema is empty,
|
||||||
if "required" in schema:
|
# in which case additionalProperties still needs to be specified.
|
||||||
|
if "required" in schema or (
|
||||||
|
"properties" in schema and not schema["properties"]
|
||||||
|
):
|
||||||
schema["additionalProperties"] = False
|
schema["additionalProperties"] = False
|
||||||
|
|
||||||
# Recursively check 'properties' and 'items' if they exist
|
# Recursively check 'properties' and 'items' if they exist
|
||||||
if "properties" in schema:
|
if "properties" in schema:
|
||||||
for value in schema["properties"].values():
|
for value in schema["properties"].values():
|
||||||
|
@ -793,3 +793,22 @@ def test_convert_union_type_py_39() -> None:
|
|||||||
assert result["parameters"]["properties"]["input"] == {
|
assert result["parameters"]["properties"]["input"] == {
|
||||||
"anyOf": [{"type": "integer"}, {"type": "number"}]
|
"anyOf": [{"type": "integer"}, {"type": "number"}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_convert_to_openai_function_no_args() -> None:
|
||||||
|
@tool
|
||||||
|
def empty_tool() -> str:
|
||||||
|
"""No args"""
|
||||||
|
return "foo"
|
||||||
|
|
||||||
|
actual = convert_to_openai_function(empty_tool, strict=True)
|
||||||
|
assert actual == {
|
||||||
|
"name": "empty_tool",
|
||||||
|
"description": "No args",
|
||||||
|
"parameters": {
|
||||||
|
"properties": {},
|
||||||
|
"additionalProperties": False,
|
||||||
|
"type": "object",
|
||||||
|
},
|
||||||
|
"strict": True,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user