forked from anis-marrouchi/chatpdf-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request anis-marrouchi#2 from EmeraldLabs/feature/chat-his…
…tory Chat Enhancements
- Loading branch information
Showing
8 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NextRequest, NextResponse } from "next/server" | ||
import { initialChatMessage } from "@/utils/chat" | ||
|
||
import { createPrisma } from "@/lib/prisma" | ||
|
||
export async function POST(request: Request) { | ||
const body = await request.json() | ||
const { childId, childContext } = body | ||
|
||
const credentials = { | ||
supabaseDatabaseUrl: process.env.DATABASE_URL, | ||
} | ||
|
||
const childInitialContextMessage = [ | ||
{ | ||
name: initialChatMessage.name, | ||
text: `${initialChatMessage.text} ${childContext}`, | ||
}, | ||
] | ||
const prisma = createPrisma({ url: credentials.supabaseDatabaseUrl }) | ||
const data = await prisma.chatHistory.create({ | ||
data: { | ||
childId: childId, | ||
messages: childInitialContextMessage, | ||
}, | ||
}) | ||
|
||
return NextResponse.json({ data }) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
prisma/migrations/20231002122742_added_chat_history_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- CreateTable | ||
CREATE TABLE "Documents" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT, | ||
"url" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "Documents_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "ChatHistory" ( | ||
"id" TEXT NOT NULL, | ||
"childId" TEXT, | ||
"messages" JSONB NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "ChatHistory_pkey" PRIMARY KEY ("id") | ||
); |
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20231002132845_added_title_column_in_chathistory_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `title` to the `ChatHistory` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "ChatHistory" ADD COLUMN "title" TEXT NOT NULL; |
9 changes: 9 additions & 0 deletions
9
prisma/migrations/20231002133243_updated_chathistory_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Warnings: | ||
- Made the column `childId` on table `ChatHistory` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "ChatHistory" ALTER COLUMN "childId" SET NOT NULL, | ||
ALTER COLUMN "title" DROP NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const initialChatMessage = { | ||
name: "system", | ||
text: "Act as an expert. Reply to questions about given data. Self reflect on your answers. Following is some of my child's information and you need to answer all my questions considering this context, ", | ||
} |