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 | |
| parent | added sources to the response (diff) | |
| download | supermemory-76c48ccb600d172f362d7cd237094d6082454825.tar.xz supermemory-76c48ccb600d172f362d7cd237094d6082454825.zip | |
add number of chunks to the respnose and only show unique values
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/cf-ai-backend/src/types.ts | 2 | ||||
| -rw-r--r-- | apps/web/app/(dash)/chat/chatWindow.tsx | 37 | ||||
| -rw-r--r-- | apps/web/app/actions/doers.ts | 1 |
3 files changed, 33 insertions, 7 deletions
diff --git a/apps/cf-ai-backend/src/types.ts b/apps/cf-ai-backend/src/types.ts index 3db62553..5f6d0583 100644 --- a/apps/cf-ai-backend/src/types.ts +++ b/apps/cf-ai-backend/src/types.ts @@ -46,5 +46,5 @@ export const vectorObj = z.object({ space: z.string().optional(), url: z.string(), user: z.string(), - type: z.string().optional(), + type: z.string().optional().default("page"), }); 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", |