Add drag reordering, exam deadlines, frozen shared quizzes, batched OCR and semantic search
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
- Drag-to-reorder for class materials, folders, quiz questions and deck cards. Pointer-based so touch works, plus keyboard (arrows/Home/End) with screen-reader announcements. - Timed exams get a wall-clock deadline. The server refuses late answers, submits overdue exams with what was saved, and the countdown keeps running while the page is closed. - Shared quiz sessions keep a frozen copy of their questions and flag later owner edits. - Scanned PDFs are read in cached 8-page batches with real page numbers (pdf-lib), removing the 30 MB whole-file limit. Compatible providers now receive PDFs as file parts. - Semantic search: embeddings for OpenAI, Gemini, Ollama and compatible servers, background indexing into chunk_vectors (migration 2), hybrid keyword + vector ranking for search, the assistant and focused generation, and a Settings -> AI section. 181 tests pass locally and in the Docker test stage on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3046e46d1c
commit
ccdad9728b
39 changed files with 1772 additions and 121 deletions
|
|
@ -6,6 +6,7 @@
|
|||
* - Tools + user turn -> picks a tool from keywords in the message.
|
||||
* - Tool result turn -> answers in text, citing the first [cN] ref it was given.
|
||||
* - No tools -> streams a short Markdown answer.
|
||||
* - /embeddings -> deterministic word-hash vectors (see mockEmbedding).
|
||||
*/
|
||||
import http from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
|
|
@ -21,6 +22,27 @@ export interface MockAi {
|
|||
const text = (content: unknown): string =>
|
||||
typeof content === 'string' ? content : Array.isArray(content) ? content.map((p: any) => (typeof p?.text === 'string' ? p.text : '')).join('\n') : '';
|
||||
|
||||
/**
|
||||
* Deterministic "embeddings": hashed bag of words over 64 dimensions, with a few nursing
|
||||
* synonyms folded together so a paraphrased query lands near the right passage.
|
||||
*/
|
||||
const SYNONYMS: Record<string, string> = {
|
||||
lasix: 'furosemide', loop: 'furosemide', diuretic: 'furosemide', diuretics: 'furosemide',
|
||||
banana: 'potassium', bananas: 'potassium', hypokalemia: 'potassium', k: 'potassium',
|
||||
halos: 'digoxin', lanoxin: 'digoxin', glycoside: 'digoxin',
|
||||
};
|
||||
export function mockEmbedding(input: string, dims = 64): number[] {
|
||||
const v = new Array(dims).fill(0);
|
||||
for (const raw of input.toLowerCase().match(/[a-z]+/g) ?? []) {
|
||||
if (raw.length < 3 && raw !== 'k') continue;
|
||||
const word = SYNONYMS[raw] ?? raw;
|
||||
let h = 2166136261;
|
||||
for (const ch of word) h = Math.imul(h ^ ch.charCodeAt(0), 16777619) >>> 0;
|
||||
v[h % dims] += 1;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
function questions(n: number, refs: string[], offset = 0) {
|
||||
return Array.from({ length: n }, (_, k) => {
|
||||
const i = k + offset;
|
||||
|
|
@ -107,6 +129,11 @@ export function startMockAi(port = 0): Promise<MockAi> {
|
|||
|
||||
if (req.headers.authorization !== 'Bearer mock-key') return json(401, { error: { message: 'Incorrect API key provided: ' + String(req.headers.authorization), type: 'invalid_request_error' } });
|
||||
if (path.endsWith('/models')) return json(200, { object: 'list', data: [{ id: 'mock-large' }, { id: 'mock-small' }, { id: 'mock-embedding-1' }] });
|
||||
if (path.endsWith('/embeddings')) {
|
||||
const inputs: string[] = Array.isArray(body?.input) ? body.input : [String(body?.input ?? '')];
|
||||
const dims = Number(body?.dimensions) || 64;
|
||||
return json(200, { object: 'list', model: body?.model, data: inputs.map((t, index) => ({ object: 'embedding', index, embedding: mockEmbedding(t, dims) })), usage: { prompt_tokens: Math.ceil(inputs.join(' ').length / 4), total_tokens: Math.ceil(inputs.join(' ').length / 4) } });
|
||||
}
|
||||
if (!path.endsWith('/chat/completions')) return json(404, { error: { message: 'not found' } });
|
||||
if (fail.times > 0) {
|
||||
fail.times -= 1;
|
||||
|
|
@ -144,6 +171,17 @@ export function startMockAi(port = 0): Promise<MockAi> {
|
|||
end('stop', Math.ceil(content.length / 4));
|
||||
};
|
||||
|
||||
// Document reading: answer with one "## Page N" section per page of the attached batch.
|
||||
if (/Transcribe this study material/.test(userText)) {
|
||||
const file = (Array.isArray(lastUser?.content) ? lastUser.content : []).find((p: any) => p?.type === 'file');
|
||||
if (!file?.file?.file_data?.startsWith('data:application/pdf;base64,')) return say('[no readable file attached]');
|
||||
const range = /contains pages? (\d+)(?:-(\d+))? of a/i.exec(userText);
|
||||
const from = Number(range?.[1] ?? 1);
|
||||
const to = Number(range?.[2] ?? range?.[1] ?? 1);
|
||||
const pages = Array.from({ length: to - from + 1 }, (_, k) => `## Page ${from + k}\n\nScanned lecture text for page ${from + k}: nursing priority ${from + k}.`);
|
||||
return say(pages.join('\n\n'));
|
||||
}
|
||||
|
||||
const forced = body?.tool_choice?.function?.name as string | undefined;
|
||||
if (forced) return callTool(forced);
|
||||
if (last.role === 'tool') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue