feat: llm node add context

This commit is contained in:
zhaoying
2026-01-04 12:06:24 +08:00
parent 02c8fd0e3f
commit 351be8aaf3
10 changed files with 233 additions and 150 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { useTranslation } from 'react-i18next'
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { MinusCircleOutlined } from '@ant-design/icons';
import { Button, Form, Input, Space } from 'antd';
interface MappingListProps {
@@ -33,8 +33,8 @@ const MappingList: React.FC<MappingListProps> = ({ name }) => {
</Space>
))}
<Form.Item>
<Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}>
Add field
<Button type="dashed" onClick={() => add()} block>
+ {t('common.add')}
</Button>
</Form.Item>
</>

View File

@@ -1,4 +1,4 @@
import { type FC } from 'react';
import { type FC, useMemo } from 'react';
import { useTranslation } from 'react-i18next'
import { Input, Form, Space, Button, Row, Col, Select, type FormListOperation } from 'antd';
import { MinusCircleOutlined } from '@ant-design/icons';
@@ -31,6 +31,24 @@ const MessageEditor: FC<TextareaProps> = ({
const form = Form.useFormInstance();
const values = form.getFieldsValue()
// 检查是否已经使用了context变量将已使用的context设置为disabled
const processedOptions = useMemo(() => {
if (!isArray || !values[parentName]) return options;
// 获取所有消息内容
const allContents = values[parentName]
.map((msg: any) => msg.content || '')
.join(' ');
// 将已使用的context变量标记为disabled
return options.map(opt => {
if (opt.isContext && allContents.includes(opt.value)) {
return { ...opt, disabled: true };
}
return opt;
});
}, [options, values, parentName, isArray]);
const handleAdd = (add: FormListOperation['add']) => {
const list = values[parentName];
const lastRole = list[list.length - 1].role
@@ -80,7 +98,7 @@ const MessageEditor: FC<TextareaProps> = ({
name={[name, 'content']}
noStyle
>
<Editor placeholder={placeholder} options={options} />
<Editor placeholder={placeholder} options={processedOptions} />
</Form.Item>
</Space>
)
@@ -104,7 +122,7 @@ const MessageEditor: FC<TextareaProps> = ({
name={parentName}
noStyle
>
<Editor placeholder={placeholder} options={options} />
<Editor placeholder={placeholder} options={processedOptions} />
</Form.Item>
</Space>
}

View File

@@ -330,9 +330,30 @@ const Properties: FC<PropertiesProps> = ({
}
if (selectedNode?.data?.type === 'llm' && key === 'messages' && config.type === 'define') {
// 为llm节点且isArray=true时添加context变量支持
let contextVariableList = [...variableList];
const isArrayMode = config.isArray !== false; // 默认为true
if (isArrayMode) {
const contextKey = `${selectedNode.id}_context`;
const hasContextVariable = contextVariableList.some(v => v.key === contextKey);
if (!hasContextVariable) {
contextVariableList.unshift({
key: contextKey,
label: 'context',
type: 'variable',
dataType: 'String',
value: `{{context}}`,
nodeData: selectedNode.getData(),
isContext: true,
});
}
}
return (
<Form.Item key={key} name={key}>
<MessageEditor options={variableList} parentName={key} />
<MessageEditor options={contextVariableList} parentName={key} />
</Form.Item>
)
}