Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions framework/elsa/fit-elsa-react/src/common/Consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export const VIRTUAL_CONTEXT_NODE = {
name: 'systemEnv',
};

export const VIRTUAL_CONTEXT_NODE_VARIABLES = {
INSTANCE_ID: 'instanceId',
APP_ID: 'appId',
MEMORIES: 'memories',
USE_MEMORY: 'useMemory',
USER_ID: 'userId',
FILE_URLS: 'fileUrls',
CHAT_ID: 'chatId',
};

export const CONNECTOR = {
RADIUS: 6,
CONDITION_RADIUS: 4,
Expand Down Expand Up @@ -177,4 +187,21 @@ export const RENDER_TYPE = {
RADIO: 'Radio',
INPUT: 'Input',
SWITCH: 'Switch',
};

export const DEFAULT_LOOP_NODE_CONTEXT = {
id: uuidv4(),
name: 'context',
type: DATA_TYPES.OBJECT,
from: FROM_TYPE.EXPAND,
value: {
id: uuidv4(),
name: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
type: DATA_TYPES.STRING,
from: FROM_TYPE.REFERENCE,
referenceId: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
referenceKey: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID,
referenceNode: VIRTUAL_CONTEXT_NODE.id,
value: [VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ChangeFlowMetaReducer} from '@/components/common/reducers/commonReducers
import {ChangePluginByMetaDataReducer, DeletePluginReducer, UpdateInputReducer, UpdateRadioInfoReducer} from '@/components/loopNode/reducers/reducers.js';
import {defaultComponent} from '@/components/defaultComponent.js';
import {v4 as uuidv4} from 'uuid';
import {DATA_TYPES, FROM_TYPE} from '@/common/Consts.js';
import {DATA_TYPES, DEFAULT_LOOP_NODE_CONTEXT, FROM_TYPE} from '@/common/Consts.js';

export const loopComponent = (jadeConfig, shape) => {
const self = defaultComponent(jadeConfig);
Expand Down Expand Up @@ -50,6 +50,7 @@ export const loopComponent = (jadeConfig, shape) => {
from: FROM_TYPE.INPUT,
value: {},
},
DEFAULT_LOOP_NODE_CONTEXT,
],
outputParams: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const loopNodeState = (id, x, y, width, height, parent, drawer) => {
self.flowMeta.jober.type = 'STORE_JOBER';
const loopNodeEntity = {
uniqueName: "",
params: [{"name": "args"}, {"name": "config"}, {"name": "toolInfo"}],
params: [{"name": "args"}, {"name": "config"}, {"name": "toolInfo"}, {"name": "context"}],
return: {type: "array"}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DATA_TYPES,
DEFAULT_KNOWLEDGE_REPO_GROUP_STRUCT,
DEFAULT_LLM_KNOWLEDGE_BASES,
DEFAULT_LLM_REFERENCE_OUTPUT,
DEFAULT_LLM_REFERENCE_OUTPUT, DEFAULT_LOOP_NODE_CONTEXT,
DEFAULT_MAX_MEMORY_ROUNDS,
END_NODE_TYPE,
FLOW_TYPE,
Expand Down Expand Up @@ -49,6 +49,8 @@ export const pageCompatibilityProcessor = (pageData, graph) => {
return knowledgeRetrievalCompatibilityProcessor(shapeData, g, self);
case 'questionClassificationNodeCondition':
return questionClassificationCompatibilityProcessor(shapeData, g, self);
case 'loopNodeState':
return loopNodeCompatibilityProcessor(shapeData, g, self);
default:
return shapeCompatibilityProcessor(shapeData, g, self);
}
Expand Down Expand Up @@ -185,6 +187,30 @@ export const questionClassificationCompatibilityProcessor = (shapeData, graph, p
return self;
};

/**
* 循环节点兼容性处理器.
*
* @override
*/
export const loopNodeCompatibilityProcessor = (shapeData, graph, pageHandler) => {
const self = shapeCompatibilityProcessor(shapeData, graph, pageHandler);

/**
* @override
*/
const process = self.process;
self.process = () => {
process.apply(self);
const jober = self.shapeData.flowMeta.jober;
if (!jober.entity.params.exist(param => param.name === 'context')) {
jober.entity.params.push({name: 'context'});
jober.converter.entity.inputParams.push(DEFAULT_LOOP_NODE_CONTEXT);
}
};

return self;
};


/**
* 开始节点兼容性处理器.
Expand Down Expand Up @@ -281,43 +307,9 @@ export const endNodeCompatibilityProcessor = (shapeData, graph, pageHandler) =>
if (inputParam.from !== FROM_TYPE.EXPAND) {
return;
}

// const values = inputParam.value;
//
// // 第一个引用若不是大模型,则后续的所有大模型节点enableLog都是false.
// // 若第一个引用是对大模型的引用,遍历,后续【连续】的对大模型节点的引用.
const llmNodes = self.pageProcessor.getShapes(sd => sd.type === 'llmNodeState').map((n, i) => {
return {index: i, data: n};
});
//
// let indexes = []; // 记录所有需要输出日志的大模型的下标.
// for (let i = 0; i < values.length; i++) {
// const input = values[i];
//
// // 不是reference,或referenceKey不存在,退出循环.
// if (input.from !== 'Reference' || !input.referenceKey) {
// break;
// }
//
// // 引用的不是大模型,退出循环.
// const node = llmNodes.find(n => n.data.id === input.referenceNode);
// if (!node) {
// break;
// }
//
// // 当前大模型节点的index小于indexes中的值,跳出循环.
// if (indexes.length > 0 && node.index < indexes[indexes.length - 1]) {
// break;
// }
//
// const chainNodes = self.pageProcessor.getNodesBetween(node.data, self.shapeData);
// if (chainNodes.contains(n => n.type === 'conditionNodeCondition' || n.type === 'manualCheckNodeState')) {
// break;
// }
//
// indexes.push(node.index);
// }

updateLlmFlowMetas(llmNodes);
};

Expand Down
16 changes: 8 additions & 8 deletions framework/elsa/fit-elsa-react/src/shapes/systemEnv.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*--------------------------------------------------------------------------------------------*/

import {rectangle} from '@fit-elsa/elsa-core';
import {VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
import {DATA_TYPES, VIRTUAL_CONTEXT_NODE, VIRTUAL_CONTEXT_NODE_VARIABLES} from '@/common/Consts.js';
import {emptyStatusManager} from '@/components/base/emptyStatusManager.js';

/**
Expand All @@ -25,13 +25,13 @@ export const systemEnv = (id, x, y, width, height, parent) => {
self.width = 0;
self.height = 0;
self.virtualNodeInfoList = [
{observableId: 'instanceId', value: 'instanceId', type: 'String'},
{observableId: 'appId', value: 'appId', type: 'String'},
{observableId: 'memories', value: 'memories', type: 'Array'},
{observableId: 'useMemory', value: 'useMemory', type: 'Boolean'},
{observableId: 'userId', value: 'userId', type: 'String'},
{observableId: 'fileUrls', value: 'fileUrls', type: 'Array'},
{observableId: 'chatId', value: 'chatId', type: 'String'},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.INSTANCE_ID, type: DATA_TYPES.STRING},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.APP_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.APP_ID, type: DATA_TYPES.STRING},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.MEMORIES, value: VIRTUAL_CONTEXT_NODE_VARIABLES.MEMORIES, type: DATA_TYPES.ARRAY},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.USE_MEMORY, value: VIRTUAL_CONTEXT_NODE_VARIABLES.USE_MEMORY, type: DATA_TYPES.BOOLEAN},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.USER_ID, type: DATA_TYPES.STRING},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.FILE_URLS, value: VIRTUAL_CONTEXT_NODE_VARIABLES.FILE_URLS, type: DATA_TYPES.ARRAY},
{observableId: VIRTUAL_CONTEXT_NODE_VARIABLES.CHAT_ID, value: VIRTUAL_CONTEXT_NODE_VARIABLES.CHAT_ID, type: DATA_TYPES.STRING},
];
self.statusManager = emptyStatusManager(self);

Expand Down