mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-06 02:47:54 +00:00
fix sapces; fix incorrect title for memory sources
This commit is contained in:
parent
c526decffc
commit
f7cf59b84d
3 changed files with 14 additions and 27 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -56,10 +56,9 @@ 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 +167,9 @@ 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,16 +179,18 @@ 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}`,
|
||||
};
|
||||
console.log("this is the tweet metadata", metadata.title);
|
||||
if (isErr(thread)) {
|
||||
console.log("Thread worker is down!");
|
||||
vectorData = JSON.stringify(pageContent);
|
||||
console.log(vectorData);
|
||||
console.error(thread.error);
|
||||
} else {
|
||||
console.log("thread worker is fine");
|
||||
|
|
@ -216,13 +217,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 +235,7 @@ export async function queue(
|
|||
type: type,
|
||||
url: metadata.baseUrl,
|
||||
description: metadata.description,
|
||||
title: metadata.description,
|
||||
title: metadata.title,
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
@ -268,6 +268,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 +304,8 @@ export async function queue(
|
|||
});
|
||||
throw insertResponse.error;
|
||||
}
|
||||
console.log(JSON.stringify(insertResponse));
|
||||
contentId = insertResponse[0]?.id;
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue