This commit is contained in:
parent
d3c111640d
commit
e898ebb2b5
|
|
@ -3,14 +3,10 @@
|
||||||
*/
|
*/
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useEffect } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { AnalysisForm } from "@/components/analysis/AnalysisForm";
|
import { AnalysisForm } from "@/components/analysis/AnalysisForm";
|
||||||
import { TradingDecision } from "@/components/analysis/TradingDecision";
|
|
||||||
import { AnalystReport } from "@/components/analysis/AnalystReport";
|
|
||||||
import { PriceChart } from "@/components/analysis/PriceChart";
|
|
||||||
import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
|
import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { useAnalysis } from "@/hooks/useAnalysis";
|
import { useAnalysis } from "@/hooks/useAnalysis";
|
||||||
import { useAnalysisContext } from "@/context/AnalysisContext";
|
import { useAnalysisContext } from "@/context/AnalysisContext";
|
||||||
import type { AnalysisRequest } from "@/lib/types";
|
import type { AnalysisRequest } from "@/lib/types";
|
||||||
|
|
@ -20,9 +16,17 @@ export default function AnalysisPage() {
|
||||||
const { setAnalysisResult } = useAnalysisContext();
|
const { setAnalysisResult } = useAnalysisContext();
|
||||||
const { runAnalysis, loading, error, result } = useAnalysis();
|
const { runAnalysis, loading, error, result } = useAnalysis();
|
||||||
|
|
||||||
const handleSubmit = async (request: AnalysisRequest) => {
|
// 當分析完成時自動跳轉到結果頁面
|
||||||
|
useEffect(() => {
|
||||||
|
if (result && !loading && !error) {
|
||||||
|
setAnalysisResult(result);
|
||||||
|
router.push("/analysis/results");
|
||||||
|
}
|
||||||
|
}, [result, loading, error, router, setAnalysisResult]);
|
||||||
|
|
||||||
|
const handleSubmit = async (data: AnalysisRequest) => {
|
||||||
try {
|
try {
|
||||||
await runAnalysis(request);
|
await runAnalysis(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Error is handled by the hook
|
// Error is handled by the hook
|
||||||
console.error("Analysis failed:", err);
|
console.error("Analysis failed:", err);
|
||||||
|
|
|
||||||
|
|
@ -155,12 +155,12 @@ export function AnalysisForm({ onSubmit, loading = false }: AnalysisFormProps) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 研究深度 - 放大顯示 */}
|
{/* 研究深度 - 單欄寬度 */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="research_depth"
|
name="research_depth"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="md:col-span-2">
|
<FormItem>
|
||||||
<FormLabel className="text-lg font-semibold">研究深度</FormLabel>
|
<FormLabel className="text-lg font-semibold">研究深度</FormLabel>
|
||||||
<Select
|
<Select
|
||||||
onValueChange={(value) => field.onChange(parseInt(value))}
|
onValueChange={(value) => field.onChange(parseInt(value))}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class FinancialSituationMemory:
|
||||||
openai_api_key = os.getenv("OPENAI_API_KEY")
|
openai_api_key = os.getenv("OPENAI_API_KEY")
|
||||||
self.client = OpenAI(base_url=config["backend_url"], api_key=openai_api_key)
|
self.client = OpenAI(base_url=config["backend_url"], api_key=openai_api_key)
|
||||||
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
self.chroma_client = chromadb.Client(Settings(allow_reset=True))
|
||||||
self.situation_collection = self.chroma_client.create_collection(name=name)
|
self.situation_collection = self.chroma_client.get_or_create_collection(name=name)
|
||||||
|
|
||||||
def get_embedding(self, text):
|
def get_embedding(self, text):
|
||||||
"""Get OpenAI embedding for a text"""
|
"""Get OpenAI embedding for a text"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue