Skip to content

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]

Litellm dev 12 17 2024 p2 (#7277)

Krish Dholakia019ddc32d637
diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py
index 73485a0bdbf..047f213b7ef 100644
--- a/litellm/integrations/langfuse/langfuse.py
+++ b/litellm/integrations/langfuse/langfuse.py
@@ -13,6 +13,7 @@ from pydantic import BaseModel
import litellm
from litellm._logging import verbose_logger
from litellm.litellm_core_utils.redact_messages import redact_user_api_key_info
+from litellm.llms.custom_httpx.http_handler import _get_httpx_client
from litellm.secret_managers.main import str_to_bool
from litellm.types.integrations.langfuse import *
from litellm.types.utils import StandardLoggingPayload
@@ -56,6 +57,8 @@ class LangFuseLogger:
self.langfuse_flush_interval = (
os.getenv("LANGFUSE_FLUSH_INTERVAL") or flush_interval
)
+ http_client = _get_httpx_client()
+ self.langfuse_client = http_client.client
parameters = {
"public_key": self.public_key,
@@ -64,6 +67,7 @@ class LangFuseLogger:
"release": self.langfuse_release,
"debug": self.langfuse_debug,
"flush_interval": self.langfuse_flush_interval, # flush interval in seconds
+ "httpx_client": self.langfuse_client,
}
if Version(langfuse.version.__version__) >= Version("2.6.0"):
diff --git a/litellm/llms/openai/transcriptions/handler.py b/litellm/llms/openai/transcriptions/handler.py
index 9e779c683dc..030adb88f1a 100644
--- a/litellm/llms/openai/transcriptions/handler.py
+++ b/litellm/llms/openai/transcriptions/handler.py
@@ -9,6 +9,7 @@ from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
from litellm.types.utils import FileTypes
from litellm.utils import TranscriptionResponse, convert_to_model_response_object
+
from ..openai import OpenAIChatCompletion
@@ -103,6 +104,17 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
timeout=timeout,
max_retries=max_retries,
)
+
+ ## LOGGING
+ logging_obj.pre_call(
+ input=None,
+ api_key=openai_client.api_key,
+ additional_args={
+ "api_base": openai_client._base_url._uri_reference,
+ "atranscription": True,
+ "complete_input_dict": data,
+ },
+ )
_, response = self.make_sync_openai_audio_transcriptions_request(
openai_client=openai_client,
data=data,
@@ -147,6 +159,16 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
client=client,
)
+ ## LOGGING
+ logging_obj.pre_call(
+ input=None,
+ api_key=openai_aclient.api_key,
+ additional_args={
+ "api_base": openai_aclient._base_url._uri_reference,
+ "atranscription": True,
+ "complete_input_dict": data,
+ },
+ )
headers, response = await self.make_openai_audio_transcriptions_request(
openai_aclient=openai_aclient,
data=data,
diff --git a/litellm/main.py b/litellm/main.py
index ad634d3f872..6a80a484524 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -4632,6 +4632,11 @@ def transcription(
Allows router to load balance between them
"""
+ litellm_call_id = kwargs.get("litellm_call_id", None)
+ proxy_server_request = kwargs.get("proxy_server_request", None)
+ model_info = kwargs.get("model_info", None)
+ metadata = kwargs.get("metadata", None)
+ atranscription = kwargs.get("atranscription", False)
atranscription = kwargs.get("atranscription", False)
litellm_logging_obj: LiteLLMLoggingObj = kwargs.get("litellm_logging_obj") # type: ignore
extra_headers = kwargs.get("extra_headers", None)
@@ -4673,6 +4678,22 @@ def transcription(
drop_params=drop_params,
)
+ litellm_logging_obj.update_environment_variables(
+ model=model,
+ user=user,
+ optional_params={},
+ litellm_params={
+ "litellm_call_id": litellm_call_id,
+ "proxy_server_request": proxy_server_request,
+ "model_info": model_info,
+ "metadata": metadata,
+ "preset_cache_key": None,
+ "stream_response": {},
+ **kwargs,
+ },
+ custom_llm_provider=custom_llm_provider,
+ )
+
response: Optional[TranscriptionResponse] = None
if custom_llm_provider == "azure":
# azure configs
diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py
index c77010a2027..ba37b3c5177 100644
--- a/litellm/proxy/proxy_cli.py
+++ b/litellm/proxy/proxy_cli.py
@@ -125,7 +125,7 @@ def is_port_in_use(port):
)
@click.option(
"--request_timeout",
- default=6000,
+ default=None,
type=int,
help="Set timeout in seconds for completion calls",
)
diff --git a/tests/local_testing/test_whisper.py b/tests/local_testing/test_whisper.py
index 68c292a6084..5bda5456a43 100644
--- a/tests/local_testing/test_whisper.py
+++ b/tests/local_testing/test_whisper.py
@@ -115,3 +115,22 @@ async def test_transcription_caching():
assert response_3.text != response_2.text
litellm.cache = None
+
+
+async def test_whisper_log_pre_call():
+ from litellm.litellm_core_utils.litellm_logging import Logging
+ from datetime import datetime
+ from unittest.mock import patch, MagicMock
+ from litellm.integrations.custom_logger import CustomLogger
+
+ custom_logger = CustomLogger()
+
+ litellm.callbacks = [custom_logger]
+
+ with patch.object(custom_logger, "log_pre_api_call") as mock_log_pre_call:
+ await litellm.atranscription(
+ model="whisper-1",
+ file=audio_file,
+ )
+ mock_log_pre_call.assert_called_once()