( results: EvaluateSummaryV2, config: Partial<UnifiedConfig>, createdAt: Date = new Date(), )
| 45 | export type { StandaloneEval }; |
| 46 | |
| 47 | export async function writeResultsToDatabase( |
| 48 | results: EvaluateSummaryV2, |
| 49 | config: Partial<UnifiedConfig>, |
| 50 | createdAt: Date = new Date(), |
| 51 | ): Promise<string> { |
| 52 | createdAt = createdAt || (results.timestamp ? new Date(results.timestamp) : new Date()); |
| 53 | const evalId = createEvalId(createdAt); |
| 54 | const db = await getDb(); |
| 55 | |
| 56 | await db.transaction(async (tx) => { |
| 57 | await tx |
| 58 | .insert(evalsTable) |
| 59 | .values({ |
| 60 | id: evalId, |
| 61 | createdAt: createdAt.getTime(), |
| 62 | author: getAuthor(), |
| 63 | description: config.description, |
| 64 | config, |
| 65 | results, |
| 66 | isRedteam: config.redteam !== undefined, |
| 67 | }) |
| 68 | .onConflictDoNothing() |
| 69 | .run(); |
| 70 | |
| 71 | logger.debug(`Inserting eval ${evalId}`); |
| 72 | |
| 73 | // Record prompt relation |
| 74 | invariant(results.table, 'Table is required'); |
| 75 | |
| 76 | for (const prompt of results.table.head.prompts) { |
| 77 | const label = prompt.label || prompt.display || prompt.raw; |
| 78 | const promptId = generateIdFromPrompt(prompt); |
| 79 | |
| 80 | await tx |
| 81 | .insert(promptsTable) |
| 82 | .values({ |
| 83 | id: promptId, |
| 84 | prompt: label, |
| 85 | }) |
| 86 | .onConflictDoNothing() |
| 87 | .run(); |
| 88 | |
| 89 | await tx |
| 90 | .insert(evalsToPromptsTable) |
| 91 | .values({ |
| 92 | evalId, |
| 93 | promptId, |
| 94 | }) |
| 95 | .onConflictDoNothing() |
| 96 | .run(); |
| 97 | |
| 98 | logger.debug(`Inserting prompt ${promptId}`); |
| 99 | } |
| 100 | |
| 101 | // Record dataset relation |
| 102 | const datasetId = sha256(JSON.stringify(config.tests || [])); |
| 103 | const testsForStorage = Array.isArray(config.tests) ? config.tests : []; |
| 104 |
no test coverage detected
searching dependent graphs…