Function
hashAndSaveDatasetEntryOutput
({
projectId,
output,
outputTokens,
trx = kysely,
}: {
projectId: string;
output: ChatCompletionMessage;
outputTokens?: number;
trx?: typeof kysely;
})
Source from the content-addressed store, hash-verified
| 96 | }; |
| 97 | |
| 98 | export const hashAndSaveDatasetEntryOutput = async ({ |
| 99 | projectId, |
| 100 | output, |
| 101 | outputTokens, |
| 102 | trx = kysely, |
| 103 | }: { |
| 104 | projectId: string; |
| 105 | output: ChatCompletionMessage; |
| 106 | outputTokens?: number; |
| 107 | trx?: typeof kysely; |
| 108 | }) => { |
| 109 | const outputHash = hashDatasetEntryOutput({ projectId, output }); |
| 110 | |
| 111 | await trx |
| 112 | .insertInto("DatasetEntryOutput") |
| 113 | .values({ |
| 114 | projectId, |
| 115 | hash: outputHash, |
| 116 | output: JSON.stringify(output), |
| 117 | outputTokens, |
| 118 | }) |
| 119 | .onConflict((oc) => oc.columns(["hash"]).doNothing()) |
| 120 | .execute(); |
| 121 | |
| 122 | return outputHash; |
| 123 | }; |