Spaces:
Running
Running
File size: 4,483 Bytes
d0622ef | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | export interface LexiconResult {
score: number;
label: string;
hawkish_hits: Record<string, number>;
dovish_hits: Record<string, number>;
word_count: number;
}
export interface SentenceResult {
sentence: string;
label: string;
score: number;
}
export interface ModelResult {
model_name: string;
score: number;
label: string;
hawkish_count: number;
dovish_count: number;
neutral_count: number;
sentences: SentenceResult[];
}
export interface AnalyzeResponse {
combined_score: number;
combined_label: string;
lexicon: LexiconResult;
model: ModelResult | null;
}
export interface HealthResponse {
status: string;
model_name: string;
model_loaded: boolean;
model_load_error: string | null;
}
export interface HistoryPoint {
doc_id: string | null;
date: string | null;
combined_score: number | null;
combined_score_rolling: number | null;
combined_label: string | null;
chair: string | null;
}
export interface FedRegime {
chair: string;
start: string;
end: string | null;
}
export interface HistoryAnnotation {
type: string;
start: string | null;
end: string | null;
label: string;
}
export interface HighlightMeeting {
doc_id: string | null;
date: string;
combined_score: number;
combined_score_rolling: number | null;
combined_label: string;
chair: string | null;
}
export interface StreakHighlight {
length: number;
start_date: string;
end_date: string;
chair: string | null;
end_chair: string | null;
}
export interface ReversalHighlight {
delta: number;
before: HighlightMeeting;
after: HighlightMeeting;
}
export interface ChairStance {
chair: string | null;
average_score: number;
meeting_count: number;
}
export interface HistoryHighlights {
current: HighlightMeeting;
trailing_year_average: number | null;
hawkish_streak: StreakHighlight | null;
dovish_streak: StreakHighlight | null;
most_hawkish: HighlightMeeting | null;
most_dovish: HighlightMeeting | null;
sharpest_reversal: ReversalHighlight | null;
by_chair: ChairStance[];
}
export interface HistoryResponse {
points: HistoryPoint[];
regimes: FedRegime[];
annotations: HistoryAnnotation[];
highlights: HistoryHighlights;
window: number;
generated_at: string;
}
export interface PhraseMatch {
phrase: string;
category: string;
start: number;
end: number;
weight: number;
}
export interface DocumentDetailResponse {
doc_id: string;
date: string | null;
chair: string | null;
combined_score: number;
combined_label: string;
lexicon_score: number;
word_count: number;
text: string;
matches: PhraseMatch[];
}
export interface FedFundsPoint {
date: string;
rate: number;
}
export interface FedFundsResponse {
points: FedFundsPoint[];
series_id: string;
source: string;
generated_at: string;
}
async function parseErrorBody(res: Response): Promise<string> {
try {
const body = await res.json();
return body.detail ? JSON.stringify(body.detail) : JSON.stringify(body);
} catch {
return res.statusText;
}
}
export async function analyzeText(text: string, useModel: boolean): Promise<AnalyzeResponse> {
const res = await fetch("/api/analyze", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text, use_model: useModel }),
});
if (!res.ok) {
throw new Error(`Analyze request failed (${res.status}): ${await parseErrorBody(res)}`);
}
return res.json();
}
export async function getHealth(): Promise<HealthResponse> {
const res = await fetch("/api/health");
if (!res.ok) {
throw new Error(`Health check failed (${res.status})`);
}
return res.json();
}
export async function getHistory(): Promise<HistoryResponse> {
const res = await fetch("/api/history");
if (!res.ok) {
throw new Error(`History request failed (${res.status}): ${await parseErrorBody(res)}`);
}
return res.json();
}
export async function getDocument(docId: string): Promise<DocumentDetailResponse> {
const res = await fetch(`/api/documents/${encodeURIComponent(docId)}`);
if (!res.ok) {
throw new Error(`Document request failed (${res.status}): ${await parseErrorBody(res)}`);
}
return res.json();
}
export async function getFedFunds(): Promise<FedFundsResponse> {
const res = await fetch("/api/fedfunds");
if (!res.ok) {
throw new Error(`Fed funds request failed (${res.status}): ${await parseErrorBody(res)}`);
}
return res.json();
}
|