From 66c9a97bc6d0d1b51569681ad428d329635c8138 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Tue, 17 Sep 2024 23:42:04 -0700 Subject: [PATCH] docs: add history to docs chat (#850) --- apps/docs/app/api/entelligence-history/route.ts | 11 +++++++++++ apps/docs/components/docs-chat/DocsChat.tsx | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 apps/docs/app/api/entelligence-history/route.ts diff --git a/apps/docs/app/api/entelligence-history/route.ts b/apps/docs/app/api/entelligence-history/route.ts new file mode 100644 index 000000000..a6cfdbe1e --- /dev/null +++ b/apps/docs/app/api/entelligence-history/route.ts @@ -0,0 +1,11 @@ +export const POST = async (req: Request) => { + await fetch(process.env["ENTELLIGENCE_HISTORY_API_URL"]!, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: await req.text(), + }); + + return new Response("OK"); +}; diff --git a/apps/docs/components/docs-chat/DocsChat.tsx b/apps/docs/components/docs-chat/DocsChat.tsx index 808749fa9..0d05b6563 100644 --- a/apps/docs/components/docs-chat/DocsChat.tsx +++ b/apps/docs/components/docs-chat/DocsChat.tsx @@ -61,6 +61,18 @@ const MyCustomAdapter: ChatModelAdapter = { text += chunk; yield { content: [{ type: "text", text }] }; } + + void fetch("/api/entelligence-history", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + question: messagesToSend.at(-1)?.content, + answer: text, + previousQuestion: messagesToSend.at(-3)?.content, + }), + }); }, };