diff options
| author | Dhravya Shah <[email protected]> | 2024-08-03 16:09:39 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-08-03 16:09:39 -0700 |
| commit | e30e9f4e0bb5a11786495445f548d40f3d08f70a (patch) | |
| tree | 586434698406d4aa343ce75b31bfdc1e2632abeb /apps | |
| parent | handle errors properly (diff) | |
| download | supermemory-e30e9f4e0bb5a11786495445f548d40f3d08f70a.tar.xz supermemory-e30e9f4e0bb5a11786495445f548d40f3d08f70a.zip | |
fix: stuff
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/cf-ai-backend/src/helper.ts | 3 | ||||
| -rw-r--r-- | apps/cf-ai-backend/src/index.ts | 2 | ||||
| -rw-r--r-- | apps/cf-ai-backend/src/utils/chunkTweet.ts | 18 | ||||
| -rw-r--r-- | apps/web/app/api/store/route.ts | 39 | ||||
| -rw-r--r-- | apps/web/package.json | 1 |
5 files changed, 49 insertions, 14 deletions
diff --git a/apps/cf-ai-backend/src/helper.ts b/apps/cf-ai-backend/src/helper.ts index 2a68879a..54848442 100644 --- a/apps/cf-ai-backend/src/helper.ts +++ b/apps/cf-ai-backend/src/helper.ts @@ -163,6 +163,7 @@ export async function batchCreateChunksAndEmbeddings({ vectors.push(...batchVectors); } console.log( + "vector Id list: ", vectors.map((vector) => { return vector.id; }), @@ -187,7 +188,7 @@ export async function batchCreateChunksAndEmbeddings({ const results = []; for (let i = 0; i < newVectors.length; i += 20) { results.push(newVectors.slice(i, i + 20)); - console.log(JSON.stringify(newVectors[1].id)); + console.log(newVectors); } await Promise.all( diff --git a/apps/cf-ai-backend/src/index.ts b/apps/cf-ai-backend/src/index.ts index 629ff172..6b900582 100644 --- a/apps/cf-ai-backend/src/index.ts +++ b/apps/cf-ai-backend/src/index.ts @@ -93,6 +93,8 @@ app.post("/api/add", zValidator("json", vectorObj), async (c) => { break; } + console.log("Chunks are here:", chunks); + await batchCreateChunksAndEmbeddings({ store, body, diff --git a/apps/cf-ai-backend/src/utils/chunkTweet.ts b/apps/cf-ai-backend/src/utils/chunkTweet.ts index 78f0f261..d9c59f24 100644 --- a/apps/cf-ai-backend/src/utils/chunkTweet.ts +++ b/apps/cf-ai-backend/src/utils/chunkTweet.ts @@ -22,10 +22,18 @@ export interface ThreadTweetData { } export function chunkThread(threadText: string): TweetChunks { - const thread = JSON.parse(threadText); - if (typeof thread == "string") { - console.log("DA WORKER FAILED DO SOMEHTING FIX DA WROKER"); + let thread = threadText; + + try { + thread = JSON.parse(threadText); + } catch (e) { + console.log("error: thread is not json.", e); + } + + if (typeof threadText == "string") { + console.log("DA WORKER FAILED DO SOMEHTING FIX DA WROKER", thread); const rawTweet = getRawTweet(thread); + console.log(rawTweet); const parsedTweet: any = JSON.parse(rawTweet); const chunkedTweet = chunkText(parsedTweet.text, 1536); @@ -46,8 +54,8 @@ export function chunkThread(threadText: string): TweetChunks { return { type: "tweet", chunks }; } else { - console.log(JSON.stringify(thread)); - const chunkedTweets = thread.map((tweet: Tweet) => { + console.log("thread in else statement", JSON.stringify(thread)); + const chunkedTweets = (thread as any).map((tweet: Tweet) => { const chunkedTweet = chunkText(tweet.text, 1536); const metadata = { diff --git a/apps/web/app/api/store/route.ts b/apps/web/app/api/store/route.ts index 6efbab8f..ad81c7c4 100644 --- a/apps/web/app/api/store/route.ts +++ b/apps/web/app/api/store/route.ts @@ -2,6 +2,7 @@ import { type NextRequest } from "next/server"; import { addFromAPIType } from "@repo/shared-types"; import { ensureAuth } from "../ensureAuth"; import { createMemoryFromAPI } from "./helper"; +import { getRawTweet } from "@repo/shared-types/utils"; export const runtime = "edge"; @@ -22,14 +23,36 @@ export async function POST(req: NextRequest) { body = await req.json(); } catch (e) { const error = (e as Error).message; - return new Response( - JSON.stringify({ - message: "A JSON was not sent to the API. " + error, - }), - { - status: 400, - }, - ); + + console.log(error); + + const tryJson = getRawTweet(await req.text()); + console.log(tryJson); + + if (tryJson) { + try { + body = JSON.parse(tryJson); + } catch (e) { + console.log(e); + return new Response( + JSON.stringify({ + message: "Raw found but not json?" + error, + }), + { + status: 400, + }, + ); + } + } else { + return new Response( + JSON.stringify({ + message: "Raw not found & not json." + error, + }), + { + status: 400, + }, + ); + } } const validated = addFromAPIType.safeParse(body); diff --git a/apps/web/package.json b/apps/web/package.json index 98016d8c..5773fe39 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -21,6 +21,7 @@ "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-slot": "^1.1.0", "@sentry/nextjs": "^8", + "ai": "^3.3.0", "clsx": "^2.1.1", "cmdk": "^1.0.0", "drizzle-orm": "0.30.0", |