Skip to content

Commit

Permalink
Add BotApiHistory model and create records in chatRequestAPIHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
n4ze3m committed Mar 5, 2024
1 parent 5f6a0ed commit 4daf9ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/prisma/migrations/q_19/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "BotApiHistory" (
"id" SERIAL NOT NULL,
"api_key" TEXT NOT NULL,
"bot_id" TEXT,
"human" TEXT,
"bot" TEXT,
"createdAt" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "BotApiHistory_pkey" PRIMARY KEY ("id")
);
9 changes: 9 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,12 @@ model DialoqbaseModels {
deleted Boolean @default(false)
createdAt DateTime @default(now())
}

model BotApiHistory {
id Int @id @default(autoincrement())
api_key String
bot_id String?
human String?
bot String?
createdAt DateTime? @default(now())
}
19 changes: 19 additions & 0 deletions server/src/handlers/bot/api.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export const chatRequestAPIHandler = async (
});
const documents = await documentPromise;


await prisma.botApiHistory.create({
data: {
api_key: request.headers["x-api-key"],
bot_id: bot.id,
human: message,
bot: response,
}
})

reply.sse({
event: "result",
id: "",
Expand Down Expand Up @@ -359,6 +369,15 @@ export const chatRequestAPIHandler = async (

const documents = await documentPromise;

await prisma.botApiHistory.create({
data: {
api_key: request.headers["x-api-key"],
bot_id: bot.id,
human: message,
bot: botResponse,
}
})

return {
bot: {
text: botResponse,
Expand Down

0 comments on commit 4daf9ba

Please sign in to comment.