/** * Analysis form component */ "use client"; import { useState } 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 { Button } from "@/components/ui/button"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Checkbox } from "@/components/ui/checkbox"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; 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"), analysts: z.array(z.string()).min(1, "請至少選擇一位分析師"), research_depth: z.number().min(1).max(5), deep_think_llm: z.string(), quick_think_llm: z.string(), // API Configuration openai_api_key: z.string().min(20, "請輸入有效的 OpenAI API Key"), openai_base_url: z.string().url("請輸入有效的 URL").optional().or(z.literal("")), alpha_vantage_api_key: z.string().optional().or(z.literal("")), }); interface AnalysisFormProps { onSubmit: (data: AnalysisRequest) => void; loading?: boolean; } const ANALYSTS = [ { value: "market", label: "市場分析師" }, { value: "social", label: "社群媒體分析師" }, { value: "news", label: "新聞分析師" }, { value: "fundamentals", label: "基本面分析師" }, ]; export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { ticker: "NVDA", analysis_date: format(new Date(), "yyyy-MM-dd"), analysts: ["market", "social", "news", "fundamentals"], // 預設全選 research_depth: 1, deep_think_llm: "gpt-4o-mini", quick_think_llm: "gpt-4o-mini", openai_api_key: "", openai_base_url: "https://api.openai.com/v1", alpha_vantage_api_key: "", }, }); // 全選/取消全選 const toggleSelectAll = () => { const currentAnalysts = form.getValues("analysts"); if (currentAnalysts.length === ANALYSTS.length) { form.setValue("analysts", []); } else { form.setValue("analysts", ANALYSTS.map(a => a.value)); } }; function handleSubmit(values: z.infer) { const request: AnalysisRequest = { ...values, }; onSubmit(request); } return ( 交易分析配置 配置您的交易分析參數
{/* 分析師選擇區塊 */}
分析師團隊
(
{ANALYSTS.map((analyst) => ( { return ( { return checked ? field.onChange([...field.value, analyst.value]) : field.onChange( field.value?.filter( (value: string) => value !== analyst.value ) ); }} /> {analyst.label} ); }} /> ))}
)} />
( 股票代碼 輸入股票代碼(例如:NVDA、AAPL) )} /> ( 分析日期 選擇分析日期 )} /> ( 研究深度 深度越高 = 辯論回合越多 )} /> ( 深度思考模型 用於複雜推理的模型 )} />
{/* API Configuration Section */}

API 配置

( OpenAI API Key(必填) 您的 OpenAI API Key(用於 LLM 推理) )} /> ( OpenAI Base URL(選填) API 基礎網址(預設為 OpenAI 官方) )} /> ( Alpha Vantage API Key(選填) 用於獲取更詳細的財務數據(可選) )} />
); }