mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-14 10:25:37 +00:00
[Fix] CI failures: mypy type error, ruff lint, and flaky router test
- Fix mypy arg-type error in background_streaming.py by adding proper type annotation and cast for terminal_status - Fix ruff F401 false positive for httpx import in vantage_destination.py caused by from __future__ import annotations - Fix flaky test_arouter_responses_api_bridge by providing a properly structured mock response to prevent exception mapping errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
24ae5cc397
commit
03231f3b26
@@ -6,7 +6,7 @@ import csv
|
||||
import io
|
||||
from typing import Any, Optional
|
||||
|
||||
import httpx
|
||||
import httpx # noqa: F401 - used at runtime (AsyncClient, HTTPStatusError)
|
||||
|
||||
from litellm._logging import verbose_logger
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ https://platform.openai.com/docs/api-reference/responses-streaming
|
||||
"""
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Any, Optional, cast
|
||||
|
||||
from fastapi import Request, Response
|
||||
|
||||
@@ -17,6 +17,7 @@ from litellm._logging import verbose_proxy_logger
|
||||
from litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuth
|
||||
from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
|
||||
from litellm.proxy.response_polling.polling_handler import ResponsePollingHandler
|
||||
from litellm.types.llms.openai import ResponsesAPIStatus
|
||||
|
||||
|
||||
async def background_streaming_task( # noqa: PLR0915
|
||||
@@ -114,7 +115,7 @@ async def background_streaming_task( # noqa: PLR0915
|
||||
UPDATE_INTERVAL = 0.150 # 150ms batching interval
|
||||
|
||||
# Track the terminal event from the stream (may not be "completed")
|
||||
terminal_status = None # Will be set by response.completed/failed/incomplete/cancelled
|
||||
terminal_status: Optional[ResponsesAPIStatus] = None # Will be set by response.completed/failed/incomplete/cancelled
|
||||
terminal_error = None
|
||||
_event_to_status = {
|
||||
"response.completed": "completed",
|
||||
@@ -249,9 +250,12 @@ async def background_streaming_task( # noqa: PLR0915
|
||||
# Terminal event - extract all ResponsesAPIResponse fields
|
||||
# https://platform.openai.com/docs/api-reference/responses-streaming
|
||||
response_data = event.get("response", {})
|
||||
terminal_status = response_data.get(
|
||||
"status",
|
||||
_event_to_status.get(event_type, "completed"),
|
||||
terminal_status = cast(
|
||||
ResponsesAPIStatus,
|
||||
response_data.get(
|
||||
"status",
|
||||
_event_to_status.get(event_type, "completed"),
|
||||
),
|
||||
)
|
||||
|
||||
# Extract error for failed responses
|
||||
|
||||
@@ -643,7 +643,13 @@ def test_arouter_responses_api_bridge():
|
||||
## CONFIRM MODEL NAME IS STRIPPED
|
||||
client = HTTPHandler()
|
||||
|
||||
with patch.object(client, "post", return_value=MagicMock()) as mock_post:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.headers = {"content-type": "application/json"}
|
||||
mock_response.json.return_value = {"id": "resp_test", "object": "response", "status": "completed", "output": []}
|
||||
mock_response.text = '{"id": "resp_test", "object": "response", "status": "completed", "output": []}'
|
||||
|
||||
with patch.object(client, "post", return_value=mock_response) as mock_post:
|
||||
try:
|
||||
result = router.completion(
|
||||
model="[IP-approved] o3-pro",
|
||||
|
||||
Reference in New Issue
Block a user