import React, { useState } from 'react'; import { Box, Typography, Card, CardContent, Grid, Button, Switch, FormControlLabel, Slider, TextField, Select, MenuItem, FormControl, InputLabel, Chip, Divider, Alert, LinearProgress, } from '@mui/material'; import { Settings as SettingsIcon, PlayArrow as PlayIcon, Stop as StopIcon, Refresh as RefreshIcon, Save as SaveIcon, } from '@mui/icons-material'; import { styled } from '@mui/material/styles'; const PageContainer = styled(Box)(({ theme }) => ({ padding: '1.5rem', backgroundColor: '#F8F9FA', minHeight: 'calc(100vh - 60px)', })); const PageHeader = styled(Box)(({ theme }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '1.5rem', })); const ConfigCard = styled(Card)(({ theme }) => ({ marginBottom: '1.5rem', border: '1px solid #E5E5E5', })); const ConfigSection = styled(Box)(({ theme }) => ({ marginBottom: '1.5rem', '&:last-child': { marginBottom: 0, }, })); const StatusIndicator = styled(Box)<{ status: 'running' | 'stopped' | 'error' }>(({ status, theme }) => ({ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', padding: '0.25rem 0.75rem', borderRadius: '12px', fontSize: '0.875rem', fontWeight: 500, backgroundColor: status === 'running' ? '#E8F5E8' : status === 'stopped' ? '#F8F9FA' : '#F8D7DA', color: status === 'running' ? '#155724' : status === 'stopped' ? '#666' : '#721C24', '&::before': { content: '""', width: '8px', height: '8px', borderRadius: '50%', backgroundColor: status === 'running' ? '#28A745' : status === 'stopped' ? '#6C757D' : '#DC3545', }, })); const PipelineConfig: React.FC = () => { const [pipelineStatus, setPipelineStatus] = useState<'running' | 'stopped' | 'error'>('stopped'); const [config, setConfig] = useState({ enabled: false, chunkSize: 512, chunkOverlap: 50, embeddingModel: 'text-embedding-ada-002', retrievalTopK: 5, temperature: 0.7, maxTokens: 2048, systemPrompt: '你是一个专业的AI助手,请基于提供的知识库内容回答用户问题。', }); const handleConfigChange = (key: string, value: any) => { setConfig(prev => ({ ...prev, [key]: value })); }; const handleStartPipeline = () => { setPipelineStatus('running'); }; const handleStopPipeline = () => { setPipelineStatus('stopped'); }; const handleSaveConfig = () => { // 保存配置逻辑 console.log('保存配置:', config); }; return ( RAG Pipeline 配置 {pipelineStatus === 'running' ? '运行中' : pipelineStatus === 'stopped' ? '已停止' : '错误'} {pipelineStatus === 'running' && ( )} {pipelineStatus === 'running' ? ( ) : ( )} 基础配置 handleConfigChange('enabled', e.target.checked)} /> } label="启用 RAG Pipeline" /> 文档分块大小 handleConfigChange('chunkSize', value)} min={128} max={2048} step={64} marks={[ { value: 128, label: '128' }, { value: 512, label: '512' }, { value: 1024, label: '1024' }, { value: 2048, label: '2048' }, ]} valueLabelDisplay="on" /> 分块重叠 (%) handleConfigChange('chunkOverlap', value)} min={0} max={50} step={5} valueLabelDisplay="on" /> 嵌入模型 检索与生成配置 handleConfigChange('retrievalTopK', parseInt(e.target.value))} inputProps={{ min: 1, max: 20 }} /> 生成温度 handleConfigChange('temperature', value)} min={0} max={1} step={0.1} marks={[ { value: 0, label: '0' }, { value: 0.5, label: '0.5' }, { value: 1, label: '1' }, ]} valueLabelDisplay="on" /> handleConfigChange('maxTokens', parseInt(e.target.value))} inputProps={{ min: 256, max: 4096 }} /> handleConfigChange('systemPrompt', e.target.value)} /> Pipeline 状态监控 1,234 已处理文档 98.5% 成功率 2.3s 平均响应时间 156 今日查询数 {pipelineStatus === 'error' && ( Pipeline 运行出现错误,请检查配置和日志。 )} ); }; export default PipelineConfig;