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 { getStreamCheckConfig, saveStreamCheckConfig, type StreamCheckConfig, } 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({ timeoutSecs: 45, maxRetries: 2, degradedThresholdMs: 6000, claudeModel: "claude-haiku-4-5-20251001", codexModel: "gpt-5.1-codex@low", geminiModel: "gemini-3-pro-preview", }); useEffect(() => { loadConfig(); }, []); async function loadConfig() { try { setIsLoading(true); setError(null); const data = await getStreamCheckConfig(); setConfig(data); } catch (e) { setError(String(e)); } finally { setIsLoading(false); } } async function handleSave() { try { setIsSaving(true); await saveStreamCheckConfig(config); toast.success(t("streamCheck.configSaved"), { closeButton: true, }); } catch (e) { toast.error( t("streamCheck.configSaveFailed") + ": " + String(e), ); } finally { setIsSaving(false); } } if (isLoading) { return (
); } return (
{error && ( {error} )} {/* 测试模型配置 */}

{t("streamCheck.testModels")}

setConfig({ ...config, claudeModel: e.target.value }) } placeholder="claude-3-5-haiku-latest" />
setConfig({ ...config, codexModel: e.target.value }) } placeholder="gpt-4o-mini" />
setConfig({ ...config, geminiModel: e.target.value }) } placeholder="gemini-1.5-flash" />
{/* 检查参数配置 */}

{t("streamCheck.checkParams")}

setConfig({ ...config, timeoutSecs: parseInt(e.target.value) || 45, }) } />
setConfig({ ...config, maxRetries: parseInt(e.target.value) || 2, }) } />
setConfig({ ...config, degradedThresholdMs: parseInt(e.target.value) || 6000, }) } />
); }