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 tests
Sameer Kankute83d0f28aa858
diff --git a/tests/llm_translation/test_gpt4o_audio.py b/tests/llm_translation/test_gpt4o_audio.pyindex f41dabb6665..d60595463b2 100644--- a/tests/llm_translation/test_gpt4o_audio.py+++ b/tests/llm_translation/test_gpt4o_audio.py@@ -34,8 +34,10 @@ async def check_streaming_response(completion):_audio_id = Noneasync for chunk in completion:print(chunk)+ if len(chunk.choices) == 0:+ continue_choice: StreamingChoices = chunk.choices[0]- if _choice.delta.audio is not None:+ if _choice.delta is not None and _choice.delta.audio is not None:if _choice.delta.audio.get("data") is not None:_audio_bytes = _choice.delta.audio["data"]if _choice.delta.audio.get("transcript") is not None:diff --git a/tests/local_testing/test_completion.py b/tests/local_testing/test_completion.pyindex f18a2b4afbb..55ce56adf90 100644--- a/tests/local_testing/test_completion.py+++ b/tests/local_testing/test_completion.py@@ -1759,8 +1759,14 @@ def test_completion_logprobs_stream():for chunk in response:# check if atleast one chunk has log probsprint(chunk)+ if len(chunk.choices) == 0:+ continueprint(f"chunk.choices[0]: {chunk.choices[0]}")- if "logprobs" in chunk.choices[0]:+ if (+ "logprobs" in chunk.choices[0]+ and chunk.choices[0].logprobs is not None+ and len(chunk.choices[0].logprobs.content) > 0+ ):# assert we got a valid logprob in the choicesassert len(chunk.choices[0].logprobs.content[0].top_logprobs) == 3found_logprob = Truediff --git a/tests/local_testing/test_streaming.py b/tests/local_testing/test_streaming.pyindex 3aed0699603..bf374ff8577 100644--- a/tests/local_testing/test_streaming.py+++ b/tests/local_testing/test_streaming.py@@ -831,23 +831,29 @@ def test_completion_mistral_api_mistral_large_function_call_with_streaming():tool_choice="auto",stream=True,)- idx = 0+ saw_function_call_chunk = Falsefor chunk in response:print(f"chunk in response: {chunk}")assert chunk._hidden_params["custom_llm_provider"] == "mistral"- if idx == 0:- assert (- chunk.choices[0].delta.tool_calls[0].function.arguments is not None- )- assert isinstance(- chunk.choices[0].delta.tool_calls[0].function.arguments, str- )- validate_first_streaming_function_calling_chunk(chunk=chunk)- elif idx == 1 and chunk.choices[0].finish_reason is None:- validate_second_streaming_function_calling_chunk(chunk=chunk)- elif chunk.choices[0].finish_reason is not None: # last chunk+ if len(chunk.choices) == 0:+ continue+ if chunk.choices[0].finish_reason is not None: # last chunkvalidate_final_streaming_function_calling_chunk(chunk=chunk)- idx += 1+ break+ tool_calls = chunk.choices[0].delta.tool_calls+ if tool_calls is None:+ continue+ assert tool_calls[0].function.arguments is not None+ assert isinstance(tool_calls[0].function.arguments, str)+ if not saw_function_call_chunk:+ if chunk.choices[0].delta.role is not None:+ validate_first_streaming_function_calling_chunk(chunk=chunk)+ else:+ validate_second_streaming_function_calling_chunk(chunk=chunk)+ saw_function_call_chunk = True+ else:+ validate_second_streaming_function_calling_chunk(chunk=chunk)+ assert saw_function_call_chunkexcept litellm.RateLimitError:passexcept Exception as e: