Conversation
- Added new environment variables for LiteLLM Whisper API configuration, including `LITELLM_WHISPER_URL`, `LITELLM_WHISPER_API_KEY`, `LITELLM_WHISPER_API_VERSION`, and `LITELLM_WHISPER_MODEL`. - Implemented assertions to ensure required environment variables are set, improving error handling and logging. - Refactored audio transcription logic to utilize the LiteLLM API, replacing the previous OpenAI client implementation. - Updated the `transcribe_audio` function to call the new LiteLLM transcription method, enhancing audio processing capabilities. This update streamlines the transcription process and improves configurability for different environments.
WalkthroughThe changes introduce LiteLLM Whisper integration for audio transcription, replacing the previous OpenAI-based approach. New environment variables are added for configuration, and the transcription logic is refactored to use the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TranscribeModule
participant S3
participant LiteLLMWhisper
Client->>TranscribeModule: transcribe_audio(audio_file_path, language, prompt)
TranscribeModule->>S3: Fetch audio file from S3
S3-->>TranscribeModule: Audio file data
TranscribeModule->>LiteLLMWhisper: litellm.transcription(audio data, config)
LiteLLMWhisper-->>TranscribeModule: { "text": transcription }
TranscribeModule-->>Client: transcription text
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
echo/server/dembrane/config.py (1)
145-158: Trim the redundancy in env-var validation for cleaner boot-time logs
LITELLM_WHISPER_API_VERSIONandLITELLM_WHISPER_MODELalready have safe defaults, yet we stillassertthat they are set. This double-work:
- Inflates boot-time log noise (“variable X is not set” will never trigger unless someone explicitly blank-sets it).
- Slightly slows container start-up with no real safety win.
Same story for
LITELLM_WHISPER_API_KEYif the OpenAI key fallback is present.Consider asserting only the pieces that truly lack defaults (
LITELLM_WHISPER_URLwhen the model isn’twhisper-1). Everything else can rely on the fallback values.-assert LITELLM_WHISPER_API_VERSION, "LITELLM_WHISPER_API_VERSION environment variable is not set" -logger.debug("LITELLM_WHISPER_API_VERSION: set") -assert LITELLM_WHISPER_MODEL, "LITELLM_WHISPER_MODEL environment variable is not set" -logger.debug("LITELLM_WHISPER_MODEL: set") +logger.debug(f"LITELLM_WHISPER_API_VERSION: {LITELLM_WHISPER_API_VERSION}") +logger.debug(f"LITELLM_WHISPER_MODEL: {LITELLM_WHISPER_MODEL}")Net result: Same safety guarantees, less friction.
echo/server/dembrane/transcribe.py (3)
32-33: Logger alias reads like legacy Azure code – rename for clarityThe function targets LiteLLM, but we’re initialising the child logger as
"transcribe.transcribe_audio_azure_ml". Renaming it to"transcribe.transcribe_audio_litellm"keeps stack-traces and LogRocket breadcrumbs self-explanatory.-logger = logging.getLogger("transcribe.transcribe_audio_azure_ml") +logger = logging.getLogger("transcribe.transcribe_audio_litellm")
35-40: Stream vs. slurp: avoid loading full audio into RAMWe eagerly read the entire S3 object into memory (
audio_bytes = audio_stream.read()), wrap it inBytesIO, then send to LiteLLM. For 15 MB caps this is fine, but future bumps (or multi-GB podcasts) will punch RAM in the face.LiteLLM accepts a file-like object; we can pass the
StreamingBodydirectly:-audio_bytes = audio_stream.read() -filename = os.path.basename(audio_file_uri) -mime_type, _ = mimetypes.guess_type(filename) -file_upload = (filename, io.BytesIO(audio_bytes), mime_type) +filename = os.path.basename(audio_file_uri) +mime_type, _ = mimetypes.guess_type(filename) +# Reset stream position just in case S3 gave us a non-zero offset +audio_stream.seek(0) +file_upload = (filename, audio_stream, mime_type or "application/octet-stream")Bonus: falls back to a sane MIME when
guess_typereturnsNone.
55-57: Update error copy-writing to match failure pointWe’re inside the API call, not reading the stream anymore. Tiny polish:
-logger.error(f"Failed to read audio stream: {e}") -raise TranscriptionError(f"Failed to read audio stream: {e}") from e +logger.error(f"LiteLLM transcription failed: {e}") +raise TranscriptionError(f"LiteLLM transcription failed: {e}") from e
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
echo/server/dembrane/config.py(1 hunks)echo/server/dembrane/transcribe.py(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
echo/server/dembrane/transcribe.py (1)
echo/server/dembrane/s3.py (1)
get_stream_from_s3(175-179)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: ci-check-server
🔇 Additional comments (1)
echo/server/dembrane/transcribe.py (1)
38-39: Guard againstNoneMIME types
mimetypes.guess_typecan return(None, None). PassingNonein the tuple may breakrequests’ multipart encoder. Provide a default such as"application/octet-stream"(see previous diff).
- Changed logger name to reflect the LiteLLM transcription context. - Enhanced error messages to provide clearer feedback on transcription failures, improving debugging and user experience.
|
Caution An unexpected error occurred while opening a pull request: Not Found - https://docs.github.com/rest/git/refs#get-a-reference |
…128) * Enhance LiteLLM transcription integration and configuration - Added new environment variables for LiteLLM Whisper API configuration, including `LITELLM_WHISPER_URL`, `LITELLM_WHISPER_API_KEY`, `LITELLM_WHISPER_API_VERSION`, and `LITELLM_WHISPER_MODEL`. - Implemented assertions to ensure required environment variables are set, improving error handling and logging. - Refactored audio transcription logic to utilize the LiteLLM API, replacing the previous OpenAI client implementation. - Updated the `transcribe_audio` function to call the new LiteLLM transcription method, enhancing audio processing capabilities. This update streamlines the transcription process and improves configurability for different environments. * Update logging for LiteLLM transcription error handling - Changed logger name to reflect the LiteLLM transcription context. - Enhanced error messages to provide clearer feedback on transcription failures, improving debugging and user experience. --------- Co-authored-by: Sameer Pashikanti <63326129+spashii@users.noreply.github.com>
LITELLM_WHISPER_URL,LITELLM_WHISPER_API_KEY,LITELLM_WHISPER_API_VERSION, andLITELLM_WHISPER_MODEL.transcribe_audiofunction to call the new LiteLLM transcription method, enhancing audio processing capabilities.This update streamlines the transcription process and improves configurability for different environments.
Summary by CodeRabbit