Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/deepgram-update-options-language.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/agents-plugin-deepgram": patch
---

Use stored language when validating Deepgram STT model updates.
51 changes: 32 additions & 19 deletions plugins/deepgram/src/stt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,34 @@ export class STT extends stt.STT {

if (this.#opts.detectLanguage) {
this.#opts.language = undefined;
} else if (
this.#opts.language &&
getBaseLanguage(this.#opts.language) !== 'en' &&
} else {
this.#opts.model = this.#validateModel(this.#opts.model, this.#opts.language);
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async _recognize(_: AudioBuffer): Promise<stt.SpeechEvent> {
throw new Error('Recognize is not supported on Deepgram STT');
}

updateOptions(opts: Partial<STTOptions>) {
const language =
opts.language !== undefined ? normalizeLanguage(opts.language) : this.#opts.language;
const model =
opts.model !== undefined ? this.#validateModel(opts.model, language) : this.#opts.model;
Comment on lines +123 to +124

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Model validation skipped when only language is updated via updateOptions

In updateOptions, the model is only validated when opts.model !== undefined. If a caller changes only the language (e.g., updateOptions({ language: 'fr' })) while the current model is an English-only one like 'nova-2-meeting', the validation is skipped and the incompatible model/language combination persists. This defeats the purpose of the PR, which is to ensure model validation happens in updateOptions.

For example: a user creates new STT({ model: 'nova-2-meeting', language: 'en-US' }) (valid), then calls updateOptions({ language: 'fr' }). The model variable at line 124 takes the this.#opts.model path (no validation), resulting in 'nova-2-meeting' being used with French — exactly the case #validateModel is supposed to catch.

Suggested change
const model =
opts.model !== undefined ? this.#validateModel(opts.model, language) : this.#opts.model;
const model = this.#validateModel(opts.model ?? this.#opts.model, language);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


this.#opts = {
...this.#opts,
...opts,
language,
model,
};
Comment on lines +120 to +131

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 detectLanguage flag not handled in updateOptions

The constructor at line 108-109 sets this.#opts.language = undefined when detectLanguage is true, and skips model validation. However, updateOptions does not mirror this behavior — if a caller passes updateOptions({ detectLanguage: true }), the language won't be cleared and the model validation still runs against the stale language. This is a pre-existing issue (the old code also didn't handle it), and may be intentionally left as a caller responsibility, but it creates an inconsistency between construction-time and update-time semantics.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}

#validateModel(model: STTModels, language?: string) {
if (
language &&
getBaseLanguage(language) !== 'en' &&
[
'nova-2-meeting',
'nova-2-phonecall',
Expand All @@ -121,27 +146,15 @@ export class STT extends stt.STT {
'nova-2-drivethru',
'nova-2-automotive',
'nova-3-general',
].includes(this.#opts.model)
].includes(model)
) {
this.#logger.warn(
`${this.#opts.model} does not support language ${this.#opts.language}, falling back to nova-2-general`,
`${model} does not support language ${language}, falling back to nova-2-general`,
);
this.#opts.model = 'nova-2-general';
return 'nova-2-general';
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async _recognize(_: AudioBuffer): Promise<stt.SpeechEvent> {
throw new Error('Recognize is not supported on Deepgram STT');
}

updateOptions(opts: Partial<STTOptions>) {
this.#opts = {
...this.#opts,
...opts,
language:
opts.language !== undefined ? normalizeLanguage(opts.language) : this.#opts.language,
};
return model;
}

stream(options?: { connOptions?: APIConnectOptions }): SpeechStream {
Expand Down