// LlamaFactoryTab.js 组件 import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, FormControlLabel, Checkbox, Typography, Box, TextField, Alert, CircularProgress, IconButton, Tooltip } from '@mui/material'; import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import CheckIcon from '@mui/icons-material/Check'; const LlamaFactoryTab = ({ projectId, systemPrompt, reasoningLanguage, confirmedOnly, includeCOT, formatType, handleSystemPromptChange, handleReasoningLanguageChange, handleConfirmedOnlyChange, handleIncludeCOTChange }) => { const { t } = useTranslation(); const [configExists, setConfigExists] = useState(false); const [configPath, setConfigPath] = useState(''); const [generating, setGenerating] = useState(false); const [error, setError] = useState(''); const [copied, setCopied] = useState(false); // 检查配置文件是否存在 useEffect(() => { if (projectId) { fetch(`/api/projects/${projectId}/llamaFactory/checkConfig`) .then(res => res.json()) .then(data => { setConfigExists(data.exists); if (data.exists) { setConfigPath(data.configPath); } }) .catch(err => { setError(err.message); }); } }, [projectId, configExists]); // 复制路径到剪贴板 const handleCopyPath = () => { const path = configPath.replace('dataset_info.json', ''); navigator.clipboard.writeText(path).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); }; // 处理生成 Llama Factory 配置 const handleGenerateConfig = async () => { try { setGenerating(true); setError(''); const response = await fetch(`/api/projects/${projectId}/llamaFactory/generate`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ formatType, systemPrompt, reasoningLanguage, confirmedOnly, includeCOT }) }); const data = await response.json(); if (!response.ok) { throw new Error(data.error); } setConfigExists(true); } catch (err) { setError(err.message); } finally { setGenerating(false); } }; return ( {error && ( {error} )} {t('export.systemPrompt')} {/* Reasoning language – only for multilingual‑thinking */} {formatType === 'multilingualthinking' && ( {t('export.reasoningLanguage')} )} } label={t('export.onlyConfirmed')} /> } label={t('export.includeCOT')} /> {configExists ? ( <> {t('export.configExists')} {t('export.configPath')}: {configPath.replace('dataset_info.json', '')} {copied ? : } ) : ( {t('export.noConfig')} )} ); }; export default LlamaFactoryTab;