From a4c835e58370641947a757cbcb5d3ff4d4c09c06 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Sun, 16 Jun 2024 19:00:24 -0500 Subject: [PATCH] added sources to the response --- apps/cf-ai-backend/src/helper.ts | 1 + apps/web/app/(dash)/chat/chatWindow.tsx | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/cf-ai-backend/src/helper.ts b/apps/cf-ai-backend/src/helper.ts index 1540c9fd..32928250 100644 --- a/apps/cf-ai-backend/src/helper.ts +++ b/apps/cf-ai-backend/src/helper.ts @@ -124,6 +124,7 @@ export async function batchCreateChunksAndEmbeddings({ url: body.url, user: body.user, type: body.type ?? "page", + content: newPageContent, }, }, ], diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index 8956ba9b..3fd08657 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -73,8 +73,18 @@ function ChatWindow({ return; } - console.log(sourcesParsed.data.ids); - console.log(sourcesParsed.data.metadata); + setChatHistory((prevChatHistory) => { + const newChatHistory = [...prevChatHistory]; + const lastAnswer = newChatHistory[newChatHistory.length - 1]; + if (!lastAnswer) return prevChatHistory; + lastAnswer.answer.sources = sourcesParsed.data.metadata.map((source) => ({ + title: source.title ?? "Untitled", + type: source.type ?? "page", + source: source.url ?? "https://supermemory.ai", + content: source.content ?? "No content available", + })); + return newChatHistory; + }); const resp = await fetch(`/api/chat?q=${query}&spaces=${spaces}`, { method: "POST",