mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-08 08:08:37 +00:00
fix(proxy): type RejectedRequestError.model and read it directly
The type check gate counted four new reportUnknownMemberType errors from reading the untyped request_data dict and model attribute. Annotate model as str, like ModifyResponseException, and use it directly; the request-data fallback only covered callers passing model=None, which the annotation now rules out.
This commit is contained in:
parent
7793917aae
commit
b649de6016
3 changed files with 5 additions and 20 deletions
|
|
@ -637,7 +637,7 @@ class RejectedRequestError(BadRequestError):
|
|||
def __init__(
|
||||
self,
|
||||
message,
|
||||
model,
|
||||
model: str,
|
||||
llm_provider,
|
||||
request_data: dict,
|
||||
litellm_debug_info: str | None = None,
|
||||
|
|
|
|||
|
|
@ -12824,7 +12824,7 @@ async def chat_completion(
|
|||
request_data=_data,
|
||||
)
|
||||
_chat_response = litellm.ModelResponse()
|
||||
_chat_response.model = _data.get("model") or e.model or ""
|
||||
_chat_response.model = e.model
|
||||
_chat_response.choices[0].message.content = e.message
|
||||
|
||||
if data.get("stream", None) is not None and data["stream"] is True:
|
||||
|
|
@ -13010,7 +13010,7 @@ async def completion(
|
|||
else:
|
||||
_response = litellm.TextCompletionResponse()
|
||||
_response.choices[0].text = e.message
|
||||
_response.model = _data.get("model") or e.model or ""
|
||||
_response.model = e.model
|
||||
return _response
|
||||
except Exception as e:
|
||||
await proxy_logging_obj.post_call_failure_hook(
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ from litellm.proxy._types import UserAPIKeyAuth
|
|||
from litellm.proxy.proxy_server import chat_completion, completion
|
||||
|
||||
|
||||
async def _run_rejected_request(route, body, exception_model="my-model"):
|
||||
async def _run_rejected_request(route, body):
|
||||
exception = RejectedRequestError(
|
||||
message="cached answer",
|
||||
model=exception_model,
|
||||
model=body["model"],
|
||||
llm_provider="",
|
||||
request_data=dict(body),
|
||||
)
|
||||
|
|
@ -64,18 +64,3 @@ async def test_rejected_text_completion_response_has_model():
|
|||
# finish_reason is still None here, so this is not validated against
|
||||
# openai.types.Completion the way the chat response is.
|
||||
assert response.model == "my-model"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"route, body",
|
||||
[
|
||||
(chat_completion, {"model": "my-model", "messages": [{"role": "user", "content": "hi"}]}),
|
||||
(completion, {"model": "my-model", "prompt": "hi"}),
|
||||
],
|
||||
)
|
||||
async def test_rejected_response_falls_back_to_request_model(route, body):
|
||||
# RejectedRequestError is public, so a custom hook can raise it without a model.
|
||||
response = await _run_rejected_request(route, body, exception_model=None)
|
||||
|
||||
assert response.model == "my-model"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue