Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: cannot have keywords {'description'}. #3001 (#3041)

Saed Bhati53b94194949f
diff --git a/camel/toolkits/function_tool.py b/camel/toolkits/function_tool.py
index c641b1861..8de871b71 100644
--- a/camel/toolkits/function_tool.py
+++ b/camel/toolkits/function_tool.py
@@ -156,7 +156,12 @@ def get_openai_tool_schema(func: Callable) -> Dict[str, Any]:
if (name := param.arg_name) in parameters_dict["properties"] and (
description := param.description
):
- parameters_dict["properties"][name]["description"] = description
+ # OpenAI does not allow descriptions on properties that use $ref.
+ # To avoid schema errors, we only add the description if "$ref" is
+ # not present.
+ prop = parameters_dict["properties"][name]
+ if "$ref" not in prop:
+ prop["description"] = description
short_description = docstring.short_description or ""
long_description = docstring.long_description or ""
diff --git a/test/toolkits/test_openai_function.py b/test/toolkits/test_openai_function.py
index 980de1420..2544ebe95 100644
--- a/test/toolkits/test_openai_function.py
+++ b/test/toolkits/test_openai_function.py
@@ -160,10 +160,7 @@ def test_get_openai_tool_schema():
'type': 'string',
'description': 'datatime_para desc',
},
- 'default_enum_para': {
- '$ref': '#/$defs/RoleType',
- 'description': 'default_enum_para desc',
- },
+ 'default_enum_para': {'$ref': '#/$defs/RoleType'},
},
'required': [
'any_para',