fix(skiva-1): spara accept, bildref, lokal träningsbank, lärande-loop-dok
- confirm-loop sparar nu även action=accept som positivt exempel i ai_corrections - imageS3Key sparas vid image_training-samtycke, annars null - ai_corrections.proposal lagrar det specifika AI-förslaget per item - BUILD_TRAINING_SAMPLE bankar lokalt till ai_training_bank (ej externt runTask) - Jobbet kastar aldrig i AAMOS_MODE=gemini - Migration 0020: ai_corrections.image_s3_key/proposal + ai_training_bank - docs/28-lärande-loop.md: datakontrakt, samtycke, retention, GDPR-radering - Tester: accept + bildref (ja/nej) + lokal bank i gemini-läge - REQUIRE_REAL=1 är AI-fokuserat i gemini-läge; staging mail/S3 får vara mock
This commit is contained in:
@@ -333,7 +333,10 @@ export async function processMemorySync(ctx: WorkerContext): Promise<number> {
|
||||
return updates;
|
||||
}
|
||||
|
||||
/** BUILD_TRAINING_SAMPLE (spec §33): exportera korrigeringar MED samtycke till AAMOS. */
|
||||
/** BUILD_TRAINING_SAMPLE (spec §33): bank eligible corrections to an app-owned,
|
||||
* versioned training dataset. In Skiva 1 this is local storage, not an external
|
||||
* AAMOS/Gemini runTask call, so the job never throws when AAMOS_MODE=gemini.
|
||||
*/
|
||||
export async function processTrainingExport(ctx: WorkerContext): Promise<number> {
|
||||
const corrections = await ctx.db
|
||||
.select()
|
||||
@@ -348,37 +351,30 @@ export async function processTrainingExport(ctx: WorkerContext): Promise<number>
|
||||
|
||||
if (eligible.length === 0) return 0;
|
||||
|
||||
const result = await ctx.aamos.runTask(
|
||||
"EXPORT_TRAINING_SAMPLE",
|
||||
{
|
||||
marketLocale: "sv-SE",
|
||||
samples: eligible.map((c) => ({
|
||||
taskType: c.taskType,
|
||||
aiOutput: c.aiOutput as Record<string, unknown>,
|
||||
userCorrection: c.userCorrection as Record<string, unknown>,
|
||||
modelVersion: c.modelVersion ?? null,
|
||||
promptVersion: c.promptVersion ?? null,
|
||||
})),
|
||||
},
|
||||
{
|
||||
correlationId: `training-export-${Date.now()}`,
|
||||
consentFlags: {
|
||||
personalization: false,
|
||||
anonymizedImprovement: true,
|
||||
imageTraining: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
const version = "v1";
|
||||
const batchId = `cibello-local-${version}-${Date.now()}`;
|
||||
const exportedAt = new Date();
|
||||
|
||||
if (result.status !== "ok" || !result.output) {
|
||||
throw new Error(`AAMOS training export failed: ${result.error ?? "unknown"}`);
|
||||
}
|
||||
|
||||
const batchId = result.output.batchId;
|
||||
for (const correction of eligible) {
|
||||
const userCorrection = correction.userCorrection as Record<string, unknown>;
|
||||
await ctx.db.insert(schema.aiTrainingBank).values({
|
||||
correctionId: correction.id,
|
||||
scanJobId: correction.scanJobId,
|
||||
version,
|
||||
taskType: correction.taskType,
|
||||
imageS3Key: correction.imageS3Key,
|
||||
proposal: (correction.proposal ?? {}) as Record<string, unknown>,
|
||||
action: String(userCorrection.action ?? "unknown"),
|
||||
corrected: (userCorrection.corrected ?? null) as Record<string, unknown> | null,
|
||||
modelVersion: correction.modelVersion,
|
||||
promptVersion: correction.promptVersion,
|
||||
consentSnapshot: correction.consentSnapshot,
|
||||
exportedAt,
|
||||
});
|
||||
|
||||
await ctx.db
|
||||
.update(schema.aiCorrections)
|
||||
.set({ exportedToTraining: new Date(), trainingBatchId: batchId })
|
||||
.set({ exportedToTraining: exportedAt, trainingBatchId: batchId })
|
||||
.where(eq(schema.aiCorrections.id, correction.id));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user