mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(proxy): address review feedback — safer backwards compat and None guards
- Replace try/except TypeError with inspect.signature() check for
litellm_call_info backwards compatibility. This avoids masking real
TypeErrors inside callback implementations and prevents double
invocation with inconsistent parameters.
- Use (data.get("key") or {}) instead of data.get("key", {}) to guard
against keys that exist with an explicit None value, which would
cause AttributeError on the subsequent .get() call.
This commit is contained in:
parent
491f36be50
commit
1a3a9aa34c
2 changed files with 7 additions and 5 deletions
|
|
@ -1212,7 +1212,7 @@ class ProxyBaseLLMRequestProcessing:
|
|||
data=self.data,
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
response=None,
|
||||
request_headers=self.data.get("proxy_server_request", {}).get("headers", {}),
|
||||
request_headers=(self.data.get("proxy_server_request") or {}).get("headers", {}),
|
||||
)
|
||||
if callback_headers:
|
||||
headers.update(callback_headers)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import copy
|
||||
import hashlib
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import smtplib
|
||||
|
|
@ -1988,7 +1989,8 @@ class ProxyLogging:
|
|||
_callback = callback # type: ignore
|
||||
|
||||
if _callback is not None and isinstance(_callback, CustomLogger):
|
||||
try:
|
||||
sig = inspect.signature(_callback.async_post_call_response_headers_hook)
|
||||
if "litellm_call_info" in sig.parameters:
|
||||
result = await _callback.async_post_call_response_headers_hook(
|
||||
data=data,
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
|
|
@ -1996,7 +1998,7 @@ class ProxyLogging:
|
|||
request_headers=request_headers,
|
||||
litellm_call_info=litellm_call_info,
|
||||
)
|
||||
except TypeError:
|
||||
else:
|
||||
# Backwards compat: callback doesn't accept litellm_call_info
|
||||
result = await _callback.async_post_call_response_headers_hook(
|
||||
data=data,
|
||||
|
|
@ -2024,8 +2026,8 @@ class ProxyLogging:
|
|||
|
||||
# model_info: check both metadata keys (chat uses "metadata", responses uses "litellm_metadata")
|
||||
model_info = (
|
||||
data.get("metadata", {}).get("model_info")
|
||||
or data.get("litellm_metadata", {}).get("model_info")
|
||||
(data.get("metadata") or {}).get("model_info")
|
||||
or (data.get("litellm_metadata") or {}).get("model_info")
|
||||
or {}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue