diff options
| author | Dhravya Shah <[email protected]> | 2024-08-06 11:51:54 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-08-06 11:51:54 -0700 |
| commit | e652d3a10e0d0a0733a97bc96891361a8a64a007 (patch) | |
| tree | 21dd173f53e4b8e747dd78175e11784a1400dac4 | |
| parent | make use of the promise-based thingy we're doing (diff) | |
| download | supermemory-e652d3a10e0d0a0733a97bc96891361a8a64a007.tar.xz supermemory-e652d3a10e0d0a0733a97bc96891361a8a64a007.zip | |
uncomment
| -rw-r--r-- | apps/cf-ai-backend/src/index.ts | 30 | ||||
| -rw-r--r-- | apps/cf-ai-backend/src/queueConsumer/index.ts | 36 | ||||
| -rw-r--r-- | apps/cf-ai-backend/src/types.ts | 3 | ||||
| -rw-r--r-- | apps/web/app/(dash)/dialogContentContainer.tsx | 5 |
4 files changed, 52 insertions, 22 deletions
diff --git a/apps/cf-ai-backend/src/index.ts b/apps/cf-ai-backend/src/index.ts index 1f391359..5957eb04 100644 --- a/apps/cf-ai-backend/src/index.ts +++ b/apps/cf-ai-backend/src/index.ts @@ -631,6 +631,31 @@ app.post( } //Serach mem0 + type Mem0Response = { + id: string; + memory: string; + user_id: string; + hash: string; + metadata: any; + categories: any; + created_at: string; + updated_at: string; + }; + const mem0Response = await fetch( + "https://api.mem0.ai/v1/memories/?user_id=" + query.user, + { + method: "GET", + headers: { + Authorization: `Token ${c.env.MEM0_API_KEY}`, + }, + }, + ); + const contextFromMem0 = await mem0Response.text(); + const contextJson: Mem0Response[] = await JSON.parse(contextFromMem0); + const memories = contextJson.map((item) => { + return item.memory; + }); + console.log("Here are the mem0 memories", memories); const preparedContext = body.sources.normalizedData.map( ({ metadata, score, normalizedScore }) => ({ @@ -642,7 +667,10 @@ app.post( const initialMessages: CoreMessage[] = [ { role: "user", content: systemPrompt }, - { role: "assistant", content: "Hello, how can I help?" }, // prase and add memory json here + { + role: "assistant", + content: `Here is the profile of the user, refer this whenever possible ${memories.join(", ")}}`, + }, // prase and add memory json here ]; const prompt = template({ diff --git a/apps/cf-ai-backend/src/queueConsumer/index.ts b/apps/cf-ai-backend/src/queueConsumer/index.ts index 393f1fbf..761aeb56 100644 --- a/apps/cf-ai-backend/src/queueConsumer/index.ts +++ b/apps/cf-ai-backend/src/queueConsumer/index.ts @@ -202,22 +202,26 @@ export async function queue( //add to mem0, abstract - // const mem0Response = fetch('https://api.mem0.ai/v1/memories/', { - // method: 'POST', - // headers: { - // 'Content-Type': 'application/json', - // Authorization: `Token ${process.env.MEM0_API_KEY}`, - // }, - // body: JSON.stringify({ - // messages: [ - // { - // role: 'user', - // content: query, - // }, - // ], - // user_id: user?.user?.email, - // }), - // }); + const mem0Response = fetch("https://api.mem0.ai/v1/memories/", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Token ${env.MEM0_API_KEY}`, + }, + body: JSON.stringify({ + messages: [ + { + role: "system", + content: `Extract information about the user based on this saved content provided, remember that the date was ${new Date().toUTCString()} in utc time zone`, + }, + { + role: "user", + content: pageContent, + }, + ], + user_id: body.user, + }), + }); // see what's up with the storedToSpaces in this block const { store } = await initQuery(env); diff --git a/apps/cf-ai-backend/src/types.ts b/apps/cf-ai-backend/src/types.ts index e4f13f1b..dd1b477a 100644 --- a/apps/cf-ai-backend/src/types.ts +++ b/apps/cf-ai-backend/src/types.ts @@ -22,13 +22,14 @@ export type Env = { THREAD_CF_WORKER: string; NODE_ENV: string; MD_SEC_KEY: string; + MEM0_API_KEY: string; }; export interface JobData { content: string; space: Array<number>; user: string; - type: string + type: string; } export interface TweetData { diff --git a/apps/web/app/(dash)/dialogContentContainer.tsx b/apps/web/app/(dash)/dialogContentContainer.tsx index f856427f..0b2b615c 100644 --- a/apps/web/app/(dash)/dialogContentContainer.tsx +++ b/apps/web/app/(dash)/dialogContentContainer.tsx @@ -174,10 +174,7 @@ export function DialogContentContainer({ ]); setSelectedSpaces((prev) => [...prev, creationTask.data!]); } else { - toast.error( - "Space creation failed: " + creationTask.error ?? - "Unknown error", - ); + toast.error("Space creation failed: " + creationTask.error); } }} placeholder="Select or create a new space." |