diff --git a/frontend/components/analysis/AnalysisForm.tsx b/frontend/components/analysis/AnalysisForm.tsx
index d4643adf..4935d1c0 100644
--- a/frontend/components/analysis/AnalysisForm.tsx
+++ b/frontend/components/analysis/AnalysisForm.tsx
@@ -3,12 +3,14 @@
*/
"use client";
-import { useState } from "react";
+import { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { format } from "date-fns";
import { CheckIcon } from "lucide-react";
+import { getApiSettings } from "@/lib/storage";
+import { getBaseUrlForModel, getApiKeyForModel } from "@/lib/api-helpers";
import { cn } from "@/lib/utils";
@@ -51,7 +53,7 @@ const formSchema = z.object({
quick_think_llm: z.string().min(1, "請選擇快速思維模型"),
deep_think_llm: z.string().min(1, "請選擇深層思維模型"),
- // API Configuration
+ // API Configuration (hidden from UI, populated from localStorage)
quick_think_base_url: z
.string()
.url("請輸入有效的 URL")
@@ -105,6 +107,24 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
},
});
+ // Load API settings from localStorage and update when models change
+ useEffect(() => {
+ const savedSettings = getApiSettings();
+ const quickThinkLlm = form.getValues("quick_think_llm");
+ const deepThinkLlm = form.getValues("deep_think_llm");
+
+ // Set base URLs based on selected models
+ form.setValue("quick_think_base_url", getBaseUrlForModel(quickThinkLlm));
+ form.setValue("deep_think_base_url", getBaseUrlForModel(deepThinkLlm));
+ form.setValue("embedding_base_url", "https://api.openai.com/v1");
+
+ // Set API keys based on selected models
+ form.setValue("quick_think_api_key", getApiKeyForModel(quickThinkLlm, savedSettings));
+ form.setValue("deep_think_api_key", getApiKeyForModel(deepThinkLlm, savedSettings));
+ form.setValue("embedding_api_key", savedSettings.openai_api_key);
+ form.setValue("alpha_vantage_api_key", savedSettings.alpha_vantage_api_key);
+ }, [form, form.watch("quick_think_llm"), form.watch("deep_think_llm")]);
+
// 全選/取消全選
const toggleSelectAll = () => {
const currentAnalysts = form.getValues("analysts");
@@ -505,299 +525,6 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
- {/* API Configuration Section */}
-
-
API 配置
-
-
(
-
- 快速思維模型 Base URL
-
-
- {(![
- "https://api.openai.com/v1",
- "https://api.anthropic.com",
- "https://generativelanguage.googleapis.com/v1beta/openai",
- "https://api.x.ai/v1",
- "https://api.deepseek.com/v1",
- "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
- ].includes(field.value || "") ||
- field.value === "") && (
-
-
-
-
-
- )}
-
-
- 快速思維模型的 API 基礎網址
-
-
-
- )}
- />
-
- (
-
- 快速思維模型 API Key *
-
-
-
-
- 該模型的專屬 API Key(必填)
-
-
-
- )}
- />
-
- (
-
- 深層思維模型 Base URL
-
-
- {(![
- "https://api.openai.com/v1",
- "https://api.anthropic.com",
- "https://generativelanguage.googleapis.com/v1beta/openai",
- "https://api.x.ai/v1",
- "https://api.deepseek.com/v1",
- "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
- ].includes(field.value || "") ||
- field.value === "") && (
-
-
-
-
-
- )}
-
-
- 深層思維模型的 API 基礎網址
-
-
-
- )}
- />
-
- (
-
- 深層思維模型 API Key *
-
-
-
-
- 該模型的專屬 API Key(必填)
-
-
-
- )}
- />
-
- (
-
- 嵌入模型 Base URL
-
-
- {field.value !== "https://api.openai.com/v1" && (
-
-
-
-
-
- )}
-
-
- 嵌入向量生成的 API 端點(用於記憶體系統)
-
-
-
- )}
- />
-
- (
-
- 嵌入模型 API Key *
-
-
-
- 該端點的 API Key(必填)
-
-
- )}
- />
-
- (
-
- Alpha Vantage API Key *
-
-
-
-
- 用於獲取市場基本面數據(必填)
-
-
-
- )}
- />
-
-