Skip to content

Commit

Permalink
whisper: add groq support (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayeshp19 authored Oct 25, 2024
1 parent ade93d5 commit 62b789c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eleven-items-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-openai": patch
---

Groq integration with Whisper-compatible STT endpoints
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
"gemma2-9b-it",
]

GroqAudioModels = Literal[
"whisper-large-v3",
"distil-whisper-large-v3-en",
"whisper-large-v3-turbo"
]

DeepSeekChatModels = Literal[
"deepseek-coder",
"deepseek-chat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import dataclasses
import io
import os
import wave
from dataclasses import dataclass

Expand All @@ -26,7 +27,7 @@

import openai

from .models import WhisperModels
from .models import WhisperModels, GroqAudioModels


@dataclass

Check failure on line 33 in livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py

View workflow job for this annotation

GitHub Actions / build

Ruff (I001)

livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py:15:1: I001 Import block is un-sorted or un-formatted
Expand Down Expand Up @@ -80,6 +81,39 @@ def __init__(
),
)


@staticmethod
def with_groq(
*,
model: GroqAudioModels = "whisper-large-v3-turbo",
api_key: str | None = None,
base_url: str | None = "https://api.groq.com/openai/v1",
client: openai.AsyncClient | None = None,
language: str = "en",
detect_language: bool = False,
) -> STT:
"""
Create a new instance of Groq STT.
``api_key`` must be set to your Groq API key, either using the argument or by setting
the ``GROQ_API_KEY`` environmental variable.
"""

# Use environment variable if API key is not provided
api_key = api_key or os.environ.get("GROQ_API_KEY")
if api_key is None:
raise ValueError("Groq API key is required")

# Instantiate and return a configured STT instance
return STT(
model=model,
api_key=api_key,
base_url=base_url,
client=client,
language=language,
detect_language=detect_language,
)

def _sanitize_options(self, *, language: str | None = None) -> _STTOptions:
config = dataclasses.replace(self._opts)
config.language = language or config.language
Expand Down

0 comments on commit 62b789c

Please sign in to comment.