Spaces:
Running
Running
Download frontend/src/lib/api.ts from mishig/openai-math-explorer: direct link, hf CLI and curl.
- Browser
- Download file 875 Bytes
-
https://huggingface.co/spaces/mishig/openai-math-explorer/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/mishig/openai-math-explorer/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/mishig/openai-math-explorer/resolve/main/frontend/src/lib/api.ts
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; | |
| } | |