mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix: address PR review feedback — F821, double auth, strict field, docs format, system-only fallback
- Fix F821: add BaseTokenCounter TYPE_CHECKING import in gpt_transformation.py - Remove duplicate auth invocation in count_response_input_tokens endpoint - Preserve `strict` field during chat→Responses API tool conversion - Fix docs tools example to use chat completions format (not Responses API format) - Return None early for system-only messages to avoid noisy error logs
This commit is contained in:
parent
92b0585f2e
commit
8786e674ee
5 changed files with 17 additions and 8 deletions
|
|
@ -65,11 +65,13 @@ async def main():
|
|||
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
|
||||
tools=[{
|
||||
"type": "function",
|
||||
"name": "get_weather",
|
||||
"description": "Get weather for a city",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string"}},
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get weather for a city",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string"}},
|
||||
},
|
||||
},
|
||||
}],
|
||||
system="You are a helpful weather assistant.",
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ from ..common_utils import OpenAIError
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
|
||||
from litellm.llms.base_llm.base_utils import BaseTokenCounter
|
||||
from litellm.types.llms.openai import ChatCompletionToolParam
|
||||
|
||||
LiteLLMLoggingObj = _LiteLLMLoggingObj
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ class OpenAITokenCounter(BaseTokenCounter):
|
|||
if instructions is None and system is not None:
|
||||
instructions = system if isinstance(system, str) else str(system)
|
||||
|
||||
# If no input items were produced (e.g., system-only messages), fall back to local counting
|
||||
if not input_items:
|
||||
return None
|
||||
|
||||
try:
|
||||
result = await openai_count_tokens_handler.handle_count_tokens_request(
|
||||
model=model_to_use,
|
||||
|
|
|
|||
|
|
@ -75,12 +75,15 @@ class OpenAICountTokensConfig:
|
|||
for tool in tools:
|
||||
if tool.get("type") == "function" and "function" in tool:
|
||||
func = tool["function"]
|
||||
transformed.append({
|
||||
item: Dict[str, Any] = {
|
||||
"type": "function",
|
||||
"name": func.get("name", ""),
|
||||
"description": func.get("description", ""),
|
||||
"parameters": func.get("parameters", {}),
|
||||
})
|
||||
}
|
||||
if "strict" in func:
|
||||
item["strict"] = func["strict"]
|
||||
transformed.append(item)
|
||||
else:
|
||||
# Pass through non-function tools (e.g., web_search, file_search)
|
||||
transformed.append(tool)
|
||||
|
|
|
|||
|
|
@ -417,7 +417,6 @@ async def cursor_chat_completions(
|
|||
)
|
||||
async def count_response_input_tokens(
|
||||
request: Request,
|
||||
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||
):
|
||||
"""
|
||||
Count input tokens for OpenAI Responses API format.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue