mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(token_counter): tolerate non-dictionary property schemas
This commit is contained in:
parent
bf81334046
commit
78f9b5f0cc
2 changed files with 19 additions and 0 deletions
|
|
@ -970,6 +970,8 @@ def _format_object_parameters(parameters, indent):
|
|||
required_params: Final = parameters.get("required", [])
|
||||
lines: Final = []
|
||||
for key, props in properties.items():
|
||||
if not isinstance(props, dict):
|
||||
continue
|
||||
description = props.get("description")
|
||||
if description:
|
||||
lines.append(f"// {description}")
|
||||
|
|
|
|||
|
|
@ -99,3 +99,20 @@ def test_token_counter_tool_array_schema_without_items():
|
|||
messages = [{"role": "user", "content": "Hello"}]
|
||||
tokens = token_counter(model="gpt-3.5-turbo", messages=messages, tools=tools)
|
||||
assert tokens > 0
|
||||
|
||||
|
||||
def test_token_counter_tool_non_dict_property_schema():
|
||||
"""Test that malformed string-valued property schemas do not crash token counting (#40344)."""
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "f",
|
||||
"description": "d",
|
||||
"parameters": {"type": "object", "properties": {"s": "string"}},
|
||||
},
|
||||
}
|
||||
]
|
||||
messages = [{"role": "user", "content": "Hello"}]
|
||||
tokens = token_counter(model="gpt-3.5-turbo", messages=messages, tools=tools)
|
||||
assert tokens > 0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue