mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
Merge bf81334046 into 9071ca503e
This commit is contained in:
commit
e6e13c7004
2 changed files with 30 additions and 5 deletions
|
|
@ -998,8 +998,10 @@ def _format_type(props, indent):
|
|||
return " | ".join([f'"{item}"' for item in props["enum"]])
|
||||
return "string"
|
||||
elif type == "array":
|
||||
# items is required, OpenAI throws an error if it's missing
|
||||
return f"{_format_type(props['items'], indent)}[]"
|
||||
items = props.get("items")
|
||||
if isinstance(items, dict):
|
||||
return f"{_format_type(items, indent)}[]"
|
||||
return "any[]"
|
||||
elif type == "object":
|
||||
return f"{{\n{_format_object_parameters(props, indent + 2)}\n}}"
|
||||
elif type in ["integer", "number"]:
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ def test_token_counter_tool_increases(messages):
|
|||
conversation.append(message)
|
||||
tokens = token_counter(model="gpt-3.5-turbo", messages=conversation, tools=TOOLS) # type: ignore
|
||||
print(f"tokens: {tokens}")
|
||||
assert (
|
||||
tokens > prev_tokens
|
||||
), f"Token did not increase: {tokens} <= {prev_tokens}"
|
||||
assert tokens > prev_tokens, f"Token did not increase: {tokens} <= {prev_tokens}"
|
||||
prev_tokens = tokens
|
||||
|
||||
|
||||
|
|
@ -76,3 +74,28 @@ def assertGrow(usermessage, tool_call, assertBiggerThanBoth=True):
|
|||
f"tokens_usermessage: {tokens_usermessage}, tokens_tool_call: {tokens_tool_call}, "
|
||||
+ f"tokens_both: {tokens_both} diff: {tokens_usermessage + tokens_tool_call - tokens_both}"
|
||||
)
|
||||
|
||||
|
||||
def test_token_counter_tool_array_schema_without_items():
|
||||
"""Test that tool array schema without 'items' property does not crash token counting (#40344)."""
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "search_data",
|
||||
"description": "Search for data",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"description": "List of tags",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
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