diff options
| author | Dhravya <[email protected]> | 2024-06-16 19:13:32 -0500 |
|---|---|---|
| committer | Dhravya <[email protected]> | 2024-06-16 19:13:32 -0500 |
| commit | 76c48ccb600d172f362d7cd237094d6082454825 (patch) | |
| tree | 2181eb10c103c558442c661071d7ad8f747189df /apps/web | |
| parent | added sources to the response (diff) | |
| download | archived-supermemory-76c48ccb600d172f362d7cd237094d6082454825.tar.xz archived-supermemory-76c48ccb600d172f362d7cd237094d6082454825.zip | |
add number of chunks to the respnose and only show unique values
Diffstat (limited to 'apps/web')
| -rw-r--r-- | apps/web/app/(dash)/chat/chatWindow.tsx | 37 | ||||
| -rw-r--r-- | apps/web/app/actions/doers.ts | 1 |
2 files changed, 32 insertions, 6 deletions
diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx index 3fd08657..77c1f32b 100644 --- a/apps/web/app/(dash)/chat/chatWindow.tsx +++ b/apps/web/app/(dash)/chat/chatWindow.tsx @@ -22,6 +22,8 @@ import { code, p } from "./markdownRenderHelpers"; import { codeLanguageSubset } from "@/lib/constants"; import { z } from "zod"; import { toast } from "sonner"; +import Link from "next/link"; +import { sources } from "next/dist/compiled/webpack/webpack"; function ChatWindow({ q, @@ -77,11 +79,24 @@ function ChatWindow({ const newChatHistory = [...prevChatHistory]; const lastAnswer = newChatHistory[newChatHistory.length - 1]; if (!lastAnswer) return prevChatHistory; - lastAnswer.answer.sources = sourcesParsed.data.metadata.map((source) => ({ + const filteredSourceUrls = new Set( + sourcesParsed.data.metadata.map((source) => source.url), + ); + const uniqueSources = sourcesParsed.data.metadata.filter((source) => { + if (filteredSourceUrls.has(source.url)) { + filteredSourceUrls.delete(source.url); + return true; + } + return false; + }); + lastAnswer.answer.sources = uniqueSources.map((source) => ({ title: source.title ?? "Untitled", type: source.type ?? "page", source: source.url ?? "https://supermemory.ai", content: source.content ?? "No content available", + numChunks: sourcesParsed.data.metadata.filter( + (f) => f.url === source.url, + ).length, })); return newChatHistory; }); @@ -191,15 +206,25 @@ function ChatWindow({ </> ))} {chat.answer.sources.map((source, idx) => ( - <div + <Link + href={source.source} key={idx} className="rounded-xl bg-secondary p-4 flex flex-col gap-2 min-w-72" > - <div className="text-foreground-menu"> - {source.type} + <div className="flex justify-between text-foreground-menu text-sm"> + <span>{source.type}</span> + + {source.numChunks > 1 && ( + <span>{source.numChunks} chunks</span> + )} + </div> + <div className="text-base">{source.title}</div> + <div className="text-xs"> + {source.content.length > 100 + ? source.content.slice(0, 100) + "..." + : source.content} </div> - <div>{source.title}</div> - </div> + </Link> ))} </AccordionContent> </AccordionItem> diff --git a/apps/web/app/actions/doers.ts b/apps/web/app/actions/doers.ts index 3aac1f5a..f94ed8ec 100644 --- a/apps/web/app/actions/doers.ts +++ b/apps/web/app/actions/doers.ts @@ -171,6 +171,7 @@ export const createMemory = async (input: { // TODO: now, in the vector store, we are only saving the first space. We need to save all spaces. space: storeToSpaces[0], user: data.user.id, + type, }), headers: { "Content-Type": "application/json", |