-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: IMG TTV node support reference model #4949
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,13 @@ | |
| > | ||
| <el-form-item | ||
| :label="$t('workflow.nodes.imageUnderstandNode.model.label')" | ||
| prop="model_id" | ||
| :prop="form_data.model_id_type === 'reference' ? 'model_id_reference' : 'model_id'" | ||
| :rules="{ | ||
| required: true, | ||
| message: $t('workflow.nodes.imageUnderstandNode.model.requiredMessage'), | ||
| message: | ||
| form_data.model_id_type === 'reference' | ||
| ? $t('workflow.variable.placeholder') | ||
| : $t('workflow.nodes.imageUnderstandNode.model.requiredMessage'), | ||
| trigger: 'change', | ||
| }" | ||
| > | ||
|
|
@@ -28,29 +31,49 @@ | |
| }}<span class="color-danger">*</span></span | ||
| > | ||
| </div> | ||
| <el-select | ||
| v-model="form_data.model_id_type" | ||
| :teleported="false" | ||
| size="small" | ||
| style="width: 85px" | ||
| @change="form_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="form_data.model_id_type !== 'reference'"> | ||
| <ModelSelect | ||
| @wheel="wheel" | ||
| :teleported="false" | ||
| v-model="form_data.model_id" | ||
| :placeholder="$t('workflow.nodes.imageUnderstandNode.model.requiredMessage')" | ||
| :options="modelOptions" | ||
| showFooter | ||
| :model-type="'IMAGE'" | ||
| ></ModelSelect> | ||
| <div class="ml-8"> | ||
| <el-button | ||
| :disabled="!form_data.model_id" | ||
| type="primary" | ||
| link | ||
| @click="openAIParamSettingDialog(form_data.model_id)" | ||
| @refreshForm="refreshParam" | ||
| > | ||
| <AppIcon iconName="app-setting"></AppIcon> | ||
| <el-icon> | ||
| <Operation /> | ||
| </el-icon> | ||
| </el-button> | ||
| </div> | ||
| </template> | ||
|
|
||
| <ModelSelect | ||
| @wheel="wheel" | ||
| :teleported="false" | ||
| v-model="form_data.model_id" | ||
| :placeholder="$t('workflow.nodes.imageUnderstandNode.model.requiredMessage')" | ||
| :options="modelOptions" | ||
| showFooter | ||
| :model-type="'IMAGE'" | ||
| ></ModelSelect> | ||
| </div> | ||
| <NodeCascader | ||
| v-else | ||
| ref="nodeCascaderRef" | ||
| :nodeModel="nodeModel" | ||
| class="w-full" | ||
| :placeholder="$t('workflow.variable.placeholder')" | ||
| v-model="form_data.model_id_reference" | ||
| /> | ||
| </el-form-item> | ||
|
|
||
| <el-form-item> | ||
| <template #label> | ||
| <div class="flex-between"> | ||
|
|
@@ -262,6 +285,8 @@ const defaultPrompt = `{{${t('workflow.nodes.startNode.label')}.question}}` | |
|
|
||
| const form = { | ||
| model_id: '', | ||
| model_id_type: 'custom', | ||
| model_id_reference: [], | ||
| system: '', | ||
| prompt: defaultPrompt, | ||
| dialogue_number: 0, | ||
|
|
@@ -275,6 +300,12 @@ const form = { | |
| const form_data = computed({ | ||
| get: () => { | ||
| if (props.nodeModel.properties.node_data) { | ||
| 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) | ||
|
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. The provided code has several issues that need to be addressed:
Here's an improved version of the code with these issues resolved: const form_data = computed({
get: () => {
if (props.nodeModel.properties.node_data) {
return props.nodeModel.properties.node_data;
} else {
return { ...defaultProps };
}
},
});
watch(
() => props.nodeModel.properties.node_data,
newValue => {
Object.assign(form_data.value, newValue);
}
);
function handleModelTypeChange(value) {
if (value === 'reference') {
form_data.value.model_id_reference.splice(0);
}
}
const ModelSelectRef = ref(null);
const NodeCascaderRef = ref(null);
// Use this function to refresh parameter settings when needed.
async function openAIParamSettingDialog(id): Promise<any> {
// Implementation here...
}
function wheel() {
// Wheel event handler implementation here...
}Key points:
This should help improve stability and performance while maintaining clarity and integrity. |
||
|
|
||
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 code is mostly correct but can be optimized for better readability and functionality. Here are some suggestions:
Optimal Code
Reduce Redundancy:
Improve Logic:
Handle State Consistency:
Here's an improved version of the specified part of your code:
Explanation
Default Selection: The
model_id_typestarts as "custom". If not provided in the saved data, it defaults this way.Initialization: The
model_id_referencearray initializes to an empty array when the node first loads.Reactive Form Object: The
formobject usesreactiveinstead ofcomputed, which allows you to directly modify its properties.Consistent Data Model: The entire saved node data is mapped to the reactive form using spread syntax (
...). This maintains consistency and reduces redundant checks.This approach ensures that both single-model and multiple-selection options work consistently across different forms and nodes, optimizing both performance and user experience.