({
modelId,
nodeEntryId,
skipCache,
}: {
modelId: string;
nodeEntryId: string;
skipCache?: boolean;
})
| 76 | }); |
| 77 | |
| 78 | export const generateEntry = async ({ |
| 79 | modelId, |
| 80 | nodeEntryId, |
| 81 | skipCache, |
| 82 | }: { |
| 83 | modelId: string; |
| 84 | nodeEntryId: string; |
| 85 | skipCache?: boolean; |
| 86 | }) => { |
| 87 | const nodeEntry = await kysely |
| 88 | .selectFrom("NodeEntry as ne") |
| 89 | .where("ne.id", "=", nodeEntryId) |
| 90 | .innerJoin("DataChannel as dc", "dc.id", "ne.dataChannelId") |
| 91 | .innerJoin("Node as n", "n.id", "dc.destinationId") |
| 92 | .innerJoin("Dataset as d", "d.nodeId", "n.id") |
| 93 | .innerJoin("DatasetEntryInput as dei", "dei.hash", "ne.inputHash") |
| 94 | .innerJoin("DatasetEntryOutput as deo", "deo.hash", "ne.outputHash") |
| 95 | .select([ |
| 96 | "n.projectId", |
| 97 | "d.id as datasetId", |
| 98 | "ne.persistentId", |
| 99 | "ne.inputHash", |
| 100 | "dei.tool_choice", |
| 101 | "dei.tools", |
| 102 | "dei.messages", |
| 103 | "dei.response_format", |
| 104 | "deo.output", |
| 105 | ]) |
| 106 | .executeTakeFirst(); |
| 107 | |
| 108 | if (!nodeEntry) return; |
| 109 | |
| 110 | let fineTune; |
| 111 | if (!isComparisonModel(modelId)) { |
| 112 | fineTune = await prisma.fineTune |
| 113 | .findUnique({ |
| 114 | where: { id: modelId }, |
| 115 | }) |
| 116 | .then((ft) => ft && typedFineTune(ft)); |
| 117 | } |
| 118 | |
| 119 | // If the fine-tune was deleted then we don't need to generate a test set |
| 120 | // entry |
| 121 | if (!fineTune && !isComparisonModel(modelId)) return; |
| 122 | |
| 123 | const tNodeEntry = typedNodeEntry(nodeEntry); |
| 124 | |
| 125 | const existingTestEntry = await kysely |
| 126 | .selectFrom("FineTuneTestingEntry as ftte") |
| 127 | .where("ftte.modelId", "=", modelId) |
| 128 | .where("ftte.inputHash", "=", nodeEntry.inputHash) |
| 129 | .innerJoin("DatasetEntryOutput as deo", "deo.hash", "ftte.outputHash") |
| 130 | .select(["ftte.outputHash", "ftte.errorMessage", "deo.output"]) |
| 131 | .executeTakeFirst(); |
| 132 | |
| 133 | if (existingTestEntry?.outputHash && !existingTestEntry.errorMessage && !skipCache) { |
| 134 | const existingOutput = chatCompletionMessage.safeParse(existingTestEntry.output); |
| 135 |
no test coverage detected