Merge #101 into develop_web from feature/20251219_zy
feat: llm node add context * feature/20251219_zy: (2 commits) feat(web): forgetting engine config feat: llm node add context Signed-off-by: zhaoying <zhaoying@redbearai.com> Merged-by: zhaoying <zhaoying@redbearai.com> CR-link: https://codeup.aliyun.com/redbearai/python/redbear-mem-open/change/101
This commit is contained in:
@@ -157,11 +157,11 @@ export const deleteMemoryConfig = (config_id: number) => {
|
|||||||
}
|
}
|
||||||
// 遗忘引擎-获取配置
|
// 遗忘引擎-获取配置
|
||||||
export const getMemoryForgetConfig = (config_id: number | string) => {
|
export const getMemoryForgetConfig = (config_id: number | string) => {
|
||||||
return request.get('/memory-storage/read_config_forget', { config_id })
|
return request.get('/memory/forget/read_config', { config_id })
|
||||||
}
|
}
|
||||||
// 遗忘引擎-更新配置
|
// 遗忘引擎-更新配置
|
||||||
export const updateMemoryForgetConfig = (values: ForgetConfigForm) => {
|
export const updateMemoryForgetConfig = (values: ForgetConfigForm) => {
|
||||||
return request.post('/memory-storage/update_config_forget', values)
|
return request.post('/memory/forget/update_config', values)
|
||||||
}
|
}
|
||||||
// 记忆萃取引擎-获取配置
|
// 记忆萃取引擎-获取配置
|
||||||
export const getMemoryExtractionConfig = (config_id: number | string) => {
|
export const getMemoryExtractionConfig = (config_id: number | string) => {
|
||||||
|
|||||||
@@ -1616,6 +1616,7 @@ Memory Bear: After the rebellion, regional warlordism intensified for several re
|
|||||||
model_id: 'Model',
|
model_id: 'Model',
|
||||||
temperature: 'Temperature',
|
temperature: 'Temperature',
|
||||||
max_tokens: 'Max Tokens',
|
max_tokens: 'Max Tokens',
|
||||||
|
context: 'Context',
|
||||||
},
|
},
|
||||||
start: {
|
start: {
|
||||||
variables: 'Input Fields',
|
variables: 'Input Fields',
|
||||||
|
|||||||
@@ -1716,6 +1716,7 @@ export const zh = {
|
|||||||
model_id: '模型',
|
model_id: '模型',
|
||||||
temperature: '温度',
|
temperature: '温度',
|
||||||
max_tokens: '最大令牌数',
|
max_tokens: '最大令牌数',
|
||||||
|
context: '上下文',
|
||||||
},
|
},
|
||||||
start: {
|
start: {
|
||||||
variables: '输入字段',
|
variables: '输入字段',
|
||||||
|
|||||||
@@ -3,6 +3,39 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import ReactEcharts from 'echarts-for-react';
|
import ReactEcharts from 'echarts-for-react';
|
||||||
import type { ConfigForm } from '../types'
|
import type { ConfigForm } from '../types'
|
||||||
|
|
||||||
|
// 定义当前数据类型
|
||||||
|
type CurrentDataItem = {
|
||||||
|
name: string;
|
||||||
|
data: number[];
|
||||||
|
config: ConfigForm | {};
|
||||||
|
type: string;
|
||||||
|
smooth: boolean;
|
||||||
|
lineStyle: { width: number };
|
||||||
|
showSymbol: boolean;
|
||||||
|
label: { show: boolean; position: string };
|
||||||
|
emphasis: { focus: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
// 定义图表系列数据类型
|
||||||
|
type SeriesDataItem = {
|
||||||
|
name: string;
|
||||||
|
data: number[];
|
||||||
|
config: ChartConfig;
|
||||||
|
type: string;
|
||||||
|
smooth: boolean;
|
||||||
|
lineStyle: { width: number };
|
||||||
|
showSymbol: boolean;
|
||||||
|
label: { show: boolean; position: string };
|
||||||
|
emphasis: { focus: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
// 定义简化的配置类型,只包含图表计算需要的属性
|
||||||
|
interface ChartConfig {
|
||||||
|
lambda_mem: number;
|
||||||
|
lambda_time: number;
|
||||||
|
offset: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface LineCardProps {
|
interface LineCardProps {
|
||||||
config: ConfigForm
|
config: ConfigForm
|
||||||
}
|
}
|
||||||
@@ -29,14 +62,14 @@ const Colors = ['#155EEF', '#4DA8FF', '#FFB048']
|
|||||||
const LineChart: FC<LineCardProps> = ({ config }) => {
|
const LineChart: FC<LineCardProps> = ({ config }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const chartRef = useRef<ReactEcharts>(null);
|
const chartRef = useRef<ReactEcharts>(null);
|
||||||
const debounceRef = useRef()
|
const debounceRef = useRef<number>()
|
||||||
const resizeScheduledRef = useRef(false)
|
const resizeScheduledRef = useRef(false)
|
||||||
const xAxisData = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]
|
const xAxisData = [1, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60]
|
||||||
const [initialData, setInitialData] = useState([])
|
const [initialData, setInitialData] = useState<SeriesDataItem[]>([])
|
||||||
const [currentData, setCurrentData] = useState({
|
const [currentData, setCurrentData] = useState<CurrentDataItem>({
|
||||||
...SeriesConfig,
|
...SeriesConfig,
|
||||||
name: `${t('forgettingEngine.currentConfig')}(λ_time=${config?.lambda_mem})`,
|
name: `${t('forgettingEngine.currentConfig')}(λ_time=${config?.lambda_mem})`,
|
||||||
data: [],
|
data: [] as number[],
|
||||||
config: {}
|
config: {}
|
||||||
})
|
})
|
||||||
const seriesData = useMemo(() => [
|
const seriesData = useMemo(() => [
|
||||||
@@ -44,19 +77,26 @@ const LineChart: FC<LineCardProps> = ({ config }) => {
|
|||||||
...SeriesConfig,
|
...SeriesConfig,
|
||||||
name: `${t('forgettingEngine.quicklyForget')}(λ_time=0.3)`,
|
name: `${t('forgettingEngine.quicklyForget')}(λ_time=0.3)`,
|
||||||
data: [],
|
data: [],
|
||||||
config: {lambda_mem: 0.3, lambda_time: 1, offset: 0.05}
|
config: {lambda_mem: 0.3, lambda_time: 1, offset: 0.05} as ChartConfig
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...SeriesConfig,
|
...SeriesConfig,
|
||||||
name: `${t('forgettingEngine.slowForgetting')}(λ_time=1)`,
|
name: `${t('forgettingEngine.slowForgetting')}(λ_time=1)`,
|
||||||
data: [],
|
data: [],
|
||||||
config: {lambda_mem: 1, lambda_time: 0.3, offset: 0.2}
|
config: {lambda_mem: 1, lambda_time: 0.3, offset: 0.2} as ChartConfig
|
||||||
}
|
}
|
||||||
], [t])
|
], [t])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getInitData()
|
getInitData()
|
||||||
}, [])
|
}, [t])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 语言切换时重新生成数据
|
||||||
|
if (config) {
|
||||||
|
getCaculateData(config)
|
||||||
|
}
|
||||||
|
}, [t, config])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
@@ -101,14 +141,14 @@ const LineChart: FC<LineCardProps> = ({ config }) => {
|
|||||||
setInitialData(list)
|
setInitialData(list)
|
||||||
}, [seriesData])
|
}, [seriesData])
|
||||||
|
|
||||||
const calculateSeriesData = useCallback((days: number, data: ConfigForm) => {
|
const calculateSeriesData = useCallback((days: number, data: ChartConfig | ConfigForm) => {
|
||||||
const offset = Number(data.offset)
|
const offset = Number(data.offset)
|
||||||
const lambda_time = Number(data.lambda_time)
|
const lambda_time = Number(data.lambda_time)
|
||||||
const lambda_mem = Number(data.lambda_mem)
|
const lambda_mem = Number(data.lambda_mem)
|
||||||
// R = offset + (1 - offset) × e^(-λtime × t / (λmem × S))
|
// R = offset + (1 - offset) × e^(-λtime × t / (λmem × S))
|
||||||
return +(offset + (1 - offset) * Math.exp(-lambda_time * days / lambda_mem)).toFixed(4)
|
return +(offset + (1 - offset) * Math.exp(-lambda_time * days / lambda_mem)).toFixed(4)
|
||||||
}, [])
|
}, [])
|
||||||
const formatData = useCallback((data: ConfigForm) => {
|
const formatData = useCallback((data: ChartConfig | ConfigForm) => {
|
||||||
return xAxisData.map(days => Number(calculateSeriesData(days, data)))
|
return xAxisData.map(days => Number(calculateSeriesData(days, data)))
|
||||||
}, [calculateSeriesData])
|
}, [calculateSeriesData])
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Row, Col, Form, Slider, Button, Space, message } from 'antd';
|
import { Row, Col, Form, Slider, Button, Space, message, Switch } from 'antd';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import RbCard from '@/components/RbCard/Card';
|
import RbCard from '@/components/RbCard/Card';
|
||||||
@@ -18,19 +18,72 @@ const configList = [
|
|||||||
{
|
{
|
||||||
key: 'forgettingRate',
|
key: 'forgettingRate',
|
||||||
name: 'lambda_mem',
|
name: 'lambda_mem',
|
||||||
range: [0, 1],
|
range: [0.01, 1],
|
||||||
type: 'decimal',
|
type: 'decimal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'offset',
|
key: 'offset',
|
||||||
name: 'offset',
|
name: 'offset',
|
||||||
|
range: [0, 1],
|
||||||
type: 'decimal',
|
type: 'decimal',
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
key: 'decay_constant',
|
||||||
|
name: 'decay_constant',
|
||||||
|
range: [0, 1],
|
||||||
|
type: 'decimal',
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'max_history_length',
|
||||||
|
name: 'max_history_length',
|
||||||
|
type: 'decimal',
|
||||||
|
step: 1,
|
||||||
|
range: [10, 1000],
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'forgetting_threshold',
|
||||||
|
name: 'forgetting_threshold',
|
||||||
|
type: 'decimal',
|
||||||
|
range: [0, 1],
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'min_days_since_access',
|
||||||
|
name: 'min_days_since_access',
|
||||||
|
type: 'decimal',
|
||||||
|
step: 1,
|
||||||
|
range: [1, 365],
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'enable_llm_summary',
|
||||||
|
name: 'enable_llm_summary',
|
||||||
|
type: 'button',
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'max_merge_batch_size',
|
||||||
|
name: 'max_merge_batch_size',
|
||||||
|
type: 'decimal',
|
||||||
|
step: 1,
|
||||||
|
range: [1, 1000],
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'forgetting_interval_hours',
|
||||||
|
name: 'forgetting_interval_hours',
|
||||||
|
type: 'decimal',
|
||||||
|
step: 1,
|
||||||
|
range: [1, 168],
|
||||||
|
hiddenDesc: true,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const ForgettingEngine: React.FC = () => {
|
const ForgettingEngine: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const params = useParams();
|
const { id } = useParams();
|
||||||
const [configData, setConfigData] = useState<ConfigForm>();
|
const [configData, setConfigData] = useState<ConfigForm>();
|
||||||
const [form] = Form.useForm<ConfigForm>();
|
const [form] = Form.useForm<ConfigForm>();
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
@@ -43,7 +96,7 @@ const ForgettingEngine: React.FC = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const getConfigData = () => {
|
const getConfigData = () => {
|
||||||
getMemoryForgetConfig(params.id)
|
getMemoryForgetConfig(id as string)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const response = res as ConfigForm
|
const response = res as ConfigForm
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
@@ -60,12 +113,12 @@ const ForgettingEngine: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
form.setFieldsValue(configData);
|
form.setFieldsValue(configData || {});
|
||||||
}
|
}
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
updateMemoryForgetConfig({
|
updateMemoryForgetConfig({
|
||||||
config_id: params.id,
|
config_id: id,
|
||||||
...values
|
...values
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -83,7 +136,7 @@ const ForgettingEngine: React.FC = () => {
|
|||||||
<RbCard
|
<RbCard
|
||||||
title={
|
title={
|
||||||
<div className="rb:flex rb:items-center">
|
<div className="rb:flex rb:items-center">
|
||||||
<img src={strategyImpactSimulator} className="rb:w-[20px] rb:h-[20px] rb:mr-[8px]" />
|
<img src={strategyImpactSimulator} className="rb:w-5 rb:h-5 rb:mr-2" />
|
||||||
{t('forgettingEngine.forgettingEngineConfigParams')}
|
{t('forgettingEngine.forgettingEngineConfigParams')}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -99,28 +152,60 @@ const ForgettingEngine: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Space size={24} direction="vertical" style={{ width: '100%' }}>
|
<Space size={24} direction="vertical" style={{ width: '100%' }}>
|
||||||
{configList.map(config => (
|
{configList.map(config => {
|
||||||
<div key={config.key}>
|
if (config.type === 'button') {
|
||||||
<div className="rb:text-[14px] rb:font-medium rb:leading-[20px] rb:mb-[8px]">
|
return (
|
||||||
{t(`forgettingEngine.${config.key}`)}
|
<div key={config.key} className="rb:mb-2">
|
||||||
|
<div className="rb:flex rb:items-center rb:justify-between">
|
||||||
|
<div>
|
||||||
|
<span className="rb:text-[14px] rb:font-medium rb:leading-5">{t(`forgettingEngine.${config.key}`)}</span>
|
||||||
|
</div>
|
||||||
|
<Form.Item
|
||||||
|
name={config.name}
|
||||||
|
valuePropName="checked"
|
||||||
|
className="rb:ml-2 rb:mb-0!"
|
||||||
|
>
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
<div className="rb:flex rb:text-[12px] rb:items-center rb:justify-between rb:text-[#5B6167] rb:leading-5">
|
||||||
|
<Space size={4}>
|
||||||
|
{config.range && <span>{t(`forgettingEngine.range`)}: {config.range?.join('-')}</span>}
|
||||||
|
{config.type && <span>{t(`forgettingEngine.type`)}: {config.type}</span>}
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div key={config.key}>
|
||||||
|
<div className="rb:text-[14px] rb:font-medium rb:leading-5 rb:mb-2">
|
||||||
|
{t(`forgettingEngine.${config.key}`)}
|
||||||
|
</div>
|
||||||
|
{!config.hiddenDesc && <div className="rb:mt-1 rb:text-[12px] rb:text-[#5B6167] rb:font-regular rb:leading-4 ">
|
||||||
|
{t(`forgettingEngine.${config.key}Desc`)}
|
||||||
|
</div>}
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name={config.name}
|
||||||
|
>
|
||||||
|
{config.type === 'decimal'
|
||||||
|
? <Slider tooltip={{ open: false }} max={config.range?.[1] || 1} min={config.range?.[0] || 0} step={config.step ?? 0.01} style={{ margin: '0' }} />
|
||||||
|
: config.type === 'button'
|
||||||
|
? <Switch />
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</Form.Item>
|
||||||
|
<div className="rb:flex rb:text-[12px] rb:items-center rb:justify-between rb:text-[#5B6167] rb:leading-5 rb:-mt-6.5">
|
||||||
|
<Space size={4}>
|
||||||
|
{config.range && <span>{t(`forgettingEngine.range`)}: {config.range?.join('-')}</span>}
|
||||||
|
{config.type && <span>{t(`forgettingEngine.type`)}: {config.type}</span>}
|
||||||
|
</Space>
|
||||||
|
<>{t('forgettingEngine.CurrentValue')}: {values?.[config.name] || 0}</>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="rb:mt-[4px] rb:text-[12px] rb:text-[#5B6167] rb:font-regular rb:leading-[16px] ">
|
)
|
||||||
{t(`forgettingEngine.${config.key}Desc`)}
|
})}
|
||||||
</div>
|
|
||||||
<Form.Item
|
|
||||||
name={config.name}
|
|
||||||
>
|
|
||||||
<Slider tooltip={{open: false}} max={config.range?.[1] || 1} min={config.range?.[0] || 0} step={0.01} style={{ margin: '0' }} />
|
|
||||||
</Form.Item>
|
|
||||||
<div className="rb:flex rb:text-[12px] rb:items-center rb:justify-between rb:text-[#5B6167] rb:leading-[20px] rb:mt-[-26px]">
|
|
||||||
<Space size={4}>
|
|
||||||
{config.range && <span>{t(`forgettingEngine.range`)}: {config.range?.join('-')}</span>}
|
|
||||||
{config.type && <span>{t(`forgettingEngine.type`)}: {config.type}</span>}
|
|
||||||
</Space>
|
|
||||||
<>{t('forgettingEngine.CurrentValue')}: {values?.[config.name] || 0}</>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Button block onClick={handleReset}>{t('common.reset')}</Button>
|
<Button block onClick={handleReset}>{t('common.reset')}</Button>
|
||||||
@@ -135,7 +220,6 @@ const ForgettingEngine: React.FC = () => {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={15}>
|
<Col span={15}>
|
||||||
<RbCard
|
<RbCard
|
||||||
className='rb:h-full!'
|
|
||||||
>
|
>
|
||||||
<LineChart
|
<LineChart
|
||||||
config={values}
|
config={values}
|
||||||
|
|||||||
@@ -40,11 +40,17 @@ export interface CurveRecord {
|
|||||||
|
|
||||||
export interface ConfigForm {
|
export interface ConfigForm {
|
||||||
config_id?: string;
|
config_id?: string;
|
||||||
statement_granularity?: string;
|
|
||||||
include_dialogue_context?: boolean;
|
|
||||||
max_context?: string;
|
|
||||||
lambda_time: string | number;
|
lambda_time: string | number;
|
||||||
lambda_mem: string | number;
|
lambda_mem: string | number;
|
||||||
offset: string | number;
|
offset: string | number;
|
||||||
|
|
||||||
|
decay_constant: string | number;
|
||||||
|
max_history_length: string | number;
|
||||||
|
forgetting_threshold: string | number;
|
||||||
|
min_days_since_access: string | number;
|
||||||
|
enable_llm_summary: boolean;
|
||||||
|
max_merge_batch_size: string | number;
|
||||||
|
forgetting_interval_hours: string | number;
|
||||||
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
@@ -42,13 +42,21 @@ const VariableComponent: React.FC<{ nodeKey: NodeKey; data: Suggestion }> = ({
|
|||||||
})}
|
})}
|
||||||
contentEditable={false}
|
contentEditable={false}
|
||||||
>
|
>
|
||||||
<img
|
{data.isContext ? (
|
||||||
src={data.nodeData?.icon}
|
<span style={{ fontSize: '12px', marginRight: '4px' }}>📄</span>
|
||||||
style={{ width: '12px', height: '12px', marginRight: '4px' }}
|
) : (
|
||||||
alt=""
|
<img
|
||||||
/>
|
src={data.nodeData?.icon}
|
||||||
<span className="rb:wrap-break-word rb:line-clamp-1">{data.nodeData?.name}</span>
|
style={{ width: '12px', height: '12px', marginRight: '4px' }}
|
||||||
<span style={{ color: '#DFE4ED', margin: '0 2px' }}>/</span>
|
alt=""
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!data.isContext && (
|
||||||
|
<>
|
||||||
|
<span className="rb:wrap-break-word rb:line-clamp-1">{data.nodeData?.name}</span>
|
||||||
|
<span style={{ color: '#DFE4ED', margin: '0 2px' }}>/</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<span className="rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap rb:flex-1" style={{ color: '#155EEF' }}>{data.label}</span>
|
<span className="rb:text-ellipsis rb:overflow-hidden rb:whitespace-nowrap rb:flex-1" style={{ color: '#155EEF' }}>{data.label}</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ export interface Suggestion {
|
|||||||
type: string;
|
type: string;
|
||||||
dataType: string;
|
dataType: string;
|
||||||
value: string;
|
value: string;
|
||||||
nodeData: NodeProperties
|
nodeData: NodeProperties;
|
||||||
|
isContext?: boolean; // 标记是否为context变量
|
||||||
|
disabled?: boolean; // 标记是否禁用
|
||||||
}
|
}
|
||||||
|
|
||||||
const AutocompletePlugin: FC<{ options: Suggestion[] }> = ({ options }) => {
|
const AutocompletePlugin: FC<{ options: Suggestion[] }> = ({ options }) => {
|
||||||
@@ -131,19 +133,20 @@ const AutocompletePlugin: FC<{ options: Suggestion[] }> = ({ options }) => {
|
|||||||
key={option.key}
|
key={option.key}
|
||||||
style={{
|
style={{
|
||||||
padding: '8px 12px',
|
padding: '8px 12px',
|
||||||
cursor: 'pointer',
|
cursor: option.disabled ? 'not-allowed' : 'pointer',
|
||||||
background: selectedIndex === globalIndex ? '#f0f8ff' : 'white',
|
background: selectedIndex === globalIndex ? '#f0f8ff' : 'white',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
|
opacity: option.disabled ? 0.5 : 1,
|
||||||
}}
|
}}
|
||||||
onClick={() => insertMention(option)}
|
onClick={() => !option.disabled && insertMention(option)}
|
||||||
onMouseEnter={() => setSelectedIndex(globalIndex)}
|
onMouseEnter={() => setSelectedIndex(globalIndex)}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
background: option.type === 'context' ? '#722ed1' :
|
background: option.isContext ? '#722ed1' :
|
||||||
option.type === 'system' ? '#1890ff' : '#52c41a',
|
option.type === 'system' ? '#1890ff' : '#52c41a',
|
||||||
color: 'white',
|
color: 'white',
|
||||||
padding: '2px 6px',
|
padding: '2px 6px',
|
||||||
@@ -153,7 +156,7 @@ const AutocompletePlugin: FC<{ options: Suggestion[] }> = ({ options }) => {
|
|||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{option.type === 'context' ? '📄' :
|
{option.isContext ? '📄' :
|
||||||
option.type === 'system' ? 'x' : 'x'}
|
option.type === 'system' ? 'x' : 'x'}
|
||||||
</span>
|
</span>
|
||||||
<span style={{ fontSize: '14px' }}>{option.label}</span>
|
<span style={{ fontSize: '14px' }}>{option.label}</span>
|
||||||
|
|||||||
@@ -25,7 +25,20 @@ const InitialValuePlugin: React.FC<InitialValuePluginProps> = ({ value, options
|
|||||||
|
|
||||||
parts.forEach(part => {
|
parts.forEach(part => {
|
||||||
const match = part.match(/^\{\{([^.]+)\.([^}]+)\}\}$/);
|
const match = part.match(/^\{\{([^.]+)\.([^}]+)\}\}$/);
|
||||||
|
const contextMatch = part.match(/^\{\{context\}\}$/);
|
||||||
|
|
||||||
|
// 匹配{{context}}格式
|
||||||
|
if (contextMatch) {
|
||||||
|
const contextSuggestion = options.find(s => s.isContext && s.label === 'context');
|
||||||
|
if (contextSuggestion) {
|
||||||
|
paragraph.append($createVariableNode(contextSuggestion));
|
||||||
|
} else {
|
||||||
|
paragraph.append($createTextNode(part));
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配普通变量{{nodeId.label}}格式
|
||||||
if (match) {
|
if (match) {
|
||||||
const [_, nodeId, label] = match;
|
const [_, nodeId, label] = match;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next'
|
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';
|
import { Button, Form, Input, Space } from 'antd';
|
||||||
|
|
||||||
interface MappingListProps {
|
interface MappingListProps {
|
||||||
@@ -33,8 +33,8 @@ const MappingList: React.FC<MappingListProps> = ({ name }) => {
|
|||||||
</Space>
|
</Space>
|
||||||
))}
|
))}
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}>
|
<Button type="dashed" onClick={() => add()} block>
|
||||||
Add field
|
+ {t('common.add')}
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type FC } from 'react';
|
import { type FC, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { Input, Form, Space, Button, Row, Col, Select, type FormListOperation } from 'antd';
|
import { Input, Form, Space, Button, Row, Col, Select, type FormListOperation } from 'antd';
|
||||||
import { MinusCircleOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined } from '@ant-design/icons';
|
||||||
@@ -31,6 +31,24 @@ const MessageEditor: FC<TextareaProps> = ({
|
|||||||
const form = Form.useFormInstance();
|
const form = Form.useFormInstance();
|
||||||
const values = form.getFieldsValue()
|
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 handleAdd = (add: FormListOperation['add']) => {
|
||||||
const list = values[parentName];
|
const list = values[parentName];
|
||||||
const lastRole = list[list.length - 1].role
|
const lastRole = list[list.length - 1].role
|
||||||
@@ -80,7 +98,7 @@ const MessageEditor: FC<TextareaProps> = ({
|
|||||||
name={[name, 'content']}
|
name={[name, 'content']}
|
||||||
noStyle
|
noStyle
|
||||||
>
|
>
|
||||||
<Editor placeholder={placeholder} options={options} />
|
<Editor placeholder={placeholder} options={processedOptions} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Space>
|
</Space>
|
||||||
)
|
)
|
||||||
@@ -104,7 +122,7 @@ const MessageEditor: FC<TextareaProps> = ({
|
|||||||
name={parentName}
|
name={parentName}
|
||||||
noStyle
|
noStyle
|
||||||
>
|
>
|
||||||
<Editor placeholder={placeholder} options={options} />
|
<Editor placeholder={placeholder} options={processedOptions} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,9 +330,30 @@ const Properties: FC<PropertiesProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selectedNode?.data?.type === 'llm' && key === 'messages' && config.type === 'define') {
|
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 (
|
return (
|
||||||
<Form.Item key={key} name={key}>
|
<Form.Item key={key} name={key}>
|
||||||
<MessageEditor options={variableList} parentName={key} />
|
<MessageEditor options={contextVariableList} parentName={key} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ export const nodeLibrary: NodeLibrary[] = [
|
|||||||
step: 1,
|
step: 1,
|
||||||
defaultValue: 2000
|
defaultValue: 2000
|
||||||
},
|
},
|
||||||
|
context: {
|
||||||
|
type: 'variableList',
|
||||||
|
},
|
||||||
messages: {
|
messages: {
|
||||||
type: 'define',
|
type: 'define',
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
@@ -142,27 +145,27 @@ export const nodeLibrary: NodeLibrary[] = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// { type: "classification", icon: classificationIcon },
|
// { type: "classification", icon: classificationIcon },
|
||||||
// { type: "parameter-extractor", icon: parameterExtractionIcon,
|
{ type: "parameter-extractor", icon: parameterExtractionIcon,
|
||||||
// config: {
|
config: {
|
||||||
// model_id: {
|
model_id: {
|
||||||
// type: 'customSelect',
|
type: 'customSelect',
|
||||||
// url: getModelListUrl,
|
url: getModelListUrl,
|
||||||
// params: { type: 'llm,chat' }, // llm/chat
|
params: { type: 'llm,chat' }, // llm/chat
|
||||||
// valueKey: 'id',
|
valueKey: 'id',
|
||||||
// labelKey: 'name',
|
labelKey: 'name',
|
||||||
// },
|
},
|
||||||
// text: {
|
text: {
|
||||||
// type: 'variableList',
|
type: 'variableList',
|
||||||
// },
|
},
|
||||||
// params: {
|
params: {
|
||||||
// type: 'paramList',
|
type: 'paramList',
|
||||||
// },
|
},
|
||||||
// prompt: {
|
prompt: {
|
||||||
// type: 'messageEditor',
|
type: 'messageEditor',
|
||||||
// isArray: false,
|
isArray: false,
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
@@ -182,115 +185,115 @@ export const nodeLibrary: NodeLibrary[] = [
|
|||||||
// { type: "agent_arbitration", icon: agentArbitrationIcon }
|
// { type: "agent_arbitration", icon: agentArbitrationIcon }
|
||||||
// ]
|
// ]
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// category: "flowControl",
|
category: "flowControl",
|
||||||
// nodes: [
|
nodes: [
|
||||||
// { type: "if-else", icon: conditionIcon,
|
{ type: "if-else", icon: conditionIcon,
|
||||||
// config: {
|
config: {
|
||||||
// cases: {
|
cases: {
|
||||||
// type: 'caseList',
|
type: 'caseList',
|
||||||
// defaultValue: [
|
defaultValue: [
|
||||||
// {
|
{
|
||||||
// logical_operator: 'and',
|
logical_operator: 'and',
|
||||||
// expressions: []
|
expressions: []
|
||||||
// }
|
}
|
||||||
// ]
|
]
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// // { type: "iteration", icon: iterationIcon },
|
// { type: "iteration", icon: iterationIcon },
|
||||||
// { type: "loop", icon: loopIcon },
|
// { type: "loop", icon: loopIcon },
|
||||||
// // { type: "parallel", icon: parallelIcon },
|
// { type: "parallel", icon: parallelIcon },
|
||||||
// { type: "var-aggregator", icon: aggregatorIcon,
|
{ type: "var-aggregator", icon: aggregatorIcon,
|
||||||
// config: {
|
config: {
|
||||||
// group: {
|
group: {
|
||||||
// type: 'switch',
|
type: 'switch',
|
||||||
// defaultValue: false
|
defaultValue: false
|
||||||
// },
|
},
|
||||||
// group_names: {
|
group_names: {
|
||||||
// type: 'groupVariableList',
|
type: 'groupVariableList',
|
||||||
// defaultValue: [{ key: 'Group1', value: []}]
|
defaultValue: [{ key: 'Group1', value: []}]
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ]
|
]
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// category: "externalInteraction",
|
category: "externalInteraction",
|
||||||
// nodes: [
|
nodes: [
|
||||||
// { type: "http-request", icon: httpRequestIcon,
|
{ type: "http-request", icon: httpRequestIcon,
|
||||||
// config: {
|
config: {
|
||||||
// method: {
|
method: {
|
||||||
// type: 'select',
|
type: 'select',
|
||||||
// options: [
|
options: [
|
||||||
// { label: 'GET', value: 'GET' },
|
{ label: 'GET', value: 'GET' },
|
||||||
// { label: 'POST', value: 'POST' },
|
{ label: 'POST', value: 'POST' },
|
||||||
// { label: 'HEAD', value: 'HEAD' },
|
{ label: 'HEAD', value: 'HEAD' },
|
||||||
// { label: 'PATCH', value: 'PATCH' },
|
{ label: 'PATCH', value: 'PATCH' },
|
||||||
// { label: 'PUT', value: 'PUT' },
|
{ label: 'PUT', value: 'PUT' },
|
||||||
// { label: 'DELETE', value: 'DELETE' },
|
{ label: 'DELETE', value: 'DELETE' },
|
||||||
// ],
|
],
|
||||||
// defaultValue: 'GET'
|
defaultValue: 'GET'
|
||||||
// },
|
},
|
||||||
// url: {
|
url: {
|
||||||
// type: 'messageEditor',
|
type: 'messageEditor',
|
||||||
// isArray: false,
|
isArray: false,
|
||||||
// },
|
},
|
||||||
// auth: {
|
auth: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {
|
defaultValue: {
|
||||||
// auth_type: 'none'
|
auth_type: 'none'
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// headers: {
|
headers: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {}
|
defaultValue: {}
|
||||||
// },
|
},
|
||||||
// params: {
|
params: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {}
|
defaultValue: {}
|
||||||
// },
|
},
|
||||||
// body: {
|
body: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {
|
defaultValue: {
|
||||||
// 'content_type': 'none'
|
'content_type': 'none'
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// verify_ssl: {
|
verify_ssl: {
|
||||||
// type: 'switch',
|
type: 'switch',
|
||||||
// defaultValue: false
|
defaultValue: false
|
||||||
// },
|
},
|
||||||
// timeouts: {
|
timeouts: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {}
|
defaultValue: {}
|
||||||
// },
|
},
|
||||||
// retry: {
|
retry: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// },
|
},
|
||||||
// error_handle: {
|
error_handle: {
|
||||||
// type: 'define',
|
type: 'define',
|
||||||
// defaultValue: {
|
defaultValue: {
|
||||||
// method: 'default'
|
method: 'default'
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// // { type: "tools", icon: toolsIcon },
|
// { type: "tools", icon: toolsIcon },
|
||||||
// // { type: "code_execution", icon: codeExecutionIcon },
|
// { type: "code_execution", icon: codeExecutionIcon },
|
||||||
// { type: "jinja-render", icon: templateRenderingIcon,
|
{ type: "jinja-render", icon: templateRenderingIcon,
|
||||||
// config: {
|
config: {
|
||||||
// mapping: {
|
mapping: {
|
||||||
// type: 'mappingList',
|
type: 'mappingList',
|
||||||
// defaultValue: []
|
defaultValue: []
|
||||||
// },
|
},
|
||||||
// template: {
|
template: {
|
||||||
// type: 'messageEditor',
|
type: 'messageEditor',
|
||||||
// isArray: false,
|
isArray: false,
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ]
|
]
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// category: "safetyAndCompliance",
|
// category: "safetyAndCompliance",
|
||||||
// nodes: [
|
// nodes: [
|
||||||
|
|||||||
@@ -160,7 +160,12 @@ export const useWorkflowGraph = ({
|
|||||||
graphRef.current?.addNodes(nodeList)
|
graphRef.current?.addNodes(nodeList)
|
||||||
}
|
}
|
||||||
if (edges.length) {
|
if (edges.length) {
|
||||||
const edgeList = edges.map(edge => {
|
// 去重处理:相同节点之间的连线仅连一次
|
||||||
|
const uniqueEdges = edges.filter((edge, index, arr) => {
|
||||||
|
return arr.findIndex(e => e.source === edge.source && e.target === edge.target) === index;
|
||||||
|
});
|
||||||
|
|
||||||
|
const edgeList = uniqueEdges.map(edge => {
|
||||||
const { source, target, label } = edge
|
const { source, target, label } = edge
|
||||||
const sourceCell = graphRef.current?.getCellById(source)
|
const sourceCell = graphRef.current?.getCellById(source)
|
||||||
const targetCell = graphRef.current?.getCellById(target)
|
const targetCell = graphRef.current?.getCellById(target)
|
||||||
@@ -788,6 +793,11 @@ export const useWorkflowGraph = ({
|
|||||||
const targetCell = graphRef.current?.getCellById(edge.getTargetCellId());
|
const targetCell = graphRef.current?.getCellById(edge.getTargetCellId());
|
||||||
const sourcePortId = edge.getSourcePortId();
|
const sourcePortId = edge.getSourcePortId();
|
||||||
|
|
||||||
|
// 过滤无效连线:源节点或目标节点不存在
|
||||||
|
if (!sourceCell?.getData()?.id || !targetCell?.getData()?.id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是if-else节点的右侧端口连线,添加label
|
// 如果是if-else节点的右侧端口连线,添加label
|
||||||
if (sourceCell?.getData()?.type === 'if-else' && sourcePortId?.startsWith('CASE')) {
|
if (sourceCell?.getData()?.type === 'if-else' && sourcePortId?.startsWith('CASE')) {
|
||||||
return {
|
return {
|
||||||
@@ -801,6 +811,11 @@ export const useWorkflowGraph = ({
|
|||||||
source: sourceCell?.getData().id,
|
source: sourceCell?.getData().id,
|
||||||
target: targetCell?.getData().id,
|
target: targetCell?.getData().id,
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
.filter(edge => edge !== null)
|
||||||
|
.filter((edge, index, arr) => {
|
||||||
|
// 去重:相同节点之间的连线仅保留一次
|
||||||
|
return arr.findIndex(e => e && e.source === edge?.source && e.target === edge?.target) === index;
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
saveWorkflowConfig(config.app_id, params as WorkflowConfig)
|
saveWorkflowConfig(config.app_id, params as WorkflowConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user