-
Notifications
You must be signed in to change notification settings - Fork 309
fix(deepgram): validate updated model with stored language #1755
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
base: 1.5.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
| this.#opts = { | ||
| ...this.#opts, | ||
| ...opts, | ||
| language, | ||
| model, | ||
| }; | ||
|
Comment on lines
+120
to
+131
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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', | ||
|
|
@@ -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 { | ||
|
|
||
There was a problem hiding this comment.
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 whenopts.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 inupdateOptions.For example: a user creates
new STT({ model: 'nova-2-meeting', language: 'en-US' })(valid), then callsupdateOptions({ language: 'fr' }). Themodelvariable at line 124 takes thethis.#opts.modelpath (no validation), resulting in'nova-2-meeting'being used with French — exactly the case#validateModelis supposed to catch.Was this helpful? React with 👍 or 👎 to provide feedback.