fix: stuff

This commit is contained in:
Dhravya Shah 2024-08-03 16:09:39 -07:00
parent 626ca898e4
commit e30e9f4e0b
6 changed files with 7727 additions and 15754 deletions

View file

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

View file

@ -93,6 +93,8 @@ app.post("/api/add", zValidator("json", vectorObj), async (c) => {
break;
}
console.log("Chunks are here:", chunks);
await batchCreateChunksAndEmbeddings({
store,
body,

View file

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

View file

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

View file

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

23418
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff