Refactor Ask Anything Page to use AI SDK#130
Open
riazosama wants to merge 2 commits into
Open
Conversation
|
Static Code Review 📊 ✅ All quality checks passed! |
| } from 'ai' | ||
| import { Document } from 'langchain/document' | ||
| import { formatDocumentsAsString } from 'langchain/util/document' | ||
| import { z } from 'zod' |
Comment on lines
+65
to
+71
| const openAIApiKey = apiKey || process.env.RIPESEED_OPENAI_API_KEY! | ||
|
|
||
| // Get the last user message | ||
| const lastMessage = messages[messages.length - 1] | ||
| const userQuery = | ||
| lastMessage.parts.find((part) => part.type === 'text')?.text || '' | ||
|
|
There was a problem hiding this comment.
logic: Missing input validation for API key and messages array can crash the server. Add checks to handle missing or invalid inputs.
Suggested change
| const openAIApiKey = apiKey || process.env.RIPESEED_OPENAI_API_KEY! | |
| // Get the last user message | |
| const lastMessage = messages[messages.length - 1] | |
| const userQuery = | |
| lastMessage.parts.find((part) => part.type === 'text')?.text || '' | |
| const openAIApiKey = apiKey || process.env.RIPESEED_OPENAI_API_KEY | |
| if (!openAIApiKey) { | |
| return new Response('Missing API key', { status: 400 }) | |
| } | |
| if (!messages || messages.length === 0) { | |
| return new Response('Empty message history', { status: 400 }) | |
| } | |
| // Get the last user message | |
| const lastMessage = messages[messages.length - 1] | |
| const userQuery = | |
| lastMessage.parts.find((part) => part.type === 'text')?.text || '' |
| href={href} | ||
| target="_blank" | ||
| className="group flex list-none items-center justify-between transition duration-300" | ||
| target='_blank' |
There was a problem hiding this comment.
security: Links with target='_blank' are missing rel='noopener noreferrer'. This can lead to security vulnerabilities.
Suggested change
| target='_blank' | |
| target='_blank' rel='noopener noreferrer' |
…tion or class' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary by Typo
Overview
This PR refactors the "Ask Anything" chat page to utilize the Vercel AI SDK, enhancing its capabilities by integrating multiple AI models and enabling Retrieval Augmented Generation (RAG) with document context.
Key Changes
useChatMessagesWithDocshook to centralize chat message management, IndexedDB persistence, and AI SDK integration for document-aware chats./api/chat/send-messageendpoint to leverage the AI SDK'sstreamTextfunction, adding support for OpenAI, Deepseek, and XAI models, and integrating Pinecone for RAG.ChatMessagescomponent by delegating chat logic to the newuseChatMessagesWithDocshook and utilizing a newMessageListcomponent for rendering.Work Breakdown
To turn off PR summary, please visit Notification settings.