mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
Fix logging and encrypted content extraction
This commit is contained in:
parent
db0ece391c
commit
185fcab88b
2 changed files with 19 additions and 11 deletions
|
|
@ -76,26 +76,31 @@ class EncryptedContentAffinityCheck(CustomLogger):
|
|||
def _extract_item_ids_from_output(
|
||||
output: list,
|
||||
) -> List[str]:
|
||||
"""Extract all item IDs from a Responses API output list."""
|
||||
"""Extract item IDs from output items that contain encrypted_content."""
|
||||
item_ids: List[str] = []
|
||||
for item in output:
|
||||
item_id: Optional[str] = None
|
||||
has_encrypted_content = False
|
||||
|
||||
if isinstance(item, dict):
|
||||
item_id = item.get("id")
|
||||
has_encrypted_content = "encrypted_content" in item
|
||||
else:
|
||||
item_id = getattr(item, "id", None)
|
||||
if item_id and isinstance(item_id, str):
|
||||
has_encrypted_content = hasattr(item, "encrypted_content")
|
||||
|
||||
if item_id and isinstance(item_id, str) and has_encrypted_content:
|
||||
item_ids.append(item_id)
|
||||
return item_ids
|
||||
|
||||
@staticmethod
|
||||
def _extract_item_ids_from_input(request_input: Any) -> List[str]:
|
||||
"""
|
||||
Extract item IDs from the ``input`` field of a Responses API request.
|
||||
Extract item IDs from input items that contain encrypted_content.
|
||||
|
||||
``input`` can be:
|
||||
- a plain string -> no item IDs
|
||||
- a list of items -> each item may have an ``id`` field
|
||||
- a list of items -> only extract IDs from items with encrypted_content
|
||||
"""
|
||||
if not isinstance(request_input, list):
|
||||
return []
|
||||
|
|
@ -104,7 +109,8 @@ class EncryptedContentAffinityCheck(CustomLogger):
|
|||
for item in request_input:
|
||||
if isinstance(item, dict):
|
||||
item_id = item.get("id")
|
||||
if item_id and isinstance(item_id, str):
|
||||
has_encrypted_content = "encrypted_content" in item
|
||||
if item_id and isinstance(item_id, str) and has_encrypted_content:
|
||||
item_ids.append(item_id)
|
||||
return item_ids
|
||||
|
||||
|
|
@ -191,13 +197,13 @@ class EncryptedContentAffinityCheck(CustomLogger):
|
|||
ttl=self.ttl_seconds,
|
||||
)
|
||||
except Exception as e:
|
||||
verbose_router_logger.debug(
|
||||
verbose_router_logger.error(
|
||||
"EncryptedContentAffinityCheck: failed to cache item_id=%s error=%s",
|
||||
item_id,
|
||||
e,
|
||||
)
|
||||
|
||||
verbose_router_logger.info(
|
||||
verbose_router_logger.debug(
|
||||
"EncryptedContentAffinityCheck: cached %d item IDs -> deployment=%s",
|
||||
len(item_ids),
|
||||
model_id,
|
||||
|
|
@ -247,7 +253,7 @@ class EncryptedContentAffinityCheck(CustomLogger):
|
|||
model_id=cached_model_id,
|
||||
)
|
||||
if deployment is not None:
|
||||
verbose_router_logger.info(
|
||||
verbose_router_logger.debug(
|
||||
"EncryptedContentAffinityCheck: item_id=%s pinning -> deployment=%s",
|
||||
item_id,
|
||||
cached_model_id,
|
||||
|
|
@ -257,7 +263,7 @@ class EncryptedContentAffinityCheck(CustomLogger):
|
|||
] = True
|
||||
return [deployment]
|
||||
|
||||
verbose_router_logger.info(
|
||||
verbose_router_logger.debug(
|
||||
"EncryptedContentAffinityCheck: cached deployment=%s for item_id=%s "
|
||||
"not found in healthy_deployments",
|
||||
cached_model_id,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ async def test_encrypted_content_affinity_tracks_and_routes():
|
|||
"type": "reasoning",
|
||||
"id": "rs_encrypted_item_456",
|
||||
"status": "completed",
|
||||
"encrypted_content": "gAAAAABpnW_yEYmSNEyOG...",
|
||||
},
|
||||
],
|
||||
"parallel_tool_calls": True,
|
||||
|
|
@ -118,7 +119,7 @@ async def test_encrypted_content_affinity_tracks_and_routes():
|
|||
model=model_group,
|
||||
input=[
|
||||
{"type": "message", "id": "msg_abc123", "role": "assistant"},
|
||||
{"type": "reasoning", "id": "rs_encrypted_item_456"},
|
||||
{"type": "reasoning", "id": "rs_encrypted_item_456", "encrypted_content": "gAAAAABpnW_yEYmSNEyOG..."},
|
||||
],
|
||||
)
|
||||
second_model_id = second_response._hidden_params["model_id"]
|
||||
|
|
@ -204,6 +205,7 @@ async def test_encrypted_content_affinity_bypasses_rpm_limits():
|
|||
"type": "reasoning",
|
||||
"id": "rs_encrypted_must_pin",
|
||||
"status": "completed",
|
||||
"encrypted_content": "gAAAAABpnW_yEYmSNEyOG...",
|
||||
},
|
||||
],
|
||||
"usage": {"input_tokens": 5, "output_tokens": 10, "total_tokens": 15},
|
||||
|
|
@ -255,7 +257,7 @@ async def test_encrypted_content_affinity_bypasses_rpm_limits():
|
|||
second_response = await router.aresponses(
|
||||
model="openai.gpt-5.1-codex",
|
||||
input=[
|
||||
{"type": "reasoning", "id": "rs_encrypted_must_pin"},
|
||||
{"type": "reasoning", "id": "rs_encrypted_must_pin", "encrypted_content": "gAAAAABpnW_yEYmSNEyOG..."},
|
||||
],
|
||||
)
|
||||
second_model_id = second_response._hidden_params["model_id"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue