mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-01 02:02:20 +00:00
fix(token_counter): guard None input_schema in Anthropic tool fallback
Use `or {}` instead of `.get(..., {})` so explicit null parameters do not
raise AttributeError when formatting function definitions for token counting.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
278242de84
commit
ac06e2f3b4
1 changed files with 7 additions and 2 deletions
|
|
@ -769,15 +769,20 @@ def _format_function_definitions(tools):
|
|||
function = tool.get("function")
|
||||
if function is None:
|
||||
# Anthropic tool shape → OpenAI function dict for token counting.
|
||||
params = tool.get("input_schema") or tool.get("parameters") or {}
|
||||
if not isinstance(params, dict):
|
||||
params = {}
|
||||
function = {
|
||||
"name": tool.get("name"),
|
||||
"description": tool.get("description"),
|
||||
"parameters": tool.get("input_schema", tool.get("parameters", {})),
|
||||
"parameters": params,
|
||||
}
|
||||
if function_description := function.get("description"):
|
||||
lines.append(f"// {function_description}")
|
||||
function_name = function.get("name")
|
||||
parameters = function.get("parameters", {})
|
||||
parameters = function.get("parameters") or {}
|
||||
if not isinstance(parameters, dict):
|
||||
parameters = {}
|
||||
properties = parameters.get("properties")
|
||||
if properties and properties.keys():
|
||||
lines.append(f"type {function_name} = (_: {{")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue