mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-27 01:22:18 +00:00
fix(guardrails): tolerate a model-less request when translating Anthropic response context
The proxy-endpoints shard failed with KeyError: 'model' because the new Anthropic post-call context translation reached translate_anthropic_to_openai with request data that only carried messages and guardrail metadata. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
8e25720c08
commit
43ae9aff3d
2 changed files with 17 additions and 1 deletions
|
|
@ -1180,7 +1180,7 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
self._add_system_message_to_messages(new_messages, anthropic_message_request)
|
||||
|
||||
new_kwargs: Final[ChatCompletionRequest] = {
|
||||
"model": anthropic_message_request["model"],
|
||||
"model": anthropic_message_request.get("model", ""),
|
||||
"messages": new_messages,
|
||||
}
|
||||
## CONVERT METADATA (user_id + litellm metadata)
|
||||
|
|
|
|||
|
|
@ -2793,3 +2793,19 @@ class TestAnthropicResponseScanCarriesRequestConversation:
|
|||
]
|
||||
assert inputs["structured_messages"][-1] == {"role": "assistant", "content": "Paris is the capital"}
|
||||
assert inputs["tools"][0]["function"]["name"] == "run_shell"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_streaming_response_scan_survives_a_request_without_a_model(self):
|
||||
handler = AnthropicMessagesHandler()
|
||||
guardrail = TypedInputsRecordingGuardrail()
|
||||
request = {key: value for key, value in self._request().items() if key != "model"}
|
||||
|
||||
await handler.process_output_streaming_response(
|
||||
responses_so_far=self._sse_chunks(ended=True),
|
||||
guardrail_to_apply=guardrail,
|
||||
litellm_logging_obj=MagicMock(),
|
||||
request_data=request,
|
||||
)
|
||||
|
||||
[(_, inputs)] = guardrail.seen
|
||||
assert [m["role"] for m in inputs["structured_messages"]] == ["system", "user", "assistant", "tool", "assistant"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue