diff --git a/apps/chat-with-pdf/app/api/chat/route.ts b/apps/chat-with-pdf/app/api/chat/route.ts index 701747b..a3297a9 100644 --- a/apps/chat-with-pdf/app/api/chat/route.ts +++ b/apps/chat-with-pdf/app/api/chat/route.ts @@ -77,12 +77,12 @@ export async function POST(req: Request) { const data = new StreamData(); data.append(messageData); - const result = await streamText({ + const result = streamText({ model: google("gemini-1.5-flash-latest"), messages: convertToCoreMessages(messages), system: systemInstructions, maxTokens: 3000, - onFinish({ text, toolCalls, toolResults, usage, finishReason }) { + onFinish({ text, toolCalls, toolResults, usage, finishReason, ...rest }) { console.log({ onFinish: { text, @@ -90,6 +90,7 @@ export async function POST(req: Request) { toolResults, usage, finishReason, + ...rest, }, }); data.close(); diff --git a/apps/chat-with-pdf/lib/supabase/queries/get-chat.ts b/apps/chat-with-pdf/lib/supabase/queries/get-chat.ts index a244111..eecdcb0 100644 --- a/apps/chat-with-pdf/lib/supabase/queries/get-chat.ts +++ b/apps/chat-with-pdf/lib/supabase/queries/get-chat.ts @@ -57,7 +57,6 @@ export async function getChat(id: string) { }, )(supabase); - console.log({ chat, id }); if (!chat?.suggestedQuestions) { const suggestedQuestions = await generateAndUpdateSuggestedQuestions( supabase, diff --git a/apps/chat-with-pdf/package.json b/apps/chat-with-pdf/package.json index 2371312..69fb49a 100644 --- a/apps/chat-with-pdf/package.json +++ b/apps/chat-with-pdf/package.json @@ -9,7 +9,10 @@ "lint": "next lint" }, "dependencies": { - "@ai-sdk/anthropic": "0.0.50", + "@ai-sdk/anthropic": "1.0.0", + "@ai-sdk/google": "1.0.0", + "@ai-sdk/openai": "1.0.0", + "ai": "4.0.0", "@makefy/ui": "workspace:*", "@makefy/supabase": "workspace:*", "@react-email/components": "0.0.25", @@ -38,8 +41,6 @@ "usehooks-ts": "3.1.0" }, "devDependencies": { - "@ai-sdk/google": "0.0.48", - "@ai-sdk/openai": "0.0.13", "@google/generative-ai": "0.14.1", "@langchain/community": "0.2.16", "@langchain/core": "0.2.15", @@ -53,7 +54,6 @@ "@types/node": "20", "@types/react": "18.2.61", "@types/react-dom": "18.2.19", - "ai": "3.4.30", "autoprefixer": "10.4.20", "dotenv-cli": "7.4.2", "js-md5": "0.8.3", diff --git a/apps/chat-with-pdf/utils/context.ts b/apps/chat-with-pdf/utils/context.ts index 3639042..35f196a 100644 --- a/apps/chat-with-pdf/utils/context.ts +++ b/apps/chat-with-pdf/utils/context.ts @@ -11,7 +11,9 @@ export async function getContext(query: string, documentId: string) { const { data: documentSections, error } = await supabase.rpc( "match_documents", { - query_embedding: userQueryEmbeddings.toString(), + query_embedding: Array.isArray(userQueryEmbeddings) + ? JSON.stringify(userQueryEmbeddings) + : JSON.stringify([userQueryEmbeddings]), match_threshold: 0.7, match_count: 200, document_id: documentId, diff --git a/bun.lockb b/bun.lockb index a78d4fd..8871e8c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/supabase/src/supabase/migrations/20241109155454_auto-remove-document-file.sql b/packages/supabase/src/supabase/migrations/20241109155454_auto-remove-document-file.sql index 9c868f5..f5abedb 100644 --- a/packages/supabase/src/supabase/migrations/20241109155454_auto-remove-document-file.sql +++ b/packages/supabase/src/supabase/migrations/20241109155454_auto-remove-document-file.sql @@ -35,4 +35,7 @@ AS $function$BEGIN END;$function$ ; +CREATE TRIGGER remove_document_file_after_chat_delete +AFTER DELETE ON public."Chat" FOR EACH ROW +EXECUTE FUNCTION public.remove_document_file_after_removing_chats ();