-
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
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 |
|---|---|---|
|
|
@@ -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> | ||
|
|
||
|
|
@@ -100,12 +110,17 @@ import { computed, onMounted, ref, inject } from 'vue' | |
| import { groupBy, set } from 'lodash' | ||
| import NodeCascader from '@/workflow/common/NodeCascader.vue' | ||
| import type { FormInstance } from 'element-plus' | ||
| import { MsgSuccess } from '@/utils/message' | ||
| import { t } from '@/locales' | ||
| import { useRoute } from 'vue-router' | ||
| import { loadSharedApi } from '@/utils/dynamics-api/shared-api' | ||
| import STTModeParamSettingDialog from '@/views/application/component/STTModelParamSettingDialog.vue' | ||
| const getApplicationDetail = inject('getApplicationDetail') as any | ||
| const route = useRoute() | ||
|
|
||
| const {} = route as any | ||
| const { | ||
| params: { id }, | ||
| } = route as any | ||
|
|
||
| const apiType = computed(() => { | ||
| if (route.path.includes('resource-management')) { | ||
|
|
@@ -117,6 +132,8 @@ const apiType = computed(() => { | |
|
|
||
| const props = defineProps<{ nodeModel: any }>() | ||
| const modelOptions = ref<any>(null) | ||
| const STTModeParamSettingDialogRef = ref<InstanceType<typeof STTModeParamSettingDialog>>() | ||
|
|
||
|
|
||
| const aiChatNodeFormRef = ref<FormInstance>() | ||
| const nodeCascaderRef = ref() | ||
|
|
@@ -143,6 +160,7 @@ const form = { | |
| stt_model_id: '', | ||
| is_result: true, | ||
| audio_list: [], | ||
| model_params_setting: {}, | ||
| } | ||
|
|
||
| const form_data = computed({ | ||
|
|
@@ -159,6 +177,25 @@ const form_data = computed({ | |
| }, | ||
| }) | ||
|
|
||
|
|
||
| const openSTTParamSettingDialog = () => { | ||
| const model_id = form_data.value.stt_model_id | ||
| if (!model_id) { | ||
| MsgSuccess(t('views.application.form.voiceInput.requiredMessage')) | ||
| return | ||
| } | ||
| STTModeParamSettingDialogRef.value?.open( | ||
| model_id, | ||
| id, | ||
| form_data.value.model_params_setting, | ||
| ) | ||
| } | ||
|
|
||
| const refreshSTTForm = (data: any) => { | ||
| form_data.value.model_params_setting = data | ||
| } | ||
|
|
||
|
|
||
| const application = getApplicationDetail() | ||
| function getSelectModel() { | ||
| const obj = | ||
|
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. This code appears to be mostly syntactically correct, but it contains several areas that could benefit from improvements. Here are some suggestions:
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. |
||
|
|
||
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:
Detailed Changes Made:
Renaming Variables:
restoformattedDataconsistently.Added Comment Breaks to enhance readability.
These changes make the code more readable and maintainable while keeping it functional.