import React, { useState, useEffect } from 'react'; import { Row, Col, Form, Slider, Button, Space, message } 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 LineChart from './components/LineChart' import { getMemoryForgetConfig, updateMemoryForgetConfig } from '@/api/memory' import type { ConfigForm } from './types' import SwitchFormItem from '@/components/FormItem/SwitchFormItem' const configList = [ { key: 'minimumRetention', name: 'lambda_time', range: [0, 1], type: 'decimal', }, { key: 'forgettingRate', name: 'lambda_mem', range: [0.01, 1], type: 'decimal', }, { key: 'offset', name: 'offset', range: [0, 1], 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 { t } = useTranslation(); const { id } = useParams(); const [configData, setConfigData] = useState(); const [form] = Form.useForm(); const [messageApi, contextHolder] = message.useMessage(); const [loading, setLoading] = useState(false) const values = Form.useWatch([], form); useEffect(() => { getConfigData() }, []) const getConfigData = () => { getMemoryForgetConfig(id as string) .then((res) => { const response = res as ConfigForm const initialValues = { ...response, lambda_time: Number(response.lambda_time || 0), lambda_mem: Number(response.lambda_mem || 0), offset: Number(response.offset || 0), } setConfigData(initialValues); form.setFieldsValue(initialValues); }) .catch(() => { console.error('Failed to load data'); }) } const handleReset = () => { form.setFieldsValue(configData || {}); } const handleSave = () => { setLoading(true) updateMemoryForgetConfig({ config_id: id, ...values }) .then(() => { messageApi.success(t('common.saveSuccess')) setConfigData({...(values || {})}) }) .finally(() => { setLoading(false) }) } return ( {t('forgettingEngine.forgettingEngineConfigParams')} } className='rb:h-full!' >
{configList.map(config => { if (config.type === 'button') { return ( {t(`forgettingEngine.type`)}: {config.type}} className="rb:mb-2" /> ) } return (
{t(`forgettingEngine.${config.key}`)}
{!config.hiddenDesc &&
{t(`forgettingEngine.${config.key}Desc`)}
} {config.type === 'decimal' ? : null }
{config.range && {t(`forgettingEngine.range`)}: {config.range?.join('-')}} {config.type && {t(`forgettingEngine.type`)}: {config.type}} <>{t('forgettingEngine.CurrentValue')}: {values?.[config.name] || 0}
) })}
{contextHolder}
); }; export default ForgettingEngine;