-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: STT node #4108
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
fix: STT node #4108
Conversation
--bug=1062113 --user=张展玮 【应用】语音转文本节点,没有支持模型参数设置 https://www.tapd.cn/62980211/s/1778991
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| const application = getApplicationDetail() | ||
| function getSelectModel() { | ||
| const obj = |
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.
This code appears to be mostly syntactically correct, but it contains several areas that could benefit from improvements. Here are some suggestions:
-
Unused Imports:
MsgSuccessandtfrom'@/utils/message', along with'@/locales'should only be imported if used within their respective modules.
-
Unnecessary Variable Declaration:
- The line
{}seems unnecessary and can likely be removed.
- The line
-
Duplicate Route Parameter Usage:
- There's a duplicate usage of route parameters in the comment:
${}) as anyinside theonMountedhook. It might be better to use the new variableiddirectly unless there's a specific reason for this duplication.
- There's a duplicate usage of route parameters in the comment:
-
Function Scope:
- The function
getSelectModelis defined after its usage. While not technically incorrect, it would generally be cleaner to place it at the beginning of functions where variables are declared before being used.
- The function
-
Code Readability and Structure:
- Ensure proper indentation and spacing for readability. Adjust the line lengths to fit comfortably in an editor without wrapping them excessively.
Here is a revised version keeping these points in mind:
@@ -28,6 +28,15 @@
}}<span class="color-danger">*</span></span
>
</div>
+ <el-button
+ type="primary"
+ link
+ @click="openSTTParamSettingDialog"
+ :disabled="!form_data.stt_model_id"
+ class="mr-4"
+ >
+ <AppIcon iconName="app-setting"></AppIcon>
+ </el-button>
</div>
</template>
<ModelSelect
@@ -91,6 +100,7 @@
</el-form-item>
</el-form>
</el-card>
+ <STTModeParamSettingDialog ref="STTModeParamSettingDialogRef" @refresh="refreshSTTForm" />
</NodeContainer>
</template>
<script lang="ts">
import {
nextTick,
watchEffect,
defineComponent,
PropType,
reactive,
} from "vue";
import { cloneDeep } from 'lodash';
// ... other imports
import ModelSelect from './components/ModelSelect.vue';
export default defineComponent({
components: {
// Components
},
props: {
nodeModel: Object as PropType<Node>,
},
setup(props) {
const apiType = computed(() => {
// ...
});
const route = useRouter();
const id = computed((): string => route.params.id);
// Refs
const aiChatNodeFormRef = ref<FormElement>();
const nodeCascaderRef = ref();
const modelOptions = ref([]);
// Reactive state
const form = reactive({
stt_model_id: "",
is_result: true,
audio_list: [],
model_params_setting: {},
});
const form_data = computed(() => ({
// Compute properties
}));
// Methods
const openSTTParamSettingDialog = () => {
// ...
};
const refreshSTTTForm = (data: any) => {
// ...
};
// Fetching and setting initial data
async function fetchData() {
try {
applicationInfo.data.data.config.is_voice_input_enabled &&
loadSharedApi(apiType.value).listModels().then((res) => {
console.log(res);
modelOptions.value = res.models;
});
await nextTick(async () => {
loadSharedApi(apiType.value).getModel(id.value).then(response => {
let tmpData = response;
if (
props.nodeModel.settings?.voice_settings &&
props.nodeModel.settings.voice_settings.stt_mode_param_setting &&
!response.model_params_setting &&
!!props.nodeModel.settings.voice_settings.stt_mode_param_setting.id
) {
tmpData.model_params_setting =
props.nodeModel.settings.voice_settings.stt_mode_param_setting;
set(form, ["audio_list", "0"], "");
}
// Apply changes to the main form state using lodash deep copy
applyChanges(tmpData);
}, error => {
console.error(`There was an error while trying to fetch models ${error}`);
});
})
} catch(error) { console.error("Error fetching application configuration:", error); }
}
watchEffect(() => {
if (!application.config.is_voice_input_enabled || props.nodeModel.disabled) return;
fetchData();
});
const applyChanges = (tmpData: Config) => {
// ...
}
return {
applyChanges,
aiChatNodeFormRef,
getSelectModel,
fetchModels,
nodeCascaderRef,
refreshSTTForm,
};
},
});
</script>These adjustments improve code organization and consistency, ensuring readability and maintainability.
| model_setting_data = { ...resp, ...model_setting_data } | ||
| // 渲染动态表单 | ||
| dynamicsFormRef.value?.render(model_form_field.value, model_setting_data) | ||
| }) |
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 is mostly well-structured, but here are a few improvements to address some potential issues:
-
Variable Naming Consistency: Ensure consistent naming conventions for variables throughout the function. For example,
const resin one place should be renamed to match elsewhere. -
Type Annotations: While TypeScript does not change variable type assignments based on value, adding explicit types where appropriate can help catch errors early.
-
Code Readability: Consider breaking down long lines of code into multiple lines with proper indentation for better readability.
-
Functionality Verification: Ensure that
openmethod correctly processes the response and updates the UI accordingly.
Here's an improved version of the code incorporating these suggestions:
@@ -71,20 +71,28 @@
.getModelParamsForm(model_id, loading)
.then((ok: any) => {
model_form_field.value = ok.data;
const formattedData = ok.data.map(item =>
({
[item.field]: item.show_default_value !== false ? item.default_value : undefined,
})
).reduce((prev, curr) => ({ ...prev, ...curr }), {});
if (model_setting_data) {
Object.keys(model_setting_data).forEach(key => {
if (!(key in formattedData)) {
delete model_setting_data[key];
}
});
}
let updatedModelSettingData = { ...formattedData, ...model_setting_data };
// Render dynamic form
dynamicsFormRef.value?.render(model_form_field.value, updatedModelSettingData);
});Detailed Changes Made:
-
Renaming Variables:
- Change
restoformattedDataconsistently.
- Change
-
Added Comment Breaks to enhance readability.
These changes make the code more readable and maintainable while keeping it functional.
fix: STT node --bug=1062113 --user=张展玮 【应用】语音转文本节点,没有支持模型参数设置 https://www.tapd.cn/62980211/s/1778991