Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: remove unsupported keywords from pydantic schema #29611

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions libs/core/langchain_core/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@
"bool": "boolean",
}

UNSUPPORTED_OPENAI_KEYWORDS = {
"title",
"minLength",
"maxLength",
"pattern",
"format",
"minimum",
"maximum",
"multipleOf",
"patternProperties",
"unevaluatedProperties",
"propertyNames",
"minProperties",
"maxProperties",
"unevaluatedItems",
"contains",
"minContains",
"maxContains",
"minItems",
"maxItems",
"uniqueItems",
}


class FunctionDescription(TypedDict):
"""Representation of a callable function to send to an LLM."""
Expand All @@ -63,8 +86,12 @@ class ToolDescription(TypedDict):
def _rm_titles(kv: dict, prev_key: str = "") -> dict:
new_kv = {}
for k, v in kv.items():
if k == "title":
if isinstance(v, dict) and prev_key == "properties" and "title" in v:
if k in UNSUPPORTED_OPENAI_KEYWORDS:
if (
isinstance(v, dict)
and prev_key == "properties"
and len(UNSUPPORTED_OPENAI_KEYWORDS & v.keys()) > 0
):
new_kv[k] = _rm_titles(v, k)
else:
continue
Expand Down
5 changes: 0 additions & 5 deletions libs/core/tests/unit_tests/utils/test_function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,6 @@ class Tool(typed_dict):
"type": "object",
"additionalProperties": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{"type": "array", "items": {}},
{
Expand Down Expand Up @@ -829,8 +827,6 @@ class Tool(typed_dict):
},
"arg8": {
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": [
{
"title": "SubTool",
Expand Down Expand Up @@ -888,7 +884,6 @@ class Tool(typed_dict):
}
},
},
"uniqueItems": True,
},
"arg12": {
"type": "object",
Expand Down
Loading