Skip to content

ECHO-176 Enhance LiteLLM transcription integration and configuration#128

Merged
spashii merged 3 commits intomainfrom
feature/echo-176-make-changes-in-code-to-use-this-new-infra
May 9, 2025
Merged

ECHO-176 Enhance LiteLLM transcription integration and configuration#128
spashii merged 3 commits intomainfrom
feature/echo-176-make-changes-in-code-to-use-this-new-infra

Conversation

@ArindamRoy23
Copy link
Copy Markdown
Contributor

@ArindamRoy23 ArindamRoy23 commented May 5, 2025

  • 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.

Summary by CodeRabbit

  • New Features
    • Added support for audio transcription using LiteLLM Whisper integration, including new configuration options for API key, version, model, and service URL.
  • Refactor
    • Updated transcription process to use LiteLLM and Azure ML Whisper service instead of the previous OpenAI-based method, enhancing backend flexibility and error handling.

- 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.
@linear
Copy link
Copy Markdown

linear bot commented May 5, 2025

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 5, 2025

Walkthrough

The 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 litellm library and Azure ML Whisper service. Validation and logging for configuration parameters are included.

Changes

File(s) Change Summary
echo/server/dembrane/config.py Added configuration for LiteLLM Whisper integration: new environment variables (LITELLM_WHISPER_URL, LITELLM_WHISPER_API_KEY, LITELLM_WHISPER_API_VERSION, LITELLM_WHISPER_MODEL), validation, and logging for these parameters.
echo/server/dembrane/transcribe.py Refactored transcription logic to use LiteLLM Whisper via the litellm library. Removed the OpenAI-specific function, added a new function for LiteLLM, updated imports, error handling, and logging. Legacy code for other providers remains commented out.

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
Loading

Suggested labels

Feature

Poem

🚀 Whisper flies on LiteLLM wings,
Transcribing words that S3 brings.
With configs set and logs in tow,
Azure’s voice now steals the show.
Old code rests, new flows ignite—
Ship it fast, the future’s bright!
LGTM, let’s launch tonight!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3fb5eb and adf9fad.

📒 Files selected for processing (1)
  • echo/server/dembrane/transcribe.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • echo/server/dembrane/transcribe.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: ci-check-frontend
  • GitHub Check: ci-check-server
✨ Finishing Touches
  • 🔥 Error while generating docstrings. (🔄 Check again to generate docstrings again)

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ArindamRoy23 ArindamRoy23 requested a review from spashii May 5, 2025 19:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_VERSION and LITELLM_WHISPER_MODEL already have safe defaults, yet we still assert that they are set. This double-work:

  1. Inflates boot-time log noise (“variable X is not set” will never trigger unless someone explicitly blank-sets it).
  2. Slightly slows container start-up with no real safety win.

Same story for LITELLM_WHISPER_API_KEY if the OpenAI key fallback is present.

Consider asserting only the pieces that truly lack defaults (LITELLM_WHISPER_URL when the model isn’t whisper-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 clarity

The 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 RAM

We eagerly read the entire S3 object into memory (audio_bytes = audio_stream.read()), wrap it in BytesIO, 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 StreamingBody directly:

-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_type returns None.


55-57: Update error copy-writing to match failure point

We’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

📥 Commits

Reviewing files that changed from the base of the PR and between a13d618 and e3fb5eb.

📒 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 against None MIME types

mimetypes.guess_type can return (None, None). Passing None in the tuple may break requests’ 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.
@spashii spashii changed the title Enhance LiteLLM transcription integration and configuration ECHO-176 Enhance LiteLLM transcription integration and configuration May 9, 2025
@spashii spashii merged commit b4642b6 into main May 9, 2025
7 checks passed
@spashii spashii deleted the feature/echo-176-make-changes-in-code-to-use-this-new-infra branch May 9, 2025 07:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 12, 2025

Caution

An unexpected error occurred while opening a pull request: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

spashii added a commit that referenced this pull request Nov 18, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants