Skip to content

Commit 53b9419

Browse files
fix: cannot have keywords {'description'}. #3001 (#3041)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 5c7baea commit 53b9419

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

camel/toolkits/function_tool.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ def _create_mol(name, field):
156156
if (name := param.arg_name) in parameters_dict["properties"] and (
157157
description := param.description
158158
):
159-
parameters_dict["properties"][name]["description"] = description
159+
# OpenAI does not allow descriptions on properties that use $ref.
160+
# To avoid schema errors, we only add the description if "$ref" is
161+
# not present.
162+
prop = parameters_dict["properties"][name]
163+
if "$ref" not in prop:
164+
prop["description"] = description
160165

161166
short_description = docstring.short_description or ""
162167
long_description = docstring.long_description or ""

test/toolkits/test_openai_function.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ def test_all_parameters(
160160
'type': 'string',
161161
'description': 'datatime_para desc',
162162
},
163-
'default_enum_para': {
164-
'$ref': '#/$defs/RoleType',
165-
'description': 'default_enum_para desc',
166-
},
163+
'default_enum_para': {'$ref': '#/$defs/RoleType'},
167164
},
168165
'required': [
169166
'any_para',

0 commit comments

Comments
 (0)