Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prompt to STT options #1447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _STTOptions:
language: str
detect_language: bool
model: WhisperModels | str

prompt: str | None = None

class STT(stt.STT):
def __init__(
Expand All @@ -48,6 +48,7 @@ def __init__(
language: str = "en",
detect_language: bool = False,
model: WhisperModels | str = "whisper-1",
prompt: str | None = None,
base_url: str | None = None,
api_key: str | None = None,
client: openai.AsyncClient | None = None,
Expand All @@ -69,6 +70,7 @@ def __init__(
language=language,
detect_language=detect_language,
model=model,
prompt=prompt,
)

self._client = client or openai.AsyncClient(
Expand All @@ -91,9 +93,12 @@ def update_options(
*,
model: WhisperModels | GroqAudioModels | None = None,
language: str | None = None,
prompt: str | None = None,
) -> None:
self._opts.model = model or self._opts.model
self._opts.language = language or self._opts.language
if prompt is not None:
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to update it back to None if a user wants to clear the previous prompt too.

self._opts.prompt = prompt

@staticmethod
def with_groq(
Expand All @@ -104,6 +109,7 @@ def with_groq(
client: openai.AsyncClient | None = None,
language: str = "en",
detect_language: bool = False,
prompt: str = "Always spell 'Grok' as 'Groq'",
Copy link
Member

@davidzhao davidzhao Feb 4, 2025

Choose a reason for hiding this comment

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

IMO this doesn't belong as a default prompt. it would be weird if someone uses it in a sentence, and see it misspelled

) -> STT:
"""
Create a new instance of Groq STT.
Expand All @@ -123,6 +129,7 @@ def with_groq(
client=client,
language=language,
detect_language=detect_language,
prompt=prompt,
)

def _sanitize_options(self, *, language: str | None = None) -> _STTOptions:
Expand All @@ -148,6 +155,7 @@ async def _recognize_impl(
),
model=self._opts.model,
language=config.language,
prompt=self._opts.prompt,
# verbose_json returns language and other details
response_format="verbose_json",
timeout=httpx.Timeout(30, connect=conn_options.timeout),
Expand Down
Loading