update: upload fix
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card, Form, Input, Select, Button, Alert, Space, message } from "antd";
|
||||
import { Card, Form, Input, Select, Button, Alert, Space, Divider, Descriptions, message } from "antd";
|
||||
import {
|
||||
api,
|
||||
type RuntimeSettings,
|
||||
type ProviderKey,
|
||||
getApiBaseUrl,
|
||||
setApiBaseUrl,
|
||||
} from "../services/api";
|
||||
|
||||
const PROVIDER_OPTIONS = [
|
||||
{ label: "OpenAI", value: "openai" as ProviderKey },
|
||||
{ label: "Anthropic", value: "anthropic" as ProviderKey },
|
||||
{ label: "DeepSeek", value: "deepseek" as ProviderKey },
|
||||
{ label: "自定义(OpenAI兼容)", value: "custom_openai" as ProviderKey },
|
||||
];
|
||||
|
||||
export default function Settings() {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -20,9 +28,11 @@ export default function Settings() {
|
||||
setRuntime(data);
|
||||
form.setFieldsValue({
|
||||
system_api_base_url: getApiBaseUrl(),
|
||||
llm_provider: data.llm_provider,
|
||||
ocr_provider: data.ocr_provider,
|
||||
ocr_model: data.ocr_model,
|
||||
inference_provider: data.inference_provider,
|
||||
inference_model: data.inference_model,
|
||||
custom_openai_base_url: data.base_urls?.custom_openai || "",
|
||||
custom_openai_model: data.models?.custom_openai || "gpt-4o-mini",
|
||||
});
|
||||
} catch {
|
||||
message.error("加载设置失败");
|
||||
@@ -35,21 +45,15 @@ export default function Settings() {
|
||||
loadSettings();
|
||||
}, []);
|
||||
|
||||
const onFinish = async (values: {
|
||||
system_api_base_url?: string;
|
||||
llm_provider: "openai" | "anthropic" | "deepseek" | "custom_openai";
|
||||
openai_api_key?: string;
|
||||
anthropic_api_key?: string;
|
||||
deepseek_api_key?: string;
|
||||
custom_openai_api_key?: string;
|
||||
custom_openai_base_url?: string;
|
||||
custom_openai_model?: string;
|
||||
}) => {
|
||||
const onFinish = async (values: Record<string, string | undefined>) => {
|
||||
setSaving(true);
|
||||
try {
|
||||
setApiBaseUrl(values.system_api_base_url || "");
|
||||
const payload = {
|
||||
llm_provider: values.llm_provider,
|
||||
const payload: Record<string, string | undefined> = {
|
||||
ocr_provider: values.ocr_provider,
|
||||
ocr_model: values.ocr_model?.trim() || undefined,
|
||||
inference_provider: values.inference_provider,
|
||||
inference_model: values.inference_model?.trim() || undefined,
|
||||
openai_api_key: values.openai_api_key?.trim() || undefined,
|
||||
anthropic_api_key: values.anthropic_api_key?.trim() || undefined,
|
||||
deepseek_api_key: values.deepseek_api_key?.trim() || undefined,
|
||||
@@ -59,7 +63,7 @@ export default function Settings() {
|
||||
};
|
||||
const data = await api.settings.update(payload);
|
||||
setRuntime(data);
|
||||
message.success("设置已保存并生效(含系统 API BaseURL)");
|
||||
message.success("设置已保存");
|
||||
} catch {
|
||||
message.error("保存失败");
|
||||
} finally {
|
||||
@@ -68,35 +72,42 @@ export default function Settings() {
|
||||
};
|
||||
|
||||
return (
|
||||
<Card title="LLM 设置" loading={loading}>
|
||||
<Card title="模型与接口设置" loading={loading}>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
message="LLM API Key 仅在当前服务进程运行期内生效,不会自动写入磁盘。"
|
||||
message="API Key 仅在当前服务进程运行期内生效,不写入磁盘。OCR 模型用于从截图中提取交易,推理模型用于生成报告等文本推理任务。"
|
||||
/>
|
||||
<Form form={form} layout="vertical" onFinish={onFinish}>
|
||||
<Form.Item
|
||||
label="系统 API BaseURL(前端请求后端)"
|
||||
name="system_api_base_url"
|
||||
extra="默认 /api;若前后端分离部署,可填如 http://127.0.0.1:8000/api"
|
||||
extra="默认 /api;前后端分离时填 http://127.0.0.1:8000/api"
|
||||
>
|
||||
<Input placeholder="/api 或 http://127.0.0.1:8000/api" />
|
||||
<Input placeholder="/api" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="默认模型提供商"
|
||||
name="llm_provider"
|
||||
rules={[{ required: true, message: "请选择提供商" }]}
|
||||
>
|
||||
<Select
|
||||
options={[
|
||||
{ label: "OpenAI", value: "openai" },
|
||||
{ label: "Anthropic", value: "anthropic" },
|
||||
{ label: "DeepSeek", value: "deepseek" },
|
||||
{ label: "自定义(OpenAI兼容)", value: "custom_openai" },
|
||||
]}
|
||||
/>
|
||||
|
||||
<Divider orientation="left">OCR 视觉模型(截图识别交易)</Divider>
|
||||
|
||||
<Form.Item label="OCR 提供商" name="ocr_provider" rules={[{ required: true }]}>
|
||||
<Select options={PROVIDER_OPTIONS} />
|
||||
</Form.Item>
|
||||
<Form.Item label="OCR 模型名" name="ocr_model" extra="留空则使用该提供商的默认模型">
|
||||
<Input placeholder="如 gpt-4o / qwen-vl-max / ..." />
|
||||
</Form.Item>
|
||||
|
||||
<Divider orientation="left">推理模型(报告生成等文本推理)</Divider>
|
||||
|
||||
<Form.Item label="推理提供商" name="inference_provider" rules={[{ required: true }]}>
|
||||
<Select options={PROVIDER_OPTIONS} />
|
||||
</Form.Item>
|
||||
<Form.Item label="推理模型名" name="inference_model" extra="留空则使用该提供商的默认模型">
|
||||
<Input placeholder="如 gpt-4o-mini / deepseek-chat / ..." />
|
||||
</Form.Item>
|
||||
|
||||
<Divider orientation="left">API Key 与厂商配置</Divider>
|
||||
|
||||
<Form.Item label="OpenAI API Key" name="openai_api_key">
|
||||
<Input.Password placeholder="sk-..." />
|
||||
</Form.Item>
|
||||
@@ -113,29 +124,33 @@ export default function Settings() {
|
||||
>
|
||||
<Input placeholder="https://api.xxx.com/v1" />
|
||||
</Form.Item>
|
||||
<Form.Item label="自定义厂商 Model" name="custom_openai_model">
|
||||
<Form.Item label="自定义厂商默认模型" name="custom_openai_model">
|
||||
<Input placeholder="gpt-4o-mini / qwen-vl-plus / ..." />
|
||||
</Form.Item>
|
||||
<Form.Item label="自定义厂商 API Key" name="custom_openai_api_key">
|
||||
<Input.Password placeholder="sk-..." />
|
||||
</Form.Item>
|
||||
|
||||
<Space>
|
||||
<Button type="primary" htmlType="submit" loading={saving}>
|
||||
保存设置
|
||||
</Button>
|
||||
<Button type="primary" htmlType="submit" loading={saving}>保存设置</Button>
|
||||
<Button onClick={loadSettings}>刷新</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
|
||||
{runtime && (
|
||||
<Card title="当前状态" size="small" style={{ marginTop: 16 }}>
|
||||
<div>系统 API BaseURL: {getApiBaseUrl()}</div>
|
||||
<div>当前提供商: {runtime.llm_provider}</div>
|
||||
<div>OpenAI Key: {runtime.has_keys.openai ? "已配置" : "未配置"}</div>
|
||||
<div>Anthropic Key: {runtime.has_keys.anthropic ? "已配置" : "未配置"}</div>
|
||||
<div>DeepSeek Key: {runtime.has_keys.deepseek ? "已配置" : "未配置"}</div>
|
||||
<div>自定义厂商 Key: {runtime.has_keys.custom_openai ? "已配置" : "未配置"}</div>
|
||||
<div>自定义厂商 BaseURL: {runtime.base_urls.custom_openai || "-"}</div>
|
||||
<Card title="当前生效配置" size="small" style={{ marginTop: 16 }}>
|
||||
<Descriptions column={2} size="small" bordered>
|
||||
<Descriptions.Item label="系统 API BaseURL">{getApiBaseUrl()}</Descriptions.Item>
|
||||
<Descriptions.Item label="自定义厂商 BaseURL">{runtime.base_urls.custom_openai || "-"}</Descriptions.Item>
|
||||
<Descriptions.Item label="OCR 提供商">{runtime.ocr_provider}</Descriptions.Item>
|
||||
<Descriptions.Item label="OCR 模型">{runtime.ocr_model}</Descriptions.Item>
|
||||
<Descriptions.Item label="推理提供商">{runtime.inference_provider}</Descriptions.Item>
|
||||
<Descriptions.Item label="推理模型">{runtime.inference_model}</Descriptions.Item>
|
||||
<Descriptions.Item label="OpenAI Key">{runtime.has_keys.openai ? "已配置" : "未配置"}</Descriptions.Item>
|
||||
<Descriptions.Item label="Anthropic Key">{runtime.has_keys.anthropic ? "已配置" : "未配置"}</Descriptions.Item>
|
||||
<Descriptions.Item label="DeepSeek Key">{runtime.has_keys.deepseek ? "已配置" : "未配置"}</Descriptions.Item>
|
||||
<Descriptions.Item label="自定义厂商 Key">{runtime.has_keys.custom_openai ? "已配置" : "未配置"}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user