Merge pull request #231 from supermemoryai/kush/be-queue-fixes

fix spaces; fix incorrect title for memory sources
This commit is contained in:
Dhravya Shah 2024-08-09 09:58:43 -07:00 committed by GitHub
commit 4d9775e66d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 27 deletions

View file

@ -86,23 +86,12 @@ app.post("/api/add", zValidator("json", vectorBody), async (c) => {
"#supermemory-user-" +
body.user;
console.log(
"---------------------------------------------------------------------------------------------------------------------------------------------",
saveToDbUrl,
);
const alreadyExist = await db
.select()
.from(storedContent)
.where(eq(storedContent.baseUrl, saveToDbUrl));
console.log(
"------------------------------------------------",
JSON.stringify(alreadyExist),
);
if (alreadyExist.length > 0) {
console.log(
"------------------------------------------------------------------------------------------------I exist------------------------",
);
return c.json({ status: "error", message: "the content already exists" });
}
@ -129,11 +118,10 @@ app.post("/api/add", zValidator("json", vectorBody), async (c) => {
// unique contraint check
if (isWithinLimit) {
const spaceNumbers = body.spaces.map((s: string) => Number(s));
await c.env.EMBEDCHUNKS_QUEUE.send({
content: body.url,
user: body.user,
space: spaceNumbers,
space: body.spaces,
type: type,
});
} else {
@ -620,7 +608,6 @@ app.post(
);
const metadata = normalizedData.map((datapoint) => datapoint.metadata);
return c.json({
ids: storedContent.filter(Boolean),
metadata,

View file

@ -56,10 +56,8 @@ export async function queue(
env: Env,
): Promise<void> {
const db = database(env);
console.log(env.CF_ACCOUNT_ID, env.CF_KV_AUTH_TOKEN);
for (let message of batch.messages) {
console.log(env.CF_ACCOUNT_ID, env.CF_KV_AUTH_TOKEN);
console.log("is thie even running?", message.body);
const body = message.body;
const type = body.type;
@ -168,9 +166,8 @@ export async function queue(
}
case "tweet": {
console.log("tweet hit");
const tweet = await getTweetData(body.content.split("/").pop());
console.log(env.THREAD_CF_WORKER, env.THREAD_CF_AUTH);
const thread = await getThreadData({
tweetUrl: body.content,
env: env,
@ -180,13 +177,14 @@ export async function queue(
throw tweet.error;
}
pageContent = tweetToMd(tweet.value);
console.log(pageContent);
metadata = {
baseUrl: body.content,
description: tweet.value.text.slice(0, 200),
image: tweet.value.user.profile_image_url_https,
title: `Tweet by ${tweet.value.user.name}`,
};
if (isErr(thread)) {
console.log("Thread worker is down!");
vectorData = JSON.stringify(pageContent);
@ -216,13 +214,12 @@ export async function queue(
},
{
role: "user",
content: pageContent,
content: vectorData.replace(/<raw>.*?<\/raw>/g, ""),
},
],
user_id: body.user,
}),
});
// see what's up with the storedToSpaces in this block
const { store } = await initQuery(env);
@ -235,7 +232,7 @@ export async function queue(
type: type,
url: metadata.baseUrl,
description: metadata.description,
title: metadata.description,
title: metadata.title,
};
try {
@ -268,6 +265,7 @@ export async function queue(
(metadata.baseUrl.split("#supermemory-user-")[0] ?? metadata.baseUrl) +
"#supermemory-user-" +
body.user;
let contentId: number;
const insertResponse = await wrap(
@ -303,9 +301,8 @@ export async function queue(
});
throw insertResponse.error;
}
console.log(JSON.stringify(insertResponse));
contentId = insertResponse[0]?.id || new Date().getTime();
console.log("this is the content Id", contentId);
contentId = insertResponse.value[0].id;
if (storeToSpaces.length > 0) {
// Adding the many-to-many relationship between content and spaces
const spaceData = await wrap(

View file

@ -95,7 +95,7 @@ export const vectorObj = z.object({
type: z.string().optional().default("page"),
});
export const vectorBody = z.object({
spaces: z.array(z.string()).optional(),
spaces: z.array(z.number()).optional(),
url: z.string(),
user: z.string(),
});