import React, { useState, useEffect } from 'react'; import { Row, Col, Form, App, Button, Switch, Space, Select } from 'antd'; import { useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import RbCard from '@/components/RbCard/Card'; import strategyImpactSimulator from '@/assets/images/memory/strategyImpactSimulator.svg' import { getMemoryReflectionConfig, updateMemoryReflectionConfig, pilotRunMemoryReflectionConfig } from '@/api/memory' import type { ConfigForm, Result, ReflexionData, MemoryVerify, QualityAssessment } from './types' import CustomSelect from '@/components/CustomSelect'; import { getModelListUrl } from '@/api/models' import Tag from '@/components/Tag' const configList = [ // 启用反思引擎 { key: 'reflection_enabled', type: 'switch', }, // 反思模型 { key: 'reflection_model_id', type: 'customSelect', url: getModelListUrl, params: { type: 'chat,llm', page: 1, pagesize: 100 }, // chat,llm }, // 迭代周期 { key: 'reflection_period_in_hours', type: 'select', options: [ { label: 'oneHour', value: '1' }, { label: 'threeHours', value: '3' }, { label: 'sixHours', value: '6' }, { label: 'twelveHours', value: '12' }, { label: 'daily', value: '24' }, ], }, // 反思范围 { key: 'reflexion_range', type: 'select', hiddenDesc: true, options: [ { label: 'partial', value: 'partial' }, { label: 'all', value: 'all' }, ], }, // 反思基线 { key: 'baseline', type: 'select', hiddenDesc: true, options: [ { label: 'TIME', value: 'TIME' }, { label: 'FACT', value: 'FACT' }, { label: 'HYBRID', value: 'HYBRID' }, ], }, // 质量评估 { key: 'quality_assessment', type: 'switch', }, // 质量评估 { key: 'memory_verify', type: 'switch', }, ] const SelfReflectionEngine: React.FC = () => { const { t } = useTranslation(); const { id } = useParams(); const [configData, setConfigData] = useState({} as ConfigForm); const [form] = Form.useForm(); const { message } = App.useApp(); const [loading, setLoading] = useState(false) const [runLoading, setRunLoading] = useState(false) const [result, setResult] = useState(null) const values = Form.useWatch([], form); useEffect(() => { getConfigData() }, [id]) const getConfigData = () => { if (!id) { return } getMemoryReflectionConfig(id) .then((res) => { const response = res as ConfigForm const initialValues = { ...response, } console.log('initialValues', initialValues) setConfigData(initialValues); form.setFieldsValue(initialValues); }) .catch(() => { console.error('Failed to load data'); }) } const handleReset = () => { form.setFieldsValue(configData); } const handleSave = () => { if (!id) { return } setLoading(true) updateMemoryReflectionConfig({ ...values, config_id: id }) .then(() => { message.success(t('common.saveSuccess')) setConfigData({...(values || {})}) }) .finally(() => { setLoading(false) }) } const handleRun = () => { if (!id) { return } setRunLoading(true) updateMemoryReflectionConfig({ ...values, config_id: id }) .then(() => { pilotRunMemoryReflectionConfig({ config_id: id, dialogue_text: t('reflectionEngine.exampleText') }) .then((res) => { setResult(res as Result) }) .finally(() => { setRunLoading(false) }) }) .finally(() => { setLoading(false) }) } return ( {t('reflectionEngine.reflectionEngineConfig')} } >
{configList.map(config => { if (config.type === 'customSelect') { return (
{t(`reflectionEngine.${config.key}`)}
) } if (config.type === 'select') { return (
{t(`reflectionEngine.${config.key}`)}