-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Support stt model params setting #4056
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
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,23 @@ | ||
| # Generated by Django 5.2.4 on 2025-09-16 08:10 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('application', '0002_application_simple_mcp'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='application', | ||
| name='stt_model_params_setting', | ||
| field=models.JSONField(default=dict, verbose_name='STT模型参数相关设置'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='applicationversion', | ||
| name='stt_model_params_setting', | ||
| field=models.JSONField(default=dict, verbose_name='STT模型参数相关设置'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,14 +482,28 @@ | |
| </div> | ||
| </div> | ||
| </template> | ||
| <ModelSelect | ||
| <div class="flex-between w-full"> | ||
| <ModelSelect | ||
| v-show="applicationForm.stt_model_enable" | ||
| v-model="applicationForm.stt_model_id" | ||
| :placeholder="$t('views.application.form.voiceInput.placeholder')" | ||
| :options="sttModelOptions" | ||
| @change="sttModelChange" | ||
| :model-type="'STT'" | ||
| > | ||
| </ModelSelect> | ||
| > | ||
| </ModelSelect> | ||
|
|
||
| <el-button | ||
| v-if="applicationForm.stt_model_enable" | ||
| @click="openSTTParamSettingDialog" | ||
| :disabled="!applicationForm.stt_model_id" | ||
| class="ml-8" | ||
| > | ||
| <el-icon> | ||
| <Operation /> | ||
| </el-icon> | ||
| </el-button> | ||
| </div> | ||
| </el-form-item> | ||
| <el-form-item | ||
| prop="tts_model_id" | ||
|
|
@@ -583,6 +597,7 @@ | |
| <AIModeParamSettingDialog ref="AIModeParamSettingDialogRef" @refresh="refreshForm" /> | ||
| <GeneratePromptDialog @replace="replace" ref="GeneratePromptDialogRef" /> | ||
| <TTSModeParamSettingDialog ref="TTSModeParamSettingDialogRef" @refresh="refreshTTSForm" /> | ||
| <STTModeParamSettingDialog ref="STTModeParamSettingDialogRef" @refresh="refreshSTTForm" /> | ||
| <ParamSettingDialog ref="ParamSettingDialogRef" @refresh="refreshParam" /> | ||
| <AddKnowledgeDialog | ||
| ref="AddKnowledgeDialogRef" | ||
|
|
@@ -612,6 +627,7 @@ import { relatedObject } from '@/utils/array' | |
| import { MsgSuccess, MsgWarning } from '@/utils/message' | ||
| import { t } from '@/locales' | ||
| import TTSModeParamSettingDialog from './component/TTSModeParamSettingDialog.vue' | ||
| import STTModeParamSettingDialog from './component/STTModelParamSettingDialog.vue' | ||
| import ReasoningParamSettingDialog from './component/ReasoningParamSettingDialog.vue' | ||
| import permissionMap from '@/permission' | ||
| import { EditionConst } from '@/utils/permission/data' | ||
|
|
@@ -652,6 +668,7 @@ const optimizationPrompt = | |
| const AIModeParamSettingDialogRef = ref<InstanceType<typeof AIModeParamSettingDialog>>() | ||
| const ReasoningParamSettingDialogRef = ref<InstanceType<typeof ReasoningParamSettingDialog>>() | ||
| const TTSModeParamSettingDialogRef = ref<InstanceType<typeof TTSModeParamSettingDialog>>() | ||
| const STTModeParamSettingDialogRef = ref<InstanceType<typeof STTModeParamSettingDialog>>() | ||
| const ParamSettingDialogRef = ref<InstanceType<typeof ParamSettingDialog>>() | ||
| const GeneratePromptDialogRef = ref<InstanceType<typeof GeneratePromptDialog>>() | ||
|
|
||
|
|
@@ -756,6 +773,7 @@ const submit = async (formEl: FormInstance | undefined) => { | |
| if (!formEl) return | ||
| await formEl.validate((valid, fields) => { | ||
| if (valid) { | ||
| console.log(applicationForm.value) | ||
| loadSharedApi({ type: 'application', systemType: apiType.value }) | ||
| .putApplication(id, applicationForm.value, loading) | ||
| .then(() => { | ||
|
|
@@ -806,6 +824,17 @@ const openTTSParamSettingDialog = () => { | |
| } | ||
| } | ||
|
|
||
| const openSTTParamSettingDialog = () => { | ||
| if (applicationForm.value.stt_model_id) { | ||
| STTModeParamSettingDialogRef.value?.open( | ||
| applicationForm.value.stt_model_id, | ||
| id, | ||
| applicationForm.value.stt_model_params_setting, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const openParamSettingDialog = () => { | ||
| ParamSettingDialogRef.value?.open(applicationForm.value) | ||
| } | ||
|
|
@@ -905,6 +934,10 @@ function refreshTTSForm(data: any) { | |
| applicationForm.value.tts_model_params_setting = data | ||
| } | ||
|
|
||
| function refreshSTTForm(data: any) { | ||
| applicationForm.value.stt_model_params_setting = data | ||
| } | ||
|
|
||
| function removeKnowledge(id: any) { | ||
| if (applicationForm.value.knowledge_id_list) { | ||
| applicationForm.value.knowledge_id_list.splice( | ||
|
|
@@ -1022,6 +1055,14 @@ function ttsModelChange() { | |
| } | ||
| } | ||
|
|
||
| function sttModelChange() { | ||
| if (applicationForm.value.stt_model_id) { | ||
| STTModeParamSettingDialogRef.value?.reset_default(applicationForm.value.stt_model_id, id) | ||
| } else { | ||
| refreshSTTForm({}) | ||
| } | ||
| } | ||
|
|
||
| function ttsModelEnableChange() { | ||
| if (!applicationForm.value.tts_model_enable) { | ||
| applicationForm.value.tts_model_id = undefined | ||
|
Contributor
Author
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. There are no obvious irregularities or issues with the provided code snippet. However, here are some points and suggestions for improvement: Points to Consider:
Specific Suggestions:
If you have specific use cases or additional improvements in mind, please let me know! |
||
|
|
||
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.
The provided code has several areas that require consideration for both correctness and performance optimizations. Here are the main points to address:
Imports: Ensure all necessary imports at the beginning of the script, especially those related to handling WebSocket connections (
asyncio), JSON encoding/decoding (json), and SSL context setup.Deep Merge Function: The
deep_merge_dictfunction seems correct but can be optimized slightly. Consider using recursion directly without returning the dictionary explicitly in some cases if it's only needed internally.Optional Initialization Parameters: In
_new_instance, you're setting optional parameters conditionally based on existence checks within an empty dictionaryoptional_params. This could be done more efficiently if these values should always be present or defaulted elsewhere.Handling Empty Frames: There might be edge cases where frames can become empty after processing (e.g., no tokens passed). Adding checks around this could prevent invalid operations when sending back frames to the client.
JSON Encoding Issues: Make sure there aren't any issues with whitespace formatting or additional trailing commas in the JSON strings being sent, as this can cause parsing errors.
Exception Handling: For exception messages like
"", provide proper error messages rather than an empty string; better yet, log them appropriately.Code Readability: Although brief, consider adding comments explaining complex logic blocks or variable names for clarity when reviewing again after a refactoring pass.
Parameter Merging Logic: Adjust how parameters from
self.paramsare merged into frames to ensure only valid keys specific to SparkAPI are used.WS Connection Management: Ensure that the connection states handle exceptions gracefully during receive/send operations due to timeouts or disconnections. You might want to add retries or close/reconnect mechanisms depending on application needs.
By addressing these points, you'll improve robustness, readability, efficiency, and reliability of the implemented streaming speech-to-text service framework.