Skip to content

Conversation

@codeunia-dev
Copy link
Owner

@codeunia-dev codeunia-dev commented Nov 26, 2025

This PR enhances the AI assistant by giving it access to the user’s profile information—specifically their name—allowing the AI to generate more personalized responses and correctly answer queries like “What is my name?”.

This creates a more human, contextual, and engaging experience for users.


✅ Changes Included

1. Updated ContextData Interface

Added a new field:

userProfile?: {
  first_name: string | null
  last_name: string | null
}

This allows the rest of the AI pipeline to access the user's name when available.


2. Enhanced getContextualData

  • Now accepts userId as an argument.
  • Fetches the user’s profile from the profiles table.
  • Injects the profile information into the returned context.

This ensures the AI always receives up-to-date identity data when constructing prompts.


3. Improved buildPrompt Function

Added logic for:

  • Extracting the user’s full name from contextData.userProfile

  • Injecting the name into the system prompt for more personal responses

  • Handling special queries such as “what is my name”

    • If profile exists → returns “Your name is X!”
    • If no profile data → returns a polite fallback

The system prompt is now capable of:

  • Personalized greetings
  • User-awareness
  • More contextual conversation flow

4. Updated POST Handler

  • Passed userId into getContextualData so profile fetching is always triggered.
  • Ensures both streaming and non-streaming modes have consistent personalized behavior.

🧪 Testing Checklist

Functional Tests

  • Ask: “What is my name?”
    ✔️ Should return the user’s actual name
  • Start chat with: “Hi”
    ✔️ Should greet the user using their name
  • Ask any question
    ✔️ Responses should feel more personal
  • Try with a user who has no profile
    ✔️ AI should gracefully fallback (“I don’t have your name yet”)

Regression

  • No change to existing DB write logic
  • No change to existing prompt context except adding user name
  • Non-personal queries behave exactly as before

🔍 Notes

This update does not affect authorization, permissions, or schema.
It only enriches the AI’s context so it behaves more like a personal assistant.


🤖💬 Final Funny Note

Now that the AI knows your name, just don’t ask it to remember your birthday—
it already has enough existential crises without adding aging to the list. 😄


Authored by: @akshay0611

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced personalization: The AI now uses your name in greetings, responses, and guidance throughout conversations.
    • The system can identify and respond to questions about your identity when asked.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Nov 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
codeunia Building Building Preview Comment Nov 26, 2025 10:16am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The change adds user profile personalization to the AI route handler. It extends ContextData with user profile information, modifies getContextualData to accept an optional userId and fetch user details from the database, and integrates the user's name throughout prompt generation and response logic.

Changes

Cohort / File(s) Summary
User Profile Integration
app/api/ai/route.ts
Added userProfile field to ContextData interface; extended getContextualData function signature to accept optional userId parameter; implemented user profile fetching from profiles table; updated POST handler to pass userId to getContextualData
Prompt Personalization
app/api/ai/route.ts
Integrated user name into prompt construction; personalized greetings, general overviews, and internship-related messages with user's first and last name; added explicit handling for name-related queries with fallback for unavailable profiles; updated action-detection and response prompts for both streaming and non-streaming modes

Sequence Diagram

sequenceDiagram
    participant Client
    participant POST Handler
    participant getContextualData
    participant Database
    participant Prompt Logic
    
    Client->>POST Handler: POST /api/ai (with userId)
    POST Handler->>getContextualData: Call with userId
    getContextualData->>Database: Query user profile
    Database-->>getContextualData: Return user profile
    getContextualData-->>POST Handler: Return ContextData with userProfile
    POST Handler->>Prompt Logic: Generate prompts with userProfile
    Prompt Logic->>Prompt Logic: Inject user name into prompts
    Prompt Logic-->>POST Handler: Return personalized prompts
    POST Handler-->>Client: Send AI response with personalization
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Areas requiring attention:
    • Verification that user profile fetch handles missing/null profiles gracefully
    • All prompt personalization locations to ensure consistent name injection
    • Edge cases for name-related queries ("what is my name?")
    • Proper integration of userId propagation through the POST handler
    • Stream and non-stream response paths both account for personalization

Poem

🐰 A name makes AI truly shine bright,
User profiles fetched, personalization's right!
No more generic greetings, just "Hello there, friend!"
With first name and last, the warmth never ends. ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/unio

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7bac7f and 7a49f13.

📒 Files selected for processing (1)
  • app/api/ai/route.ts (8 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeunia-dev codeunia-dev merged commit 970d292 into main Nov 26, 2025
2 of 4 checks passed
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.

3 participants