From 58521527fded448670d343e9456e2a8a2f407ac9 Mon Sep 17 00:00:00 2001 From: MarkLo Date: Sun, 23 Nov 2025 10:20:05 +0800 Subject: [PATCH] --- frontend/components/analysis/AnalysisForm.tsx | 381 ++++++++++++------ 1 file changed, 258 insertions(+), 123 deletions(-) diff --git a/frontend/components/analysis/AnalysisForm.tsx b/frontend/components/analysis/AnalysisForm.tsx index 3538f101..274f8d39 100644 --- a/frontend/components/analysis/AnalysisForm.tsx +++ b/frontend/components/analysis/AnalysisForm.tsx @@ -28,23 +28,43 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import type { AnalysisRequest } from "@/lib/types"; const formSchema = z.object({ ticker: z.string().min(1, "股票代碼為必填").max(10), - analysis_date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式必須為 YYYY-MM-DD"), + analysis_date: z + .string() + .regex(/^\d{4}-\d{2}-\d{2}$/, "日期格式必須為 YYYY-MM-DD"), analysts: z.array(z.string()).min(1, "請至少選擇一位分析師"), research_depth: z.number().int().min(1).max(5), - shallow_thinking_agent: z.string().min(1, "請選擇快速思維模型"), + shallow_thinking_agent: z.string().min(1, "請選擇快速思維模型"), deep_thinking_agent: z.string().min(1, "請選擇深層思維模型"), - + // API Configuration - quick_think_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")), - deep_think_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")), + quick_think_base_url: z + .string() + .url("請輸入有效的 URL") + .optional() + .or(z.literal("")), + deep_think_base_url: z + .string() + .url("請輸入有效的 URL") + .optional() + .or(z.literal("")), quick_think_api_key: z.string().optional().or(z.literal("")), deep_think_api_key: z.string().optional().or(z.literal("")), - embedding_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")), + embedding_base_url: z + .string() + .url("請輸入有效的 URL") + .optional() + .or(z.literal("")), embedding_api_key: z.string().optional().or(z.literal("")), alpha_vantage_api_key: z.string().min(1, "請輸入 Alpha Vantage API Key"), }); @@ -87,7 +107,10 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { if (currentAnalysts.length === ANALYSTS.length) { form.setValue("analysts", []); } else { - form.setValue("analysts", ANALYSTS.map(a => a.value)); + form.setValue( + "analysts", + ANALYSTS.map((a) => a.value) + ); } }; @@ -102,19 +125,26 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
- +
{/* 分析師選擇區塊 - 全寬 */}
- 分析師團隊 + + 分析師團隊 +
{ return checked - ? field.onChange([...field.value, analyst.value]) + ? field.onChange([ + ...field.value, + analyst.value, + ]) : field.onChange( field.value?.filter( - (value: string) => value !== analyst.value + (value: string) => + value !== analyst.value ) ); }} @@ -191,9 +227,7 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { - - 選擇分析日期 - + 選擇分析日期 )} @@ -209,7 +243,9 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { 研究深度 - - 選擇分析深度 - + 選擇分析深度 )} @@ -237,8 +277,8 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { render={({ field }) => ( 快速思維模型 - - - 快速回應模型 - + 快速回應模型 )} @@ -295,7 +368,7 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { render={({ field }) => ( 深層思維模型 - - - 複雜推理模型 - + 複雜推理模型 )} @@ -349,10 +455,9 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
- {/* API Configuration Section */} -
-

API 配置

- + {/* API Configuration Section */} +
+

API 配置

@@ -387,35 +491,45 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { - OpenAI (預設) - Anthropic - Google Gemini - Grok (xAI) - DeepSeek - Qwen (Alibaba) + + OpenAI (預設) + + + Anthropic + + + Grok (xAI) + + + DeepSeek + + + Qwen (Alibaba) + 自訂端點 - + {(![ "https://api.openai.com/v1", "https://api.anthropic.com/", "https://generativelanguage.googleapis.com/v1", "https://api.x.ai/v1", "https://api.deepseek.com", - "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" - ].includes(field.value || "") || field.value === "") && ( + "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", + ].includes(field.value || "") || + field.value === "") && (
-
)} - + 快速思維模型的 API 基礎網址 @@ -459,12 +573,11 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { [ "https://api.openai.com/v1", "https://api.anthropic.com/", - "https://generativelanguage.googleapis.com/v1", "https://api.x.ai/v1", "https://api.deepseek.com", - "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" - ].includes(field.value || "") - ? field.value + "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", + ].includes(field.value || "") + ? field.value : "custom" } > @@ -474,35 +587,45 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { - OpenAI (預設) - Anthropic - Google Gemini - Grok (xAI) - DeepSeek - Qwen (Alibaba) + + OpenAI (預設) + + + Anthropic + + + Grok (xAI) + + + DeepSeek + + + Qwen (Alibaba) + 自訂端點 - + {(![ "https://api.openai.com/v1", "https://api.anthropic.com/", "https://generativelanguage.googleapis.com/v1", "https://api.x.ai/v1", "https://api.deepseek.com", - "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" - ].includes(field.value || "") || field.value === "") && ( + "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", + ].includes(field.value || "") || + field.value === "") && (
-
)} - + 深層思維模型的 API 基礎網址 @@ -543,7 +666,8 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { } }} defaultValue={ - field.value === "https://api.openai.com/v1" || !field.value + field.value === "https://api.openai.com/v1" || + !field.value ? "https://api.openai.com/v1" : "custom" } @@ -554,23 +678,25 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { - OpenAI (預設) + + OpenAI (預設) + 自訂端點 - + {field.value !== "https://api.openai.com/v1" && (
-
)} - + 嵌入向量生成的 API 端點(用於記憶體系統) @@ -603,7 +729,11 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { Alpha Vantage API Key * - + 用於獲取市場基本面數據(必填) @@ -614,7 +744,12 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { />
-