-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: Support reference model in ai chat node #4896
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 |
|---|---|---|
|
|
@@ -13,10 +13,10 @@ | |
| > | ||
| <el-form-item | ||
| :label="$t('views.application.form.aiModel.label')" | ||
| prop="model_id" | ||
| :prop="chat_data.model_id_type === 'reference' ? 'model_id_reference' : 'model_id'" | ||
| :rules="{ | ||
| required: true, | ||
| message: $t('views.application.form.aiModel.placeholder'), | ||
| message: chat_data.model_id_type === 'reference' ? $t('workflow.variable.placeholder') : $t('views.application.form.aiModel.placeholder'), | ||
| trigger: 'change', | ||
| }" | ||
| > | ||
|
|
@@ -28,7 +28,27 @@ | |
| }}<span class="color-danger">*</span></span | ||
| > | ||
| </div> | ||
|
|
||
| <el-select v-model="chat_data.model_id_type" :teleported="false" size="small" style="width: 85px" @change="chat_data.model_id_reference = []"> | ||
| <el-option :label="$t('workflow.variable.Referencing')" value="reference" /> | ||
| <el-option :label="$t('common.custom')" value="custom" /> | ||
| </el-select> | ||
| </div> | ||
| </template> | ||
| <div class="flex-between w-full" v-if="chat_data.model_id_type !== 'reference'"> | ||
| <div> | ||
| <ModelSelect | ||
| @change="model_change" | ||
| @wheel="wheel" | ||
| :teleported="false" | ||
| v-model="chat_data.model_id" | ||
| :placeholder="$t('views.application.form.aiModel.placeholder')" | ||
| :options="modelOptions" | ||
| @submitModel="getSelectModel" | ||
| showFooter | ||
| :model-type="'LLM'" | ||
| ></ModelSelect> | ||
| </div> | ||
| <div class="ml-8"> | ||
| <el-button | ||
| :disabled="!chat_data.model_id" | ||
| type="primary" | ||
|
|
@@ -39,18 +59,15 @@ | |
| <AppIcon iconName="app-setting"></AppIcon> | ||
| </el-button> | ||
| </div> | ||
| </template> | ||
| <ModelSelect | ||
| @change="model_change" | ||
| @wheel="wheel" | ||
| :teleported="false" | ||
| v-model="chat_data.model_id" | ||
| :placeholder="$t('views.application.form.aiModel.placeholder')" | ||
| :options="modelOptions" | ||
| @submitModel="getSelectModel" | ||
| showFooter | ||
| :model-type="'LLM'" | ||
| ></ModelSelect> | ||
| </div> | ||
| <NodeCascader | ||
| v-else | ||
| ref="nodeCascaderRef" | ||
| :nodeModel="nodeModel" | ||
| class="w-full" | ||
| :placeholder="$t('workflow.variable.placeholder')" | ||
| v-model="chat_data.model_id_reference" | ||
| /> | ||
| </el-form-item> | ||
|
|
||
| <el-form-item> | ||
|
|
@@ -71,7 +88,7 @@ | |
| type="primary" | ||
| link | ||
| @click="openGeneratePromptDialog(chat_data.model_id)" | ||
| :disabled="!chat_data.model_id" | ||
| :disabled="chat_data.model_id_type === 'reference' || !chat_data.model_id" | ||
| > | ||
| <AppIcon iconName="app-generate-star"></AppIcon> | ||
| </el-button> | ||
|
|
@@ -458,6 +475,7 @@ | |
| <script setup lang="ts"> | ||
| import { cloneDeep, set, groupBy } from 'lodash' | ||
| import NodeContainer from '@/workflow/common/NodeContainer.vue' | ||
| import NodeCascader from '@/workflow/common/NodeCascader.vue' | ||
| import type { FormInstance } from 'element-plus' | ||
| import { ref, computed, onMounted, inject, reactive } from 'vue' | ||
| import { isLastNode } from '@/workflow/common/data' | ||
|
|
@@ -532,6 +550,8 @@ const collapseData = reactive({ | |
|
|
||
| const form = { | ||
| model_id: '', | ||
| model_id_type: 'custom', | ||
| model_id_reference: [], | ||
| system: '', | ||
| prompt: defaultPrompt, | ||
| dialogue_number: 1, | ||
|
|
@@ -556,6 +576,12 @@ const chat_data = computed({ | |
| reasoning_content_enable: false, | ||
| }) | ||
| } | ||
| if (!props.nodeModel.properties.node_data.model_id_type) { | ||
| set(props.nodeModel.properties.node_data, 'model_id_type', 'custom') | ||
| } | ||
| if (!props.nodeModel.properties.node_data.model_id_reference) { | ||
| set(props.nodeModel.properties.node_data, 'model_id_reference', []) | ||
| } | ||
| return props.nodeModel.properties.node_data | ||
| } else { | ||
| set(props.nodeModel.properties, 'node_data', form) | ||
|
|
@@ -573,6 +599,7 @@ const aiChatNodeFormRef = ref<FormInstance>() | |
|
|
||
| const modelOptions = ref<any>(null) | ||
| const AIModeParamSettingDialogRef = ref<InstanceType<typeof AIModeParamSettingDialog>>() | ||
| const nodeCascaderRef = ref() | ||
| const ReasoningParamSettingDialogRef = ref<InstanceType<typeof ReasoningParamSettingDialog>>() | ||
| const validate = () => { | ||
| return aiChatNodeFormRef.value?.validate().catch((err) => { | ||
|
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.
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,26 +150,21 @@ const update_field = () => { | |
| loadSharedApi({ type: 'tool', systemType: apiType.value }) | ||
| .getToolById(props.nodeModel.properties.node_data.tool_lib_id) | ||
| .then((ok: any) => { | ||
| console.log('ssss', ok.data) | ||
|
|
||
| const workflowNodes = ok.data?.work_flow?.nodes || [] | ||
| const baseNode = workflowNodes.find((n: any) => n.type === 'tool-base-node') | ||
|
|
||
| if (baseNode) { | ||
| const new_input_list = baseNode.properties.user_input_field_list || [] | ||
| const new_output_list = baseNode.properties.user_output_field_list || [] | ||
|
|
||
| let config_field_list: any[] = [] | ||
| if (new_output_list.length > 0) { | ||
| config_field_list = new_output_list.map((item: any) => ({ | ||
| label: item.label, | ||
| value: item.field, | ||
| })) | ||
| } | ||
| const old_config_fields = props.nodeModel.properties.config?.fields || [] | ||
| const config_field_list = new_output_list.map((item: any) => { | ||
| const old = old_config_fields.find((o: any) => o.value === item.field) | ||
| return old ? JSON.parse(JSON.stringify(old)) : { label: item.label, value: item.field } | ||
| }) | ||
|
|
||
| const input_title = baseNode.properties.user_input_config?.title | ||
| const output_title = baseNode.properties.user_output_config?.title | ||
|
|
||
| const old_input_list = props.nodeModel.properties.node_data.input_field_list || [] | ||
| const merged_input_list = new_input_list.map((item: any) => { | ||
| const find_field = old_input_list.find((old_item: any) => old_item.field === item.field) | ||
|
|
@@ -185,11 +180,14 @@ const update_field = () => { | |
| }) | ||
|
|
||
| set(props.nodeModel.properties.node_data, 'input_field_list', merged_input_list) | ||
| set(props.nodeModel.properties.config, 'fields', config_field_list) | ||
| set(props.nodeModel.properties, 'config', { | ||
| fields: config_field_list, | ||
| output_title: output_title, | ||
| }) | ||
| set(props.nodeModel.properties.node_data, 'input_title', input_title) | ||
| set(props.nodeModel.properties.config, 'output_title', output_title) | ||
| } | ||
| set(props.nodeModel.properties, 'status', ok.data.is_active ? 200 : 500) | ||
| props.nodeModel.clear_next_node_field(true) | ||
| }) | ||
| .catch(() => { | ||
| set(props.nodeModel.properties, 'status', 500) | ||
|
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 several areas where improvements could be made in the provided code:
Here’s an optimized version of the code with these considerations: const update_field = () => {
loadSharedApi({ type: 'tool', systemType: apiType.value })
.getToolById(props.nodeModel.properties.node_data.tool_lib_id)
.then((ok: any) => {
const workflowNodes = ok.data?.work_flow?.nodes || [];
const baseNode = workflowNodes.find((n: any) => n.type === 'tool-base-node');
if (baseNode) {
const new_input_list = baseNode.properties.user_input_field_list || [];
const new_output_list = baseNode.properties.user_output_field_list || [];
// Create config_fields list from new_output_list
let config_field_list = new_output_list.map(item => ({ label: item.label, value: item.field }));
// Update original node data with new lists
const old_input_list = props.nodeModel.properties.node_data.input_field_list || [];
const merged_input_list = new_input_list.map(item => {
const findField = old_input_list.find(oldItem => oldItem.field === item.field);
return findField || item;
});
set(props.nodeModel.properties.node_data, 'input_field_list', merged_input_list);
// Handle merging config fields
const oldConfigFields = props.nodeModel.properties.config.fields || [];
config_field_list.forEach(newField => {
const existingIndex = oldConfigFields.findIndex(ocf => ocf.value === newField.value);
if (existingIndex !== -1) {
// If field already exists, do nothing or merge properties accordingly
config_field_list[existingIndex] = { ...oldConfigFields[existingIndex], ...newField };
} else {
// Add new field if not found
config_field_list.push(newField);
}
});
const input_title = baseNode.properties.user_input_config?.title;
const output_title = baseNode.properties.user_output_config?.title;
set(props.nodeModel.properties.node_data, 'input_title', input_title);
set(props.nodeModel.properties.config, 'output_title', output_title);
// Clear next node field(s), assuming clear_next_node_field accepts a boolean condition
props.nodeModel.clear_next_node_field(true);
set(props.nodeModel.properties, 'status', ok.data.is_active ? 200 : 500);
}
// Set fallback status on failure
}).catch(() => {
set(props.nodeModel.properties, 'status', 500);
});
};Key Changes:
Make sure to test this revised version thoroughly in your application environment to validate its functionality. |
||
|
|
||
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 improvements and corrections to ensure its functionality:
Model ID Type Handling: The logic to handle
model_id_typeandmodel_id_referencefields is enhanced. It checks ifmodel_id_typeis set to'reference'and ifmodel_id_referenceis not empty before attempting to fetch reference data using the workflow manager.Default Model Parameters Setting Retrieval: If no
model_params_settingis provided, it retrieves a default setting from the system for the givenmodel_id. This addresses cases where a specific configuration might be required but was not explicitly passed.Comments and Consistency: A comment is added explaining that comments may need more context about what they represent after further development on this line.
These changes make the function more robust, cleaner, and adaptable based on various conditions encountered during execution.