From da56201e806eb6c866f57e58b2560be63c61c599 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 29 May 2024 21:29:01 -0700 Subject: [PATCH] fix(main.py): pass api key and api base to openai.py for audio transcription call --- litellm/integrations/slack_alerting.py | 2 ++ litellm/llms/openai.py | 5 ++--- litellm/main.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index 08af8856299..49a8d0e2c78 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -1465,6 +1465,8 @@ Model Info: final_value = float( response_s.total_seconds() / completion_tokens ) + if isinstance(final_value, timedelta): + final_value = final_value.total_seconds() await self.async_update_daily_reports( DeploymentMetrics( diff --git a/litellm/llms/openai.py b/litellm/llms/openai.py index 81bbf3cab17..84d9c773fc3 100644 --- a/litellm/llms/openai.py +++ b/litellm/llms/openai.py @@ -1090,8 +1090,8 @@ class OpenAIChatCompletion(BaseLLM): model_response: TranscriptionResponse, timeout: float, max_retries: int, - api_key: Optional[str] = None, - api_base: Optional[str] = None, + api_key: Optional[str], + api_base: Optional[str], client=None, logging_obj=None, atranscription: bool = False, @@ -1147,7 +1147,6 @@ class OpenAIChatCompletion(BaseLLM): max_retries=None, logging_obj=None, ): - response = None try: if client is None: openai_aclient = AsyncOpenAI( diff --git a/litellm/main.py b/litellm/main.py index a7fbbfa69b1..d5069469778 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -4130,6 +4130,24 @@ def transcription( max_retries=max_retries, ) elif custom_llm_provider == "openai": + api_base = ( + api_base + or litellm.api_base + or get_secret("OPENAI_API_BASE") + or "https://api.openai.com/v1" + ) # type: ignore + openai.organization = ( + litellm.organization + or get_secret("OPENAI_ORGANIZATION") + or None # default - https://github.com/openai/openai-python/blob/284c1799070c723c6a553337134148a7ab088dd8/openai/util.py#L105 + ) + # set API KEY + api_key = ( + api_key + or litellm.api_key + or litellm.openai_key + or get_secret("OPENAI_API_KEY") + ) # type: ignore response = openai_chat_completions.audio_transcriptions( model=model, audio_file=file, @@ -4139,6 +4157,8 @@ def transcription( timeout=timeout, logging_obj=litellm_logging_obj, max_retries=max_retries, + api_base=api_base, + api_key=api_key, ) return response