Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download frontend/src/api.js from kiyer/pathfinder: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/kiyer/pathfinder/resolve/main/frontend/src/api.js
- Command line
-
hf download hf://spaces/kiyer/pathfinder/frontend/src/api.js
-
curl -L -o api.js https://huggingface.co/spaces/kiyer/pathfinder/resolve/main/frontend/src/api.js
1.35 kB
| // frontend/src/api.js | |
| export async function runSearch(query, topK, answerStyle, handlers) { | |
| const res = await fetch('/api/search', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ query, top_k: topK, answer_style: answerStyle }), | |
| }); | |
| const { jobId } = await res.json(); | |
| const es = new EventSource(`/api/jobs/${jobId}/events`); | |
| es.addEventListener('stage', (e) => handlers.onStage?.(JSON.parse(e.data))); | |
| es.addEventListener('papers', (e) => handlers.onPapers?.(JSON.parse(e.data).papers)); | |
| es.addEventListener('answer_token', (e) => handlers.onAnswerToken?.(JSON.parse(e.data).text)); | |
| es.addEventListener('consensus', (e) => handlers.onConsensus?.(JSON.parse(e.data))); | |
| es.addEventListener('blocked', (e) => { handlers.onBlocked?.(JSON.parse(e.data)); es.close(); }); | |
| es.addEventListener('result', () => { handlers.onDone?.(); es.close(); }); | |
| es.addEventListener('error', (e) => { | |
| try { handlers.onError?.(JSON.parse(e.data)); } catch { handlers.onError?.({ message: 'connection lost' }); } | |
| es.close(); | |
| }); | |
| return es; | |
| } | |
| export async function fetchUmapSample() { | |
| const res = await fetch('/api/umap-sample'); | |
| return (await res.json()).points; | |
| } | |
| export async function fetchStats() { | |
| const res = await fetch('/api/stats'); | |
| return (await res.json()).total; | |
| } |