added sources to the response

This commit is contained in:
Dhravya 2024-06-16 19:00:24 -05:00
parent 0f3d5c4fc6
commit a4c835e583
2 changed files with 13 additions and 2 deletions

View file

@ -124,6 +124,7 @@ export async function batchCreateChunksAndEmbeddings({
url: body.url,
user: body.user,
type: body.type ?? "page",
content: newPageContent,
},
},
],

View file

@ -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",