import { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Save, Loader2 } from "lucide-react"; import { toast } from "sonner"; import { getModelTestConfig, saveModelTestConfig, type ModelTestConfig, } from "@/lib/api/model-test"; export function ModelTestConfigPanel() { const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(null); const [config, setConfig] = useState({ claudeModel: "claude-haiku-4-5-20251001", codexModel: "gpt-5.1-low", geminiModel: "gemini-3-pro-low", testPrompt: "ping", timeoutSecs: 15, }); useEffect(() => { loadConfig(); }, []); async function loadConfig() { try { setIsLoading(true); setError(null); const data = await getModelTestConfig(); setConfig(data); } catch (e) { setError(String(e)); } finally { setIsLoading(false); } } async function handleSave() { try { setIsSaving(true); await saveModelTestConfig(config); toast.success(t("modelTest.configSaved", "模型测试配置已保存")); } catch (e) { toast.error( t("modelTest.configSaveFailed", "保存失败") + ": " + String(e), ); } finally { setIsSaving(false); } } if (isLoading) { return (
); } return (
{error && ( {error} )}
setConfig({ ...config, claudeModel: e.target.value }) } placeholder="claude-haiku-4-5-20251001" />
setConfig({ ...config, codexModel: e.target.value }) } placeholder="gpt-5.1-low" />
setConfig({ ...config, geminiModel: e.target.value }) } placeholder="gemini-3-pro-low" />
setConfig({ ...config, testPrompt: e.target.value }) } placeholder="ping" />

{t( "modelTest.testPromptHint", "发送给模型的测试消息,建议使用简短内容以减少 token 消耗", )}

setConfig({ ...config, timeoutSecs: parseInt(e.target.value) || 15, }) } />
); }