Store model on LoggedCall (#138)

This commit is contained in:
arcticfly
2023-08-11 16:39:04 -07:00
committed by GitHub
parent d9db6d80ea
commit 3a908d51aa
3 changed files with 7 additions and 9 deletions

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "LoggedCall" ADD COLUMN "model" TEXT;

View File

@@ -273,6 +273,7 @@ model LoggedCall {
projectId String @db.Uuid
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
model String?
tags LoggedCallTag[]
createdAt DateTime @default(now())

View File

@@ -141,11 +141,13 @@ export const externalApiRouter = createTRPCRouter({
const newModelResponseId = uuidv4();
let usage;
let model;
if (reqPayload.success && respPayload.success) {
usage = modelProvider.getUsage(
input.reqPayload as CompletionCreateParams,
input.respPayload as ChatCompletion,
);
model = reqPayload.data.model;
}
await prisma.$transaction([
@@ -155,6 +157,7 @@ export const externalApiRouter = createTRPCRouter({
projectId: key.projectId,
requestedAt: new Date(input.requestedAt),
cacheHit: false,
model,
},
}),
prisma.loggedCallModelResponse.create({
@@ -191,14 +194,6 @@ export const externalApiRouter = createTRPCRouter({
name: name.replaceAll(/[^a-zA-Z0-9_]/g, "_"),
value,
}));
if (reqPayload.success) {
tagsToCreate.push({
loggedCallId: newLoggedCallId,
name: "$model",
value: reqPayload.data.model,
});
}
await prisma.loggedCallTag.createMany({
data: tagsToCreate,
});