mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
refactor: clean up fresh tech debt in mcp tool call auth fields, messages drop_params, exception chain and spend log noqa
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
1c6c9cbe71
commit
f54eb8987f
4 changed files with 18 additions and 15 deletions
|
|
@ -694,7 +694,7 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
|
|||
|
||||
anthropic_messages_request: Final[AnthropicMessagesRequest] = AnthropicMessagesRequest(
|
||||
messages=strip_encrypted_reasoning_blocks_from_anthropic_messages(
|
||||
drop_non_string_tool_result_texts(messages, getattr(litellm_params, "drop_params", None))
|
||||
drop_non_string_tool_result_texts(messages, litellm_params.drop_params)
|
||||
),
|
||||
max_tokens=max_tokens,
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -6145,9 +6145,9 @@ class MCPServerManager:
|
|||
"server_name": server_name,
|
||||
"mcp_rate_limit_server_name": server.alias or server.server_name or server.name,
|
||||
"user_api_key_auth": checked_auth,
|
||||
"user_api_key_user_id": (getattr(checked_auth, "user_id", None) if checked_auth else None),
|
||||
"user_api_key_team_id": (getattr(checked_auth, "team_id", None) if checked_auth else None),
|
||||
"user_api_key_end_user_id": (getattr(checked_auth, "end_user_id", None) if checked_auth else None),
|
||||
"user_api_key_user_id": checked_auth.user_id if checked_auth else None,
|
||||
"user_api_key_team_id": checked_auth.team_id if checked_auth else None,
|
||||
"user_api_key_end_user_id": checked_auth.end_user_id if checked_auth else None,
|
||||
"user_api_key_hash": (getattr(checked_auth, "api_key_hash", None) if checked_auth else None),
|
||||
"incoming_bearer_token": caller_bearer.get_secret_value() if caller_bearer is not None else None,
|
||||
"headers": logging_safe_mcp_headers(raw_headers),
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ class SpendLogCleanup:
|
|||
rows: Final = _STORAGE_ROWS.validate_python(
|
||||
await tx.query_raw(trusted_sql(_STORAGE_SQL), list(_SPEND_LOG_TABLES))
|
||||
)
|
||||
except Exception as e: # noqa: BLE001 - a failed measurement skips the size pass, it must not fail the run
|
||||
except Exception as e: # noqa: BLE001 # a failed measurement skips the size pass, it must not fail the run
|
||||
verbose_proxy_logger.warning("Could not measure spend-log storage: %s: %s", type(e).__name__, e)
|
||||
return None
|
||||
if not rows:
|
||||
|
|
@ -493,7 +493,7 @@ class SpendLogCleanup:
|
|||
await tx.query_raw(trusted_sql(_LOAD_SIZE_STATE_SQL), SPEND_LOG_SIZE_CLEANUP_STATE_PARAM)
|
||||
)
|
||||
return SizeCleanupState.model_validate_json(rows[0].state_json) if rows else None
|
||||
except Exception as e: # noqa: BLE001 - an unreadable count restarts from the catalog, it must not fail the run
|
||||
except Exception as e: # noqa: BLE001 # an unreadable count restarts from the catalog, it must not fail the run
|
||||
verbose_proxy_logger.warning("Could not read the spend-log size cleanup state: %s: %s", type(e).__name__, e)
|
||||
return None
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ class SpendLogCleanup:
|
|||
await tx.execute_raw(
|
||||
trusted_sql(_SAVE_SIZE_STATE_SQL), SPEND_LOG_SIZE_CLEANUP_STATE_PARAM, state.model_dump_json()
|
||||
)
|
||||
except Exception as e: # noqa: BLE001 - a lost save costs one re-seed from the catalog, it must not fail the run
|
||||
except Exception as e: # noqa: BLE001 # a lost save costs one re-seed from the catalog, it must not fail the run
|
||||
verbose_proxy_logger.warning("Could not save the spend-log size cleanup state: %s: %s", type(e).__name__, e)
|
||||
|
||||
def _timeout_ms(self, deadline: float) -> int:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from dataclasses import dataclass, field
|
|||
from datetime import date, datetime, timedelta, timezone
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from functools import partial
|
||||
from functools import partial, reduce
|
||||
from itertools import takewhile
|
||||
from operator import attrgetter
|
||||
from types import MappingProxyType
|
||||
|
|
@ -1226,14 +1226,17 @@ _LOG_DB_METRICS_CALL_TYPES: Final = frozenset(("get_data", "insert_data", "updat
|
|||
_EXCEPTION_CHAIN_MAX_DEPTH: Final = 16
|
||||
|
||||
|
||||
def _extended_exception_chain(chain: tuple[BaseException, ...], iteration: int) -> tuple[BaseException, ...]:
|
||||
if len(chain) != iteration + 1:
|
||||
return chain
|
||||
following: Final = chain[-1].__cause__ or chain[-1].__context__
|
||||
if following is None or following in chain:
|
||||
return chain
|
||||
return (*chain, following)
|
||||
|
||||
|
||||
def _exception_chain(exception: BaseException) -> tuple[BaseException, ...]:
|
||||
chain: Final[list[BaseException]] = [exception] # mutable-ok: built once, returned frozen
|
||||
for _ in range(_EXCEPTION_CHAIN_MAX_DEPTH):
|
||||
following = chain[-1].__cause__ or chain[-1].__context__
|
||||
if following is None or following in chain:
|
||||
break
|
||||
chain.append(following)
|
||||
return tuple(chain)
|
||||
return reduce(_extended_exception_chain, range(_EXCEPTION_CHAIN_MAX_DEPTH), (exception,))
|
||||
|
||||
|
||||
def _timed_out_reading_from_provider(exception: Exception) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue