First revision: DeepSeek, numeric questions, background assistant, UI fixes
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 1m2s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 1m2s
Providers and pricing - Add a DeepSeek provider: thinking mode with low/high/max effort, reasoning_content replayed between tool steps, cache-hit usage, /models discovery and catalog prices. - Fix "does not support tool calling": a rejected forced tool_choice (DeepSeek thinking mode) now asks for the call in the prompt; only a genuine no-tools 400 is "unsupported". - Seven reasoning-effort levels (Off to Max) mapped per adapter. - Cached-input price per model, cache-write and DeepSeek off-peak aware cost estimates. - Built-in bge-small embedding model (transformers.js) as the semantic search default. Quizzes - Numeric (type-the-answer) questions: units ignored, optional ± tolerance; editor, runner, importer, templates and generation prompts. - Quiz start screen instead of showing answers; navigator ring no longer clipped and key legend removed; clock only for timed exams; 7-point letter grades. Assistant and generation - Assistant turns run on the server independently of the browser, with re-attach and an explicit stop; drafts tray shows generations in progress. - Per-chat model switcher, @-tagging of class materials, full-width assistant page and a smaller assistant button. - Editable generation instructions and built-in presets, separate from the chatbot import instructions. Other - Dialog footer padding, keyboard hints removed, copy buttons work over plain HTTP, class and folder shares include documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ccdad9728b
commit
f0aabe4d5d
63 changed files with 3892 additions and 488 deletions
|
|
@ -11,6 +11,7 @@
|
|||
* ("why do patients on furosemide need bananas?") also find the right passage.
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
import { LOCAL_EMBEDDING_LABEL, LOCAL_EMBEDDING_MODEL, LOCAL_PROVIDER_ID, localEmbed, localModelStatus } from '../ai/localEmbed.ts';
|
||||
import { getAdapter } from '../ai/providers/index.ts';
|
||||
import { providerConfigById } from '../ai/service.ts';
|
||||
import { AIError, type ProviderKind } from '../ai/types.ts';
|
||||
|
|
@ -23,6 +24,7 @@ import { chunkById, searchChunks, type ChunkHit, type ChunkScope } from './docum
|
|||
/* ------------------------------ settings ------------------------------ */
|
||||
|
||||
export interface EmbeddingSettings {
|
||||
/** A provider id, `local` for the built-in model, or null for keyword search only. */
|
||||
providerId: string | null;
|
||||
model: string;
|
||||
/** Requested vector size for models that support shortening (OpenAI v3, Gemini). Null = native. */
|
||||
|
|
@ -31,6 +33,13 @@ export interface EmbeddingSettings {
|
|||
|
||||
const SETTINGS_KEY = 'embeddings';
|
||||
const EMPTY: EmbeddingSettings = { providerId: null, model: '', dimensions: null };
|
||||
const LOCAL: EmbeddingSettings = { providerId: LOCAL_PROVIDER_ID, model: LOCAL_EMBEDDING_MODEL, dimensions: null };
|
||||
|
||||
/** Whether an install that never chose an embedding provider uses the built-in model. */
|
||||
let localDefault = false;
|
||||
export function setLocalEmbeddingDefault(on: boolean): void {
|
||||
localDefault = on;
|
||||
}
|
||||
|
||||
/** Suggested embedding model per provider type. Anthropic has no embeddings API. */
|
||||
export const DEFAULT_EMBEDDING_MODELS: Record<ProviderKind, string | null> = {
|
||||
|
|
@ -39,6 +48,7 @@ export const DEFAULT_EMBEDDING_MODELS: Record<ProviderKind, string | null> = {
|
|||
ollama: 'nomic-embed-text',
|
||||
openai_compatible: '',
|
||||
anthropic: null,
|
||||
deepseek: null,
|
||||
};
|
||||
|
||||
/** USD per million input tokens, for the usage log. */
|
||||
|
|
@ -56,7 +66,11 @@ export const embeddingSettingsSchema = z.object({
|
|||
});
|
||||
|
||||
export function getEmbeddingSettings(db: DB): EmbeddingSettings {
|
||||
return { ...EMPTY, ...getSetting<Partial<EmbeddingSettings>>(db, SETTINGS_KEY, EMPTY) };
|
||||
const stored = getSetting<Partial<EmbeddingSettings> | null>(db, SETTINGS_KEY, null);
|
||||
// Nothing chosen yet: the built-in model, so semantic search works without a cloud account.
|
||||
if (!stored) return localDefault ? { ...LOCAL } : { ...EMPTY };
|
||||
const s = { ...EMPTY, ...stored };
|
||||
return s.providerId === LOCAL_PROVIDER_ID ? { ...LOCAL } : s;
|
||||
}
|
||||
|
||||
const modelKey = (s: EmbeddingSettings) => `${s.providerId}:${s.model}:${s.dimensions ?? 'native'}`;
|
||||
|
|
@ -64,7 +78,10 @@ const isConfigured = (s: EmbeddingSettings) => Boolean(s.providerId && s.model);
|
|||
|
||||
export function saveEmbeddingSettings(app: AppContext, input: z.input<typeof embeddingSettingsSchema>): EmbeddingSettings {
|
||||
const next = embeddingSettingsSchema.parse(input);
|
||||
if (next.providerId) {
|
||||
if (next.providerId === LOCAL_PROVIDER_ID) {
|
||||
next.model = LOCAL_EMBEDDING_MODEL;
|
||||
next.dimensions = null;
|
||||
} else if (next.providerId) {
|
||||
const { kind } = providerConfigById(app, next.providerId);
|
||||
if (!getAdapter(kind).embed) throw badRequest('This provider has no embeddings API. Choose OpenAI, Gemini, Ollama or an OpenAI-compatible server.');
|
||||
if (!next.model) throw badRequest('Enter the embedding model to use.');
|
||||
|
|
@ -99,6 +116,11 @@ function normalise(v: number[]): Float32Array {
|
|||
export async function embedTexts(app: AppContext, texts: string[], purpose: 'document' | 'query', signal?: AbortSignal): Promise<Float32Array[]> {
|
||||
const s = getEmbeddingSettings(app.db);
|
||||
if (!isConfigured(s)) throw new AIError('not_configured', 'Semantic search is not set up. Choose an embedding model in Settings → AI.');
|
||||
if (s.providerId === LOCAL_PROVIDER_ID) {
|
||||
// Free and on this machine: nothing to log in the usage table.
|
||||
const vectors = await localEmbed(app.config.dataDir, texts, purpose, signal);
|
||||
return vectors.map(normalise);
|
||||
}
|
||||
const { cfg, kind, name } = providerConfigById(app, s.providerId!);
|
||||
const adapter = getAdapter(kind);
|
||||
if (!adapter.embed) throw new AIError('unsupported', `${name} has no embeddings API.`);
|
||||
|
|
@ -202,7 +224,16 @@ export function embeddingStatus(app: AppContext) {
|
|||
const s = getEmbeddingSettings(app.db);
|
||||
const total = app.db.get<{ n: number }>('SELECT COUNT(*) AS n FROM chunks')?.n ?? 0;
|
||||
const indexed = isConfigured(s) ? (app.db.get<{ n: number }>('SELECT COUNT(*) AS n FROM chunk_vectors WHERE model_key = ?', modelKey(s))?.n ?? 0) : 0;
|
||||
return { settings: s, configured: isConfigured(s), indexed, total, running: state.running, lastError: state.lastError, defaults: DEFAULT_EMBEDDING_MODELS };
|
||||
return {
|
||||
settings: s,
|
||||
configured: isConfigured(s),
|
||||
indexed,
|
||||
total,
|
||||
running: state.running,
|
||||
lastError: state.lastError,
|
||||
defaults: DEFAULT_EMBEDDING_MODELS,
|
||||
local: { ...localModelStatus(app.config.dataDir), label: LOCAL_EMBEDDING_LABEL, enabledByDefault: localDefault },
|
||||
};
|
||||
}
|
||||
|
||||
/* ------------------------------ vector search ------------------------------ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue