aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-06-16 12:25:36 -0500
committerDhravya <[email protected]>2024-06-16 12:25:36 -0500
commita9f5ebc9e41eb2963d4307d6fc21878c71f340f9 (patch)
tree94962f3a9d02d710af3c3a0d8ae549fba770c9be /apps
parentproper URLs (diff)
downloadsupermemory-a9f5ebc9e41eb2963d4307d6fc21878c71f340f9.tar.xz
supermemory-a9f5ebc9e41eb2963d4307d6fc21878c71f340f9.zip
include metadata in response, add type to metadata
Diffstat (limited to 'apps')
-rw-r--r--apps/cf-ai-backend/src/helper.ts1
-rw-r--r--apps/cf-ai-backend/src/index.ts4
-rw-r--r--apps/cf-ai-backend/src/types.ts1
-rw-r--r--apps/web/app/(dash)/chat/chatWindow.tsx20
4 files changed, 24 insertions, 2 deletions
diff --git a/apps/cf-ai-backend/src/helper.ts b/apps/cf-ai-backend/src/helper.ts
index e0638ca6..5d01c881 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({
space: body.space ?? "",
url: body.url,
user: body.user,
+ type: body.type ?? "page",
},
},
],
diff --git a/apps/cf-ai-backend/src/index.ts b/apps/cf-ai-backend/src/index.ts
index 36dc6750..7d3f69e6 100644
--- a/apps/cf-ai-backend/src/index.ts
+++ b/apps/cf-ai-backend/src/index.ts
@@ -180,7 +180,9 @@ app.post(
idsAsStrings.map(async (id) => await c.env.KV.get(id)),
);
- return c.json({ ids: storedContent });
+ const metadata = normalizedData.map((datapoint) => datapoint.metadata);
+
+ return c.json({ ids: storedContent, metadata });
}
const preparedContext = normalizedData.map(
diff --git a/apps/cf-ai-backend/src/types.ts b/apps/cf-ai-backend/src/types.ts
index bea4bf80..ca68d9ee 100644
--- a/apps/cf-ai-backend/src/types.ts
+++ b/apps/cf-ai-backend/src/types.ts
@@ -46,4 +46,5 @@ export const vectorObj = z.object({
space: z.string().optional(),
url: z.string(),
user: z.string(),
+ type: z.string().optional(),
});
diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx
index 2473de04..8956ba9b 100644
--- a/apps/web/app/(dash)/chat/chatWindow.tsx
+++ b/apps/web/app/(dash)/chat/chatWindow.tsx
@@ -20,6 +20,8 @@ import rehypeKatex from "rehype-katex";
import rehypeHighlight from "rehype-highlight";
import { code, p } from "./markdownRenderHelpers";
import { codeLanguageSubset } from "@/lib/constants";
+import { z } from "zod";
+import { toast } from "sonner";
function ChatWindow({
q,
@@ -56,7 +58,23 @@ function ChatWindow({
// TODO: handle this properly
const sources = await sourcesFetch.json();
- console.log(sources);
+
+ const sourcesZod = z.object({
+ ids: z.array(z.string()),
+ metadata: z.array(z.any()),
+ });
+
+ const sourcesParsed = sourcesZod.safeParse(sources);
+
+ if (!sourcesParsed.success) {
+ console.log(sources);
+ console.error(sourcesParsed.error);
+ toast.error("Something went wrong while getting the sources");
+ return;
+ }
+
+ console.log(sourcesParsed.data.ids);
+ console.log(sourcesParsed.data.metadata);
const resp = await fetch(`/api/chat?q=${query}&spaces=${spaces}`, {
method: "POST",