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
support bytes.IO for audio transcription (#9071)
Teja Vishwanadha8c049dfffc3f
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.pyindex 991e4aeaec7..0459854c4e7 100644--- a/litellm/llms/custom_httpx/llm_http_handler.py+++ b/litellm/llms/custom_httpx/llm_http_handler.py@@ -873,7 +873,7 @@ class BaseLLMHTTPHandler:elif isinstance(audio_file, bytes):# Assume it's already binary databinary_data = audio_file- elif isinstance(audio_file, io.BufferedReader):+ elif isinstance(audio_file, io.BufferedReader) or isinstance(audio_file, io.BytesIO):# Handle file-like objectsbinary_data = audio_file.read()diff --git a/tests/litellm/llms/custom_httpx/test_handle_audio_file.py b/tests/litellm/llms/custom_httpx/test_handle_audio_file.pynew file mode 100644index 00000000000..682803788bd--- /dev/null+++ b/tests/litellm/llms/custom_httpx/test_handle_audio_file.py@@ -0,0 +1,47 @@++import os+import io+import pathlib+import sys++import pytest+++sys.path.insert(+ 0, os.path.abspath("../../../..")+) # Adds the parent directory to the system path+import litellm++from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler++def test_bytes():+ return b'litellm', b'litellm'++def test_io_bytes(test_bytes):+ return io.BytesIO(test_bytes[0]), test_bytes[1]++def test_file():+ pwd = os.path.dirname(os.path.realpath(__file__))+ pwd_path = pathlib.Path(pwd)+ test_root = pwd_path.parents[2]+ file_path = os.path.join(test_root, "gettysburg.wav")+ f = open(file_path, "rb")+ content = f.read()+ f.seek(0)+ return f, content++ "fixture_name",+ [+ "test_bytes",+ "test_io_bytes",+ "test_file",+ ]+)+def test_audio_file_handling(fixture_name, request):+ handler = BaseLLMHTTPHandler()+ (audio_file, expected_output) = request.getfixturevalue(fixture_name)+ assert expected_output == handler.handle_audio_file(audio_file)\ No newline at end of file