mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
Litellm dev 12 17 2024 p2 (#7277)
* fix(openai/transcription/handler.py): call 'log_pre_api_call' on async calls * fix(openai/transcriptions/handler.py): call 'logging.pre_call' on sync whisper calls as well * fix(proxy_cli.py): remove default proxy_cli timeout param gets passed in as a dynamic request timeout and overrides config values * fix(langfuse.py): pass litellm httpx client - contains ssl certs (#7052) Fixes https://github.com/BerriAI/litellm/issues/7046
This commit is contained in:
parent
03e711e3e4
commit
57809cfbf4
5 changed files with 67 additions and 1 deletions
|
@ -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"):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
|
|
|
@ -115,3 +115,22 @@ async def test_transcription_caching():
|
|||
assert response_3.text != response_2.text
|
||||
|
||||
litellm.cache = None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue