Separate settings per generation step; explain Practice and Exam on shares
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s

- Settings -> AI: Planning, Writing, Python check and Second review each get
  their own model, reasoning effort, temperature and output limit, shown under
  Content generation. Unset choices follow Content generation, then the
  default model.
- Shared quizzes say what Practice and Exam mean under the mode toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-16 11:08:21 -07:00
parent 2454ab6e95
commit 10be5c39da
9 changed files with 128 additions and 36 deletions

View file

@ -64,12 +64,20 @@ interface ModelRow {
price_cached_in: number | null;
}
export const TASKS = ['chat', 'generate', 'vision', 'quick'] as const;
export const TASKS = ['chat', 'generate', 'plan', 'write', 'check', 'review', 'vision', 'quick'] as const;
export type TaskName = (typeof TASKS)[number];
export const TASK_INFO: Record<TaskName, { label: string; description: string }> = {
/**
* Tasks, and the steps of content generation. A step with nothing set uses Content generation's
* model and parameters (then the default's), so the steps only matter once the user sets them.
*/
export const TASK_INFO: Record<TaskName, { label: string; description: string; parent?: TaskName }> = {
chat: { label: 'Assistant', description: 'The assistant that searches your library, answers questions and runs tools.' },
generate: { label: 'Content generation', description: 'Writing quizzes, flashcards and study guides. Benefits most from a strong model.' },
generate: { label: 'Content generation', description: 'Quizzes, flashcards and study guides. Each step below can have its own settings.' },
plan: { label: 'Planning', description: 'Lists a distinct angle for every question before writing.', parent: 'generate' },
write: { label: 'Writing', description: 'Writes the questions, flashcards and study guides.', parent: 'generate' },
check: { label: 'Python check', description: 'Checks counts, answer keys and calculations with Python.', parent: 'generate' },
review: { label: 'Second review', description: 'Reads every question for badly written items.', parent: 'generate' },
vision: { label: 'Vision and OCR', description: 'Reading scanned PDFs and images. Needs a model that accepts images.' },
quick: { label: 'Quick explanations', description: 'Short explanations while studying. A fast, inexpensive model works well.' },
};
@ -379,7 +387,7 @@ export function getTaskSettings(db: DB): TaskSettings {
}
export function saveTaskSettings(db: DB, input: unknown): TaskSettings {
const schema = z.object({ default: taskConfigSchema, chat: taskConfigSchema, generate: taskConfigSchema, vision: taskConfigSchema, quick: taskConfigSchema }).partial();
const schema = z.object(Object.fromEntries(['default', ...TASKS].map((t) => [t, taskConfigSchema])) as Record<TaskName | 'default', typeof taskConfigSchema>).partial();
const patch = schema.parse(input);
const next = { ...getTaskSettings(db), ...patch } as TaskSettings;
setSetting(db, 'ai.tasks', next);
@ -399,7 +407,10 @@ export interface ResolvedModel {
export function resolveModel(app: AppContext, task: TaskName, overrideModelId?: string | null): ResolvedModel {
const tasks = getTaskSettings(app.db);
const cfg = tasks[task];
const candidates = [overrideModelId, cfg.modelId, tasks.default.modelId].filter((x): x is string => Boolean(x));
// A generation step falls back to Content generation, then to the default.
const parent = TASK_INFO[task].parent;
const chain = parent ? [cfg, tasks[parent]] : [cfg];
const candidates = [overrideModelId, ...chain.map((c) => c.modelId), tasks.default.modelId].filter((x): x is string => Boolean(x));
let model: ModelDto | undefined;
for (const id of candidates) {
const row = app.db.get<ModelRow>(`${MODEL_SELECT} WHERE m.id = ? AND p.enabled = 1`, id);
@ -420,12 +431,17 @@ export function resolveModel(app: AppContext, task: TaskName, overrideModelId?:
);
}
const provider = providerConfig(app, providerRow(app.db, model.providerId));
const own = cfg.modelId === model.id || (!cfg.modelId && tasks.default.modelId === model.id) ? cfg : EMPTY_TASK;
// A level's parameters apply when it chose this model, or chose none and inherits this model.
const applies = chain.filter((level, i) => {
const inherited = [...chain.slice(i + 1), tasks.default].find((l) => l.modelId)?.modelId ?? null;
return level.modelId ? level.modelId === model.id : inherited === model.id;
});
const fallback = tasks.default;
const pick = <K extends 'temperature' | 'reasoningEffort' | 'maxOutputTokens'>(key: K): TaskConfig[K] => applies.map((l) => l[key]).find((v) => v !== null) ?? fallback[key];
const params: ResolvedModel['params'] = {};
const temperature = own.temperature ?? fallback.temperature;
const effort = own.reasoningEffort ?? fallback.reasoningEffort;
const maxOut = own.maxOutputTokens ?? fallback.maxOutputTokens;
const temperature = pick('temperature');
const effort = pick('reasoningEffort');
const maxOut = pick('maxOutputTokens');
if (temperature !== null && model.capabilities.temperature) params.temperature = temperature;
if (effort !== null && model.capabilities.reasoning) params.reasoningEffort = effort;
if (maxOut !== null) params.maxOutputTokens = maxOut;