first commit of v.02 application

This commit is contained in:
KS Jannette
2026-05-07 23:20:30 -04:00
commit a6b0a95dfc
98 changed files with 21028 additions and 0 deletions

36
client/src/api/query.js Normal file
View File

@@ -0,0 +1,36 @@
'use strict';
import { handleResponse } from './client.js';
const BASE = '/api/query';
const CITATION_DETAIL_BASE = '/api/citation-detail';
export async function sendQuery(notebookId, question, onCitationDetails) {
const res = await fetch(BASE, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId, question }),
});
const data = await handleResponse(res);
if (data.citations?.length && onCitationDetails) {
Promise.all(
data.citations.map((c) =>
fetch(CITATION_DETAIL_BASE, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chunkTexts: c.chunkTexts,
sourceName: c.name,
answer: data.answer,
citationIndex: c.sourceIndex,
}),
})
.then((r) => handleResponse(r))
.then((detail) => ({ sourceIndex: c.sourceIndex, ...detail }))
)
).then(onCitationDetails);
}
return data;
}