Study/docs/AI.md
Elijah ccdad9728b
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 33s
Add drag reordering, exam deadlines, frozen shared quizzes, batched OCR and semantic search
- 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>
2026-11-12 11:48:20 -07:00

4.4 KiB

AI connections and verification

Settings → AI manages provider connections and model routing. Add a connection, test it, discover models where supported (or add a custom model), enable models and select defaults for generation, chat, explanations and vision. Output limits, capabilities, pricing and reasoning settings can be edited per model. Catalog prices are estimates, not billing records.

Adapters use OpenAI Responses, Anthropic Messages, Gemini generateContent, OpenAI-compatible Chat Completions and Ollama's native chat API. Configure the endpoint as shown in Settings. Local models are reached from the server/container: localhost inside Docker is the container itself, not your workstation or Unraid host. Use a reachable LAN address instead.

Keys are encrypted with AES-256-GCM in SQLite using /data/secret.key or APP_SECRET. Only the server decrypts them. Keep the key with backups; changing it breaks decryption. Documents are sent to the selected provider when you request AI processing; extraction and full-text indexing otherwise run locally. Review generated nursing content and source references before using it for study.

Reading scanned PDFs (OCR)

A PDF with little selectable text is read by the "Vision and OCR" model, which must accept PDFs (OpenAI, Anthropic, Gemini; OpenAI-compatible servers when the model is marked "PDF"). Long files are split with pdf-lib into batches of 8 pages (smaller if a batch exceeds 24 MB) and sent one batch per request, so there is no whole-file size cap. Each batch keeps its real page numbers for citations. Finished batches are cached beside the upload (uploads/<file>.ocr.json), so a restart or a failed batch does not repeat paid work; "Read with AI" on the document forces a fresh read. A batch that fails twice is skipped with a warning on the document. At most 600 pages are read per file.

Settings → AI → Semantic search chooses an embeddings provider and model (suggested: OpenAI text-embedding-3-small, Gemini gemini-embedding-001, Ollama nomic-embed-text; Anthropic has no embeddings API). Every document passage is embedded in the background and stored as a vector in SQLite (chunk_vectors). Search, the assistant's document search and focused generation then merge keyword (FTS5) and meaning-based rankings with reciprocal-rank fusion, so exact terms still match while paraphrased questions find the right passage. If the embedding provider fails, search silently falls back to keywords. Changing the model clears and rebuilds the index. Costs appear under Usage as "semantic indexing" / "semantic search". Quiz questions, flashcards and notes are still searched by keyword.

ChatGPT account investigation (2026-11-11)

The official Sign in with ChatGPT quickstart now describes plan access for eligible integrations. The official implementation guide distinguishes local personal/open-source tools from remotely hosted apps, which require access approval. This Unraid/reverse-proxy deployment is a hosted web application; eligibility for its private client has not been established. Therefore V2 currently uses conventional API connections, and does not advertise ChatGPT plan access or reuse another client's credentials.

To add this later, obtain the appropriate approval/registration and implement the documented OAuth/PKCE flow, verified identity, encrypted refresh tokens, approved callbacks and plan-scoped model discovery. Keep this separate from the single administrator's local login. Never copy ChatGPT browser session tokens or a Codex client's registration/credentials into Study Desk.

What has been tested

Mock protocol tests cover request translation, streams, tools, usage and error handling. Integration tests use a local OpenAI-compatible mock to generate/edit/save drafts, search documents with citations and exercise confirmed assistant actions, batched OCR of a 20-page scanned PDF and semantic indexing/search (the mock returns deterministic word-hash vectors). They cost no API credits. No successful real-provider inference or real ChatGPT OAuth authorization is claimed.

For manual local AI testing: npx tsx scripts/mock-ai.ts starts a scripted mock at http://localhost:4010/v1 with key mock-key. It returns clearly labeled synthetic material. Do not use mock output as nursing guidance. Stop the mock and remove its connection after QA.