uncomment

This commit is contained in:
Dhravya Shah 2024-08-06 11:51:54 -07:00
parent bc6fdf3517
commit e652d3a10e
4 changed files with 52 additions and 22 deletions

View file

@ -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({

View file

@ -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);

View file

@ -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 {

View file

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