Files
auv/src/lib/ai-analysis-api.ts
T

61 lines
1.8 KiB
TypeScript

// AI 分析报告 API 客户端
import { getApiBaseUrl } from "./api-client";
const API_BASE = getApiBaseUrl();
export interface AiReport {
id: number;
trade_date: string;
report_type: string;
title: string;
content: string;
summary: string | null;
toolsUsed: string[];
model: string;
tokens_used: number;
generation_count?: number;
llm_calls?: number | null;
issue_number?: number;
created_at: string;
updated_at?: string | null;
}
export async function fetchAiLatestReport(): Promise<AiReport> {
const resp = await fetch(`${API_BASE}/api/ai-analysis/latest`);
if (!resp.ok) throw new Error(`请求失败 (${resp.status})`);
const result = await resp.json();
return result.data;
}
export async function fetchAiReports(): Promise<AiReport[]> {
const resp = await fetch(`${API_BASE}/api/ai-analysis`);
if (!resp.ok) throw new Error(`请求失败 (${resp.status})`);
const result = await resp.json();
return result.data || [];
}
export async function fetchAiReport(id: number): Promise<AiReport> {
const resp = await fetch(`${API_BASE}/api/ai-analysis/${id}`);
if (!resp.ok) throw new Error(`请求失败 (${resp.status})`);
const result = await resp.json();
return result.data;
}
export async function checkAiReport(tradeDate: string): Promise<boolean> {
const resp = await fetch(`${API_BASE}/api/ai-analysis/check/${tradeDate}`);
if (!resp.ok) return false;
const result = await resp.json();
return result.data?.hasReport || false;
}
export async function regenerateAiReport(id: number): Promise<{ id: number; tokens_used: number }> {
const resp = await fetch(`${API_BASE}/api/ai-analysis/${id}/regenerate`, { method: "POST" });
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
throw new Error(err.detail || "重新生成失败");
}
const result = await resp.json();
return result.data;
}