/* * @Author: ZhaoYing * @Date: 2026-02-03 16:56:54 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-02-03 16:57:17 */ /** * Emotion Engine Configuration Page * Configures emotion analysis settings for memory system * Includes model selection, intensity threshold, and feature toggles */ import React, { useState, useEffect } from 'react'; import { Row, Col, Form, Slider, Button, Alert, message, Space } 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 { getMemoryEmotionConfig, updateMemoryEmotionConfig } from '@/api/memory' import type { ConfigForm } from './types' import CustomSelect from '@/components/CustomSelect'; import { getModelListUrl } from '@/api/models' import Tag from '@/components/Tag' import SwitchFormItem from '@/components/FormItem/SwitchFormItem' /** * Configuration field definitions */ const configList = [ { key: 'emotion_enabled', type: 'switch', }, { key: 'emotion_model_id', type: 'customSelect', url: getModelListUrl, params: { type: 'chat,llm', page: 1, pagesize: 100, is_active: true }, // chat,llm }, { key: 'emotion_min_intensity', type: 'slider', min: 0, max: 1, step: 0.05 }, { key: 'emotion_extract_keywords', type: 'switch', hasSubTitle: true }, { key: 'emotion_enable_subject', type: 'switch', hasSubTitle: true }, ] /** * Emotion engine configuration component */ const EmotionEngine: React.FC = () => { const { t } = useTranslation(); const { id } = useParams(); const [configData, setConfigData] = useState({} as ConfigForm); const [form] = Form.useForm(); const [messageApi, contextHolder] = message.useMessage(); const [loading, setLoading] = useState(false) const values = Form.useWatch([], form); useEffect(() => { getConfigData() }, [id]) /** Fetch emotion engine configuration */ const getConfigData = () => { if (!id) { return } getMemoryEmotionConfig(id) .then((res) => { const response = res as ConfigForm const initialValues = { ...response, } setConfigData(initialValues); form.setFieldsValue(initialValues); }) .catch(() => { console.error('Failed to load data'); }) } /** Reset form to saved configuration */ const handleReset = () => { form.setFieldsValue(configData); } /** Save emotion engine configuration */ const handleSave = () => { if (!id) { return } setLoading(true) updateMemoryEmotionConfig({ ...values, config_id: id }) .then(() => { messageApi.success(t('common.saveSuccess')) setConfigData({...(values || {})}) }) .finally(() => { setLoading(false) }) } return ( {t('emotionEngine.emotionEngineConfig')} } >
{configList.map(config => { if (config.type === 'slider') { return (
{t(`emotionEngine.${config.key}`)}
{t(`emotionEngine.${config.key}_desc`)}
<>{t('emotionEngine.currentValue')}: {values?.[config.key as keyof ConfigForm] || 0}
) } if (config.type === 'customSelect') { return (
{t(`emotionEngine.${config.key}`)}
) } return ( {config.hasSubTitle &&
{t(`emotionEngine.${config.key}_subTitle`)}
}
{t(`emotionEngine.${config.key}_desc`)}
} className="rb:mb-6" disabled={!values?.emotion_enabled && config.key !== 'emotion_enabled'} /> ) })}
{t('emotionEngine.question')}
{t('emotionEngine.answer')}
{t('emotionEngine.differentTitle')}
{['low', 'middle', 'high'].map((key, index) => (
{t(`emotionEngine.${key}_title`)} {t(`emotionEngine.${key}_tag`)}
{t('emotionEngine.advantage')}: {t(`emotionEngine.${key}_advantage`)}
{t('emotionEngine.shortcoming')}: {t(`emotionEngine.${key}_shortcoming`)}
{t('emotionEngine.scene')}: {t(`emotionEngine.${key}_scene`)}
} /> ))}
{t('emotionEngine.configSuggest')}
{['first', 'customer_service', 'data_analysis', 'risk_warning'].map(key => (
{t(`emotionEngine.${key}`)}: {t(`emotionEngine.${key}_desc`)}
))}
{t('emotionEngine.actual_case')}
{t('emotionEngine.user_input')}: {t('emotionEngine.user_input_message')}
{['neutral_emotion', 'minor_dissatisfaction', 'expect_improvement'].map((key, index) => (
{t(`emotionEngine.${key}`)} {t('emotionEngine.confidence')}: {key === 'neutral_emotion' ? 0.85 : key === 'minor_dissatisfaction' ? 0.45 : 0.32}
{t(`emotionEngine.${key}_tag`)}
))}
{contextHolder}
); }; export default EmotionEngine;