Function
hashAndSaveDatasetEntryInput
({
projectId,
tool_choice,
tools,
messages,
response_format,
inputTokens,
trx = kysely,
}: {
projectId: string;
inputTokens?: number;
trx?: typeof kysely;
} & Pick<ChatCompletionCreateParams, "tool_choice" | "tools" | "messages" | "response_format">)
Source from the content-addressed store, hash-verified
| 45 | }; |
| 46 | |
| 47 | export const hashAndSaveDatasetEntryInput = async ({ |
| 48 | projectId, |
| 49 | tool_choice, |
| 50 | tools, |
| 51 | messages, |
| 52 | response_format, |
| 53 | inputTokens, |
| 54 | trx = kysely, |
| 55 | }: { |
| 56 | projectId: string; |
| 57 | inputTokens?: number; |
| 58 | trx?: typeof kysely; |
| 59 | } & Pick<ChatCompletionCreateParams, "tool_choice" | "tools" | "messages" | "response_format">) => { |
| 60 | const inputHash = hashDatasetEntryInput({ |
| 61 | projectId, |
| 62 | tool_choice, |
| 63 | tools, |
| 64 | messages, |
| 65 | response_format, |
| 66 | }); |
| 67 | |
| 68 | await trx |
| 69 | .insertInto("DatasetEntryInput") |
| 70 | .values({ |
| 71 | projectId, |
| 72 | hash: inputHash, |
| 73 | tool_choice: tool_choice ? JSON.stringify(tool_choice) : undefined, |
| 74 | tools: tools ? JSON.stringify(tools) : undefined, |
| 75 | messages: JSON.stringify(messages), |
| 76 | response_format: response_format ? JSON.stringify(response_format) : undefined, |
| 77 | inputTokens, |
| 78 | }) |
| 79 | .onConflict((oc) => oc.columns(["hash"]).doNothing()) |
| 80 | .execute(); |
| 81 | |
| 82 | return inputHash; |
| 83 | }; |
| 84 | |
| 85 | export const hashDatasetEntryOutput = ({ |
| 86 | projectId, |