mishig's picture
mishig HF Staff
Theorem Explorer: search UI + API for github.com/openai/math
c5ced83 verified
Raw History Blame Contribute Delete
875 Bytes
import type { Catalog, SearchResponse } from "./types";
export const REPO = "https://github.com/openai/math";
export const blob = (path: string) => `${REPO}/blob/main/${path}`;
export const tree = (path: string) => `${REPO}/tree/main/${path}`;
export async function fetchCatalog(): Promise<Catalog> {
const res = await fetch("/api/catalog");
if (!res.ok) throw new Error(`catalog: ${res.status}`);
return res.json();
}
const cache = new Map<string, SearchResponse>();
export async function search(q: string, signal?: AbortSignal): Promise<SearchResponse> {
const key = q.trim().toLowerCase();
const hit = cache.get(key);
if (hit) return hit;
const res = await fetch(`/api/search?q=${encodeURIComponent(q)}`, { signal });
if (!res.ok) throw new Error(`search: ${res.status}`);
const data: SearchResponse = await res.json();
cache.set(key, data);
return data;
}