Spaces:
Runtime error
Runtime error
File size: 751 Bytes
2d93ee9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
const API_BASE = import.meta.env.VITE_API_BASE || 'http://localhost:8000';
export async function fetchStream(user, session, prompt, onChunk) {
const res = await fetch(`${API_BASE}/chat/stream`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user, session, prompt }),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) break;
onChunk(decoder.decode(value));
}
}
export async function fetchSessions(user) {
const res = await fetch(`${API_BASE}/sessions/${encodeURIComponent(user)}`);
if (!res.ok) return [];
const data = await res.json();
return data.sessions ?? [];
}
|