Spaces:
Sleeping
Sleeping
File size: 2,763 Bytes
f263c36 75959de d26f541 d35e9ec d26f541 8614f30 f263c36 5b91336 d26f541 d35e9ec d26f541 d35e9ec 8614f30 f263c36 d26f541 d35e9ec d26f541 d35e9ec d26f541 8614f30 f263c36 d26f541 5b91336 d26f541 d35e9ec d26f541 d35e9ec d26f541 8614f30 f263c36 d26f541 5b91336 d26f541 d35e9ec d26f541 d35e9ec f263c36 d26f541 8614f30 f263c36 d26f541 |
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 |
import type { Theme, Judges, Model, ModelFamily, Provider, TransitionMatrix, AssessmentItem, ApiError } from '../types.js';
// This helper centralizes our fetch logic and error handling.
async function fetchAPI<T>(url: string, options?: RequestInit): Promise<T> {
const response = await fetch(url, options);
if (!response.ok) {
const errorBody = (await response.json().catch(() => ({ error: 'An unknown error occurred' }))) as ApiError;
const errorMessage = errorBody.error || `HTTP error! Status: ${response.status}`;
throw new Error(errorMessage);
}
return response.json() as Promise<T>;
}
// --- API Functions ---
export const getThemes = (): Promise<Theme[]> => {
return fetchAPI<Theme[]>('/api/themes');
};
export const getJudges = async (): Promise<Judges[]> => {
return fetchAPI<Judges[]>('/api/judges')
};
export const getModels = async (): Promise<Model[]> => {
return fetchAPI<Model[]>('/api/models')
}
export const getModelFamilies = async (): Promise<ModelFamily[]> => {
return fetchAPI<ModelFamily[]>('/api/models_families')
}
export const getProviders = async (): Promise<Provider[]> => {
return fetchAPI<Provider[]>('/api/providers')
}
export const getReclassificationData = (
judge1: string,
judge1Classification: string,
judge2: string,
judge2Classification: string,
theme?: string,
model?: string,
modelFamily?: string,
provider?: string
): Promise<TransitionMatrix> => {
// Build the query string from the parameters
const params = new URLSearchParams({
judge1,
judge1Classification,
judge2,
judge2Classification
});
// Only add the theme parameter if it's provided
if (theme) {
params.append('theme', theme);
}
if (model) {
params.append('model', model);
}
if (modelFamily) {
params.append('modelFamily', modelFamily);
}
if (provider) {
params.append('provider', provider);
}
return fetchAPI<TransitionMatrix>(`/api/reclassification?${params.toString()}`);
};
export const getAssessmentItems = (
judge1: string,
judge1Classification: string,
fromCategory: string,
judge2: string,
judge2Classification: string,
toCategory: string,
theme?: string,
model?: string,
modelFamily?: string,
provider?: string
): Promise<any[]> => {
const params = new URLSearchParams({
judge1,
judge1Classification,
fromCategory,
judge2,
judge2Classification,
toCategory
});
if (theme) {
params.append('theme', theme);
}
if (model) {
params.append('model', model);
}
if (modelFamily) {
params.append('modelFamily', modelFamily);
}
if (provider) {
params.append('provider', provider);
}
return fetchAPI<AssessmentItem[]>(`/api/mismatches?${params.toString()}`);
} |