feat: Update AI configuration items

This commit is contained in:
shiyu
2025-08-29 18:41:57 +08:00
parent cce39f7b1c
commit 81eed370a6
2 changed files with 46 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
import { Form, Input, Button, message, Tabs, Space } from 'antd';
import { Form, Input, Button, message, Tabs, Space, Card } from 'antd';
import { useEffect, useState } from 'react';
import PageCard from '../../components/PageCard';
import { getAllConfig, setConfig } from '../../api/config';
@@ -11,16 +11,23 @@ const APP_CONFIG_KEYS = [
{ key: 'SERVER_URL', label: '服务端URL', default: API_BASE_URL },
];
const AI_CONFIG_KEYS = [
{ key: 'AI_API_URL', label: 'AI API地址' },
{ key: 'AI_VISION_MODEL', label: '视觉模型' },
{ key: 'AI_EMBED_MODEL', label: '嵌入模型' },
{ key: 'AI_API_KEY', label: 'API Key' },
const VISION_CONFIG_KEYS = [
{ key: 'AI_VISION_API_URL', label: '视觉模型 API 地址' },
{ key: 'AI_VISION_MODEL', label: '视觉模型', default: 'Qwen/Qwen2.5-VL-32B-Instruct' },
{ key: 'AI_VISION_API_KEY', label: '视觉模型 API Key' },
];
const EMBED_CONFIG_KEYS = [
{ key: 'AI_EMBED_API_URL', label: '嵌入模型 API 地址' },
{ key: 'AI_EMBED_MODEL', label: '嵌入模型', default: 'Qwen/Qwen3-Embedding-8B' },
{ key: 'AI_EMBED_API_KEY', label: '嵌入模型 API Key' },
];
const ALL_AI_KEYS = [...VISION_CONFIG_KEYS, ...EMBED_CONFIG_KEYS];
export default function SystemSettingsPage() {
const [loading, setLoading] = useState(false);
const [config, setConfigState] = useState<Record<string, string> | null>(null);
const [config, setConfigState] = useState<Record<string, string> | null>(null);
const [activeTab, setActiveTab] = useState('app');
useEffect(() => {
@@ -41,14 +48,13 @@ export default function SystemSettingsPage() {
setLoading(false);
};
// 加载中时不渲染表单
if (!config) {
return <PageCard title='系统设置'><div>...</div></PageCard>;
}
return (
<PageCard
title='系统设置'
title='系统设置'
>
<Space direction="vertical" style={{ width: '100%' }} size={32}>
<Tabs
@@ -73,7 +79,7 @@ export default function SystemSettingsPage() {
}}
onFinish={handleSave}
style={{ marginTop: 24 }}
key={JSON.stringify(config)}
key={JSON.stringify(config)}
>
{APP_CONFIG_KEYS.map(({ key, label }) => (
<Form.Item key={key} name={key} label={label}>
@@ -100,18 +106,27 @@ export default function SystemSettingsPage() {
<Form
layout="vertical"
initialValues={{
...Object.fromEntries(AI_CONFIG_KEYS.map(({ key }) => [key, config[key] ?? ''])),
...Object.fromEntries(ALL_AI_KEYS.map(({ key, default: def }) => [key, config[key] ?? def ?? ''])),
}}
onFinish={handleSave}
style={{ marginTop: 24 }}
key={JSON.stringify(config)} // 强制表单重置
key={JSON.stringify(config)}
>
{AI_CONFIG_KEYS.map(({ key, label }) => (
<Form.Item key={key} name={key} label={label}>
<Input size="large" />
</Form.Item>
))}
<Form.Item>
<Card title="视觉模型" style={{ marginBottom: 24 }}>
{VISION_CONFIG_KEYS.map(({ key, label }) => (
<Form.Item key={key} name={key} label={label}>
<Input size="large" />
</Form.Item>
))}
</Card>
<Card title="嵌入模型">
{EMBED_CONFIG_KEYS.map(({ key, label }) => (
<Form.Item key={key} name={key} label={label}>
<Input size="large" />
</Form.Item>
))}
</Card>
<Form.Item style={{ marginTop: 24 }}>
<Button type="primary" htmlType="submit" loading={loading} block>
</Button>