feat: Support reference model in ai chat node#4896
feat: Support reference model in ai chat node#4896zhanweizhang7 merged 2 commits intotool-workflowfrom
Conversation
|
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 nodeCascaderRef = ref() | ||
| const ReasoningParamSettingDialogRef = ref<InstanceType<typeof ReasoningParamSettingDialog>>() | ||
| const validate = () => { | ||
| return aiChatNodeFormRef.value?.validate().catch((err) => { |
There was a problem hiding this comment.
- Replace
set(appState.chat, "node_model_data.reasoning_info", {});withappState.node_model_data.reasoning_info = {};. - Adjust the conditional logic in the AI Chat Mode Param Setting Dialog to handle different conditions as needed.
| props.nodeModel.clear_next_node_field(true) | ||
| }) | ||
| .catch(() => { | ||
| set(props.nodeModel.properties, 'status', 500) |
There was a problem hiding this comment.
There are several areas where improvements could be made in the provided code:
-
Simplified
config_field_listCreation: The current method of creatingconfig_field_listuses nested ternary operators which can make it difficult to read and maintain. It's more readable to use plain JavaScript methods. -
Object Shallow Copying for Existing Fields: Instead of using
JSON.parse(JSON.stringify(...))when updating existing fields, we can directly modify them since they are arrays. However, this requires careful handling to ensure no unintended side effects. -
Clear Next Node Field Execution: Ensure that
props.nodeModel.clear_next_node_field(true)is called consistently throughout the function.
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:
- Simplified
config_field_listcreation. - Directly updated non-existing fields in
merge_input_list. - Merged existing config fields while preserving uniqueness.
- Ensured
clear_next_node_fieldexecution without modification risk.
Make sure to test this revised version thoroughly in your application environment to validate its functionality.
|
|
||
| if model_setting is None: | ||
| model_setting = {'reasoning_content_enable': False, 'reasoning_content_end': '</think>', | ||
| 'reasoning_content_start': '<think>'} |
There was a problem hiding this comment.
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.
fix: Tool workflow node result
feat: Support reference model in ai chat node