The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: req changes from greptile
Harshit28jafb117f5d325
diff --git a/litellm/router.py b/litellm/router.pyindex fac9409b359..06def6ceb4d 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -1501,20 +1501,21 @@ class Router:loop = asyncio.new_event_loop()asyncio.set_event_loop(loop)try:- loop.run_until_complete(- self.acompletion(++ async def _run_silent_completion():+ await self.acompletion(model=silent_model,messages=cast(List[AllMessageValues], messages),**silent_kwargs,)- )- # Drain any remaining fire-and-forget tasks (e.g. alerting hooks)- # scheduled via asyncio.create_task during the acompletion call.- pending = asyncio.all_tasks(loop)- if pending:- loop.run_until_complete(- asyncio.gather(*pending, return_exceptions=True)- )+ # Drain any fire-and-forget tasks (e.g. alerting hooks)+ # scheduled via asyncio.create_task during acompletion.+ pending = asyncio.all_tasks()+ pending.discard(asyncio.current_task())+ if pending:+ await asyncio.gather(*pending, return_exceptions=True)++ loop.run_until_complete(_run_silent_completion())finally:loop.close()except Exception as e:diff --git a/tests/test_litellm/test_router_silent_experiment.py b/tests/test_litellm/test_router_silent_experiment.pyindex 79056805d54..67d262f83d4 100644--- a/tests/test_litellm/test_router_silent_experiment.py+++ b/tests/test_litellm/test_router_silent_experiment.py@@ -1,4 +1,5 @@import asyncio+import timefrom unittest.mock import AsyncMock, MagicMock, patchimport pytest@@ -203,15 +204,10 @@ def test_router_silent_experiment_completion():assert response.choices[0].message.content == "hello"- # The sync background call uses a thread pool. We might need to wait a bit.- import time-+ # The sync background call uses a thread pool. We might need to wait.time.sleep(2.0)# Should have 1 acompletion call (the silent background call)- # The primary completion call still goes to the real litellm.completion (or we can mock it separately, but here it's testing the background one)- # Wait, the primary call in the test is router.completion.- # Actually, let's just mock both to avoid real network calls if it's hitting one.assert mock_acompletion_mock.call_count == 1call_args_list = mock_acompletion_mock.call_args_list