Skip to content

Switch to Groq LLM and fix AI sidebar focus#1192

Merged
MrgSub merged 1 commit intostagingfrom
06-03-cleanup_adding_groq
Jun 4, 2025
Merged

Switch to Groq LLM and fix AI sidebar focus#1192
MrgSub merged 1 commit intostagingfrom
06-03-cleanup_adding_groq

Conversation

@MrgSub
Copy link
Collaborator

@MrgSub MrgSub commented Jun 3, 2025

Switch to Groq LLM and Improve AI Sidebar Focus

This PR switches the AI model from OpenAI's GPT-4o to Groq's Llama-4-Maverick for both the ZeroAgent and search query generation. It also improves the AI sidebar UX by automatically focusing the editor when the sidebar is opened.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • ⚡ Performance improvement

Areas Affected

  • User Interface/Experience
  • API Endpoints

Testing Done

  • Manual testing performed

Checklist

  • I have performed a self-review of my code
  • My changes generate no new warnings

Additional Notes

The PR includes:

  1. Adding Groq SDK dependency
  2. Switching from OpenAI to Groq LLM models
  3. Adding auto-focus to the AI sidebar editor when opened
  4. Cleaning up unused code in mail components
  5. Simplifying the AI sidebar toggle logic

Summary by CodeRabbit

  • New Features

    • The editor in the AI chat sidebar now automatically gains focus when the sidebar is opened.
  • Refactor

    • Simplified the logic and state management for sidebar and bulk selection actions in the mail app.
    • Streamlined sidebar open/close toggling for improved reliability.
  • Chores

    • Switched AI model provider from OpenAI GPT-4o to Groq’s Llama 4 Maverick model for chat and search features.
    • Updated server dependencies to include the new Groq AI SDK.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

This update switches AI-related backend components from using OpenAI's GPT-4o model to Groq's "meta-llama/llama-4-maverick-17b-128e-instruct" model. It also adjusts frontend logic for the AI sidebar and AI chat editor focus, and simplifies bulk selection and error handling in the mail UI.

Changes

File(s) Change Summary
apps/server/package.json Added dependency: @ai-sdk/groq version 1.2.9.
apps/server/src/routes/chat.ts, apps/server/src/trpc/routes/ai/search.ts Switched AI model from OpenAI GPT-4o to Groq's meta-llama/llama-4-maverick-17b-128e-instruct; updated imports.
apps/mail/components/create/ai-chat.tsx Disabled sidebar toggle on thread click; added effect to focus editor when sidebar opens.
apps/mail/components/ui/ai-sidebar.tsx Simplified sidebar open/toggle logic; removed explanatory comments.
apps/mail/components/mail/mail.tsx Removed bulk selection error tracking, mutation hooks, and related callbacks; simplified bulk action logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MailUI
    participant AISidebar
    participant AIChatEditor

    User->>MailUI: Opens AI Sidebar
    MailUI->>AISidebar: Set aiSidebarOpen = true
    AISidebar->>AIChatEditor: useEffect triggers focus if aiSidebarOpen == 'true'
    AIChatEditor->>User: Editor is focused
Loading
sequenceDiagram
    participant Backend
    participant GroqModel

    Backend->>GroqModel: Request completion (streamText or object generation)
    GroqModel-->>Backend: Respond with meta-llama/llama-4-maverick-17b-128e-instruct output
Loading

Possibly related PRs

  • Mail-0/Zero#854: Refactors UI layout and styling in the AI chat component, which is also modified in this PR for sidebar and editor focus logic.

Poem

A bunny hops through code anew,
Swapping models, Groq in view!
The sidebar now is calm and neat,
The editor wakes to greet.
Bulk actions trimmed, the mail feels light—
All is fresh, and all is right!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator Author

MrgSub commented Jun 3, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@MrgSub MrgSub marked this pull request as ready for review June 3, 2025 22:38
@MrgSub MrgSub changed the title Cleanup & Adding Groq Switch to Groq LLM and fix AI sidebar focus Jun 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/server/src/trpc/routes/ai/search.ts (1)

11-11: Model migration implemented correctly.

The migration to Groq's model is clean and consistent in this file.

Consider extracting the model name to a shared constant to avoid duplication across files and make future model changes easier:

+import { GROQ_MODEL } from '../../../lib/constants';

-      model: groq('meta-llama/llama-4-maverick-17b-128e-instruct'),
+      model: groq(GROQ_MODEL),

Create apps/server/src/lib/constants.ts:

export const GROQ_MODEL = 'meta-llama/llama-4-maverick-17b-128e-instruct';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1c0a71 and 0832afe.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • apps/mail/components/create/ai-chat.tsx (3 hunks)
  • apps/mail/components/mail/mail.tsx (0 hunks)
  • apps/mail/components/ui/ai-sidebar.tsx (1 hunks)
  • apps/server/package.json (1 hunks)
  • apps/server/src/routes/chat.ts (2 hunks)
  • apps/server/src/trpc/routes/ai/search.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/mail/components/mail/mail.tsx
🔇 Additional comments (8)
apps/mail/components/ui/ai-sidebar.tsx (1)

312-312: LGTM! Clean refactor of the toggleOpen function.

The simplified one-liner maintains the same functionality while being more concise and readable. The logic correctly toggles the sidebar state by checking if open !== 'true'.

apps/mail/components/create/ai-chat.tsx (4)

29-29: Good decision to prevent sidebar state reset on thread clicks.

Commenting out the setAiSidebarOpen calls prevents the sidebar from closing unexpectedly when users click on threads, which improves the user experience by maintaining the sidebar state.

Also applies to: 34-34


278-278: LGTM! Clean separation of concerns.

Adding a separate aiSidebarOpen state variable for reading the sidebar state is a good approach that separates the concerns of reading vs. setting the sidebar state.


302-306: Excellent UX improvement with automatic editor focus.

The useEffect correctly focuses the editor when the sidebar opens, which improves the user experience by making the chat immediately ready for input. The dependency array is properly configured with both aiSidebarOpen and editor.


1-515: Note: AI summary mentions model switching, but not evident in this file.

The AI summary mentions switching from OpenAI's GPT-4o model to Groq's "meta-llama/llama-4-maverick-17b-128e-instruct" model, but the changes in this file are focused on UI sidebar management and editor focus. The model switching likely occurs in other files not included in this review.

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 354-354: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/server/package.json (1)

23-23:

Details

❓ Verification inconclusive

Dependency addition looks good.

The addition of the Groq SDK dependency aligns with the migration from OpenAI to Groq models in the codebase.

Verify that this package version is secure and compatible:


🏁 Script executed:

#!/bin/bash
# Check for security advisories and latest version info
npm audit @ai-sdk/groq@1.2.9
npm view @ai-sdk/groq versions --json | jq '.[-5:]'

Length of output: 541


🏁 Script executed:

#!/bin/bash
# Generate a lockfile and audit the @ai-sdk/groq dependency
npm install --package-lock-only
npm audit --json | jq '.vulnerabilities["@ai-sdk/groq"]'

Length of output: 1112


🏁 Script executed:

#!/bin/bash
# Verify that version 1.2.9 exists and inspect engine compatibility
npm view @ai-sdk/groq@1.2.9 version engines --json

Length of output: 116


Verify Node requirement and security for @ai-sdk/groq@1.2.9

  • @ai-sdk/groq@1.2.9 requires Node >= 18 – please confirm your runtime meets this.
  • We couldn’t run npm audit in this workspace setup. Before merging, run a full audit in your local environment with a proper lockfile or review the npm advisory database for any known vulnerabilities in 1.2.9.
apps/server/src/routes/chat.ts (1)

27-27: Import addition looks good.

The Groq import is properly added to support the model migration.

apps/server/src/trpc/routes/ai/search.ts (1)

3-4: Import changes look good.

The import updates correctly reflect the migration from OpenAI to Groq SDK.


const result = streamText({
model: openai('gpt-4o'),
model: groq('meta-llama/llama-4-maverick-17b-128e-instruct'),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Model migration implemented correctly, but incomplete.

The migration to Groq's model is implemented correctly in the ZeroAgent class. However, this creates an inconsistent state in the codebase.

This file still has OpenAI model usage at lines 131 and 445 in the buildGmailSearchQuery implementations. Consider:

  1. Complete the migration by updating all remaining OpenAI usages to Groq
  2. Document the rationale if different models should be used for different operations
  3. Extract the model name to a constant to avoid repetition
+const GROQ_MODEL = 'meta-llama/llama-4-maverick-17b-128e-instruct';

-          model: groq('meta-llama/llama-4-maverick-17b-128e-instruct'),
+          model: groq(GROQ_MODEL),

Verify all OpenAI model usages in the codebase to ensure consistent migration:


🏁 Script executed:

#!/bin/bash
# Search for remaining OpenAI model usage patterns
rg -A 2 -B 2 "openai\('.*'\)" apps/server/src/
rg -A 2 -B 2 "gpt-4o" apps/server/src/

Length of output: 2675


Complete Groq Model Migration Across the Codebase

The migration to Groq’s model in ZeroAgent is correct, but there are still OpenAI calls that need updating:

• apps/server/src/trpc/routes/ai/compose.ts
– model: openai('gpt-4o-mini')
– model: openai('gpt-4o')
• apps/server/src/routes/chat.ts
– model: openai('gpt-4o') in both generateText and generateObject calls

Recommendations:

  1. Extract the Groq model name to a constant:
    const GROQ_MODEL = 'meta-llama/llama-4-maverick-17b-128e-instruct';
  2. Replace all openai('…') usages with groq(GROQ_MODEL) (or a variant, if you intentionally need different models, document that).
  3. Add/update a comment in each file explaining why Groq is used instead of OpenAI.

Example diff (adapt for each occurrence):

+ const GROQ_MODEL = 'meta-llama/llama-4-maverick-17b-128e-instruct';

-    model: openai('gpt-4o'),
+    model: groq(GROQ_MODEL),
🤖 Prompt for AI Agents
In apps/server/src/routes/chat.ts at line 61 and also at lines 131 and 445, the
code still uses OpenAI models in the buildGmailSearchQuery implementations,
causing inconsistency after migrating to Groq models. To fix this, extract the
Groq model name 'meta-llama/llama-4-maverick-17b-128e-instruct' into a constant
at the top of the file, replace all openai('gpt-4o') usages with
groq(GROQ_MODEL), and add a comment explaining why Groq is used instead of
OpenAI for clarity and consistency.

Copy link
Collaborator Author

MrgSub commented Jun 4, 2025

Merge activity

  • Jun 4, 9:45 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 4, 9:45 PM UTC: @MrgSub merged this pull request with Graphite.

@MrgSub MrgSub merged commit e2966b9 into staging Jun 4, 2025
3 checks passed
@MrgSub MrgSub deleted the 06-03-cleanup_adding_groq branch June 4, 2025 21:45
@coderabbitai coderabbitai bot mentioned this pull request Jul 29, 2025
34 tasks
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