Add sandboxed Python for the assistant and a Python check of generated quizzes
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 51s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 51s
- Pyodide (Python 3.14, WebAssembly) in a separate Node process under the permission model: read-only access to Pyodide's files, no writes, processes or network, empty environment, JS bridges removed, time limit with kill and restart. - Assistant tool run_python, which can load a draft or quiz as Python data. - After quiz generation the model checks question count, type mix, correct answers per type, duplicates and recomputed calculations with Python, then submits fixes that are applied only if the question still validates. Switch in the Generate dialog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f0aabe4d5d
commit
5ea61c882c
13 changed files with 800 additions and 6 deletions
|
|
@ -42,6 +42,7 @@ import { weakTopics } from '../services/stats.ts';
|
|||
import { getSetting, setSetting } from '../settings.ts';
|
||||
import { newId, now, parseJson } from '../util.ts';
|
||||
import { generateStructured, resolveModel, runChat } from './service.ts';
|
||||
import { verifyQuizDraft } from './verify.ts';
|
||||
import { AIError } from './types.ts';
|
||||
|
||||
/* ------------------------------ drafts ------------------------------ */
|
||||
|
|
@ -285,6 +286,8 @@ export const generateRequestSchema = z.object({
|
|||
cardStyle: z.enum(['concise', 'detailed', 'medication', 'definition']).optional(),
|
||||
noteStyle: z.enum(['study_guide', 'summary', 'outline', 'cheat_sheet']).optional(),
|
||||
modelId: z.string().nullish(),
|
||||
/** Quizzes: check the finished draft with the model and the Python sandbox (default on). */
|
||||
verify: z.boolean().optional(),
|
||||
});
|
||||
export type GenerateRequest = z.infer<typeof generateRequestSchema>;
|
||||
|
||||
|
|
@ -757,6 +760,14 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ
|
|||
if (items().length === 0) throw new AIError('invalid_response', 'The model did not produce any usable items. Try again, or choose a different model for content generation.');
|
||||
if (items().length < count) notes.push(`Generated ${items().length} of the ${count} requested.`);
|
||||
|
||||
// Check counts, the type mix, answer keys and calculations with Python before review.
|
||||
if (draft.kind === 'quiz' && req.verify !== false) {
|
||||
setProgress(db, draftId, 0.96, 'Checking the questions with Python', draft);
|
||||
const checked = await verifyQuizDraft(app, draft, { count, style, sataShare: sata, difficulty }, { modelId: req.modelId, signal, onStep: (label) => setProgress(db, draftId, 0.97, label) });
|
||||
draft.questions = checked.draft.questions;
|
||||
notes.push(...checked.notes);
|
||||
}
|
||||
|
||||
db.run(
|
||||
`UPDATE drafts SET status = 'ready', title = ?, payload = ?, meta = ?, progress = 1, progress_label = '', error = '', updated_at = ? WHERE id = ?`,
|
||||
draft.title,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue