mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
Merge 46ded8bb53 into 3746ba58d7
This commit is contained in:
commit
cd18c9e405
2 changed files with 35 additions and 2 deletions
|
|
@ -3746,14 +3746,18 @@ def _remove_strict_from_schema(schema):
|
|||
"""
|
||||
Relevant Issues: https://github.com/BerriAI/litellm/issues/6136, https://github.com/BerriAI/litellm/issues/6088
|
||||
"""
|
||||
schema_map_keys = {"properties", "patternProperties", "$defs", "definitions"}
|
||||
if isinstance(schema, dict):
|
||||
# Remove the 'additionalProperties' key if it exists and is set to False
|
||||
if "strict" in schema:
|
||||
del schema["strict"]
|
||||
|
||||
# Recursively process all dictionary values
|
||||
for key, value in schema.items():
|
||||
_remove_strict_from_schema(value)
|
||||
if key in schema_map_keys and isinstance(value, dict):
|
||||
for prop_schema in value.values():
|
||||
_remove_strict_from_schema(prop_schema)
|
||||
else:
|
||||
_remove_strict_from_schema(value)
|
||||
|
||||
elif isinstance(schema, list):
|
||||
# Recursively process all items in the list
|
||||
|
|
|
|||
|
|
@ -45,6 +45,35 @@ def reset_mock_cache():
|
|||
_model_cache.flush_cache()
|
||||
|
||||
|
||||
def test_remove_strict_from_schema_preserves_property_named_strict():
|
||||
from litellm.utils import _remove_strict_from_schema
|
||||
|
||||
schema = {
|
||||
"type": "object",
|
||||
"strict": True,
|
||||
"properties": {
|
||||
"strict": {"type": "boolean"},
|
||||
"field": {"type": "string", "strict": True},
|
||||
},
|
||||
"patternProperties": {
|
||||
"strict": {"type": "number", "strict": True},
|
||||
},
|
||||
"$defs": {
|
||||
"strict": {"type": "object", "strict": True},
|
||||
},
|
||||
"required": ["strict", "field"],
|
||||
}
|
||||
|
||||
result = _remove_strict_from_schema(schema)
|
||||
|
||||
assert "strict" not in result
|
||||
assert result["properties"]["strict"] == {"type": "boolean"}
|
||||
assert result["properties"]["field"] == {"type": "string"}
|
||||
assert result["patternProperties"]["strict"] == {"type": "number"}
|
||||
assert result["$defs"]["strict"] == {"type": "object"}
|
||||
assert result["required"] == ["strict", "field"]
|
||||
|
||||
|
||||
# Test 1: Check trimming of normal message
|
||||
def test_basic_trimming():
|
||||
litellm._turn_on_debug()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue