evalite
Version:
Test your LLM-powered apps with a TypeScript-native, Vitest-based eval runner. No API key required.
41 lines • 1.55 kB
JavaScript
import { DEFAULT_SERVER_PORT } from "./constants.js";
const BASE_URL = `http://localhost:${DEFAULT_SERVER_PORT}`;
/**
* Common fetch function with error handling
* @param url The URL to fetch
* @param options Fetch options
* @returns The JSON response
* @throws Error if the response is not OK
*/
async function safeFetch(url, options) {
const response = await fetch(url, options);
if (!response.ok) {
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
}
return response.json();
}
export const getServerState = async (fetchOpts) => {
return safeFetch(`${BASE_URL}/api/server-state`, fetchOpts);
};
export const getMenuItems = async (fetchOpts) => {
return safeFetch(`${BASE_URL}/api/menu-items`, fetchOpts);
};
export const getEvalByName = async (name, timestamp, fetchOpts) => {
const params = new URLSearchParams({ name, timestamp: timestamp || "" });
return safeFetch(`${BASE_URL}/api/eval?${params.toString()}`, fetchOpts);
};
export const getResult = async (opts, fetchOpts) => {
const params = new URLSearchParams({
name: opts.evalName,
index: opts.resultIndex,
timestamp: opts.evalTimestamp || "",
});
return safeFetch(`${BASE_URL}/api/eval/result?${params.toString()}`, fetchOpts);
};
export const serveFile = (filepath) => {
return `${BASE_URL}/api/file?path=${filepath}`;
};
export const downloadFile = (filepath) => {
return `${BASE_URL}/api/file?path=${filepath}&download=true`;
};
//# sourceMappingURL=sdk.js.map