feat: add multi-provider AI support (Groq, OpenAI, Anthropic, Google)#35
Draft
dhairyashiil wants to merge 1 commit intomainfrom
Draft
feat: add multi-provider AI support (Groq, OpenAI, Anthropic, Google)#35dhairyashiil wants to merge 1 commit intomainfrom
dhairyashiil wants to merge 1 commit intomainfrom
Conversation
Replace the hardcoded Groq provider with a dynamic, env-driven provider selector supporting Groq, OpenAI, Anthropic, and Google Gemini, controlled by AI_PROVIDER and AI_MODEL env vars. - Rewrite lib/ai-provider.ts with provider registry and getModel() switch - Install @ai-sdk/anthropic and @ai-sdk/google packages - Generalize error helpers in lib/agent.ts for all providers - Add AI_PROVIDER validation in lib/env.ts - Update .env.example and README.md documentation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Deployment failed with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
Contributor
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/chat/lib/agent.ts">
<violation number="1" location="apps/chat/lib/agent.ts:888">
P2: Treating any 429 as an AI token limit can misclassify unrelated 429 errors and return an incorrect user message.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| (err as { statusCode?: number }).statusCode === 429 || | ||
| (cause as { statusCode?: number } | undefined)?.statusCode === 429; | ||
| return hasRateLimit || (status429 && (msg.includes("retry") || causeMsg.includes("retry"))); | ||
| return hasRateLimit || status429; |
Contributor
There was a problem hiding this comment.
P2: Treating any 429 as an AI token limit can misclassify unrelated 429 errors and return an incorrect user message.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/chat/lib/agent.ts, line 888:
<comment>Treating any 429 as an AI token limit can misclassify unrelated 429 errors and return an incorrect user message.</comment>
<file context>
@@ -858,30 +858,34 @@ export function isAIToolCallError(err: unknown): boolean {
(err as { statusCode?: number }).statusCode === 429 ||
(cause as { statusCode?: number } | undefined)?.statusCode === 429;
- return hasRateLimit || (status429 && (msg.includes("retry") || causeMsg.includes("retry")));
+ return hasRateLimit || status429;
}
</file context>
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.
feat: add multi-provider AI support (Groq, OpenAI, Anthropic, Google)
Summary
Replaces the hardcoded Groq provider in
apps/chatwith a dynamic, env-driven provider selector. Two env vars now control AI behavior:AI_PROVIDER—groq|openai|anthropic|google(default:groq)AI_MODEL— optional model override (each provider has a sensible default)The Vercel AI SDK's provider-agnostic
LanguageModelinterface means onlylib/ai-provider.tsneeds to know which provider is active — the rest of the codebase (streamText, tools, etc.) is unchanged.Files changed (6):
apps/chat/package.json@ai-sdk/anthropic,@ai-sdk/googleapps/chat/lib/ai-provider.tsPROVIDER_CONFIGregistry +getModel()exhaustive switchapps/chat/lib/agent.tsisAIToolCallError/isAIRateLimitErrorfor all providersapps/chat/lib/env.tsAI_PROVIDERvalue and that the selected provider's API key is presentapps/chat/.env.exampleapps/chat/README.mdReview & Testing Checklist for Human
openai/gpt-oss-120b→llama-3.3-70b-versatile. Verify this is the intended default for existing deployments, or whether existing deploys should setAI_MODEL=openai/gpt-oss-120bexplicitly."function_call"pattern inisAIToolCallError: This substring is fairly generic. Confirm it won't false-positive on non-error messages that mention "function_call" in passing.isAIRateLimitErrornow returnstruefor any 429 status code, whereas previously it also required "retry" in the error message. Verify this won't cause unintended error handling behavior.AI_PROVIDER=openaiwith a real API key) to confirm end-to-end streaming works through the agent.^ranges (^3.0.58,^3.0.43) while existing@ai-sdk/groqand@ai-sdk/openaiare pinned exactly. Confirm this inconsistency is acceptable.Notes
bun run typecheck:chat). Pre-existing biome lint errors inpackages/cli/are unrelated to this PR.