Skip to content

Refactor Ask Anything Page to use AI SDK#130

Open
riazosama wants to merge 2 commits into
mainfrom
ai-sdk-ask-anything
Open

Refactor Ask Anything Page to use AI SDK#130
riazosama wants to merge 2 commits into
mainfrom
ai-sdk-ask-anything

Conversation

@riazosama
Copy link
Copy Markdown
Contributor

@riazosama riazosama commented Nov 7, 2025

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

  • Introduced a new useChatMessagesWithDocs hook to centralize chat message management, IndexedDB persistence, and AI SDK integration for document-aware chats.
  • Rewrote the /api/chat/send-message endpoint to leverage the AI SDK's streamText function, adding support for OpenAI, Deepseek, and XAI models, and integrating Pinecone for RAG.
  • Simplified the ChatMessages component by delegating chat logic to the new useChatMessagesWithDocs hook and utilizing a new MessageList component for rendering.
  • Removed outdated, custom chat message handling logic and unused imports/variables, streamlining the codebase.

Work Breakdown

Category Lines Changed
New Work 280 (52.7%)
Churn 209 (39.4%)
Rework 42 (7.9%)
Total Changes 531
To turn off PR summary, please visit Notification settings.

@riazosama riazosama marked this pull request as ready for review November 7, 2025 10:04
@typo-app
Copy link
Copy Markdown

typo-app Bot commented Nov 7, 2025

Static Code Review 📊

✅ All quality checks passed!

Comment thread src/app/_components/hooks/useChatMessagesWithDocs.ts Fixed
} from 'ai'
import { Document } from 'langchain/document'
import { formatDocumentsAsString } from 'langchain/util/document'
import { z } from 'zod'
Copy link
Copy Markdown

@typo-app typo-app Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review 🤖

Files Reviewed: 5
Comments Added: 2
Lines of Code Analyzed: 573
Critical Issues: 0

PR Health: Good

Give 👍 or 👎 on each review comment to help us improve.

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 || ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 || ''

Comment thread src/app/page.tsx
href={href}
target="_blank"
className="group flex list-none items-center justify-between transition duration-300"
target='_blank'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant