Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GROQ support #254

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/app/api/user/settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ async function saveAISettings(options: SaveSettingsBody) {
}
// use bedrock if no api key set
return Model.CLAUDE_3_5_SONNET_BEDROCK;
case Provider.GROQ:
return Model.LLAMA_3_70B_GROQ;
0xrushi marked this conversation as resolved.
Show resolved Hide resolved
default:
throw new Error("Invalid AI provider");
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@ai-sdk/amazon-bedrock": "^0.0.30",
"@ai-sdk/anthropic": "^0.0.51",
"@ai-sdk/groq": "^0.0.3",
"@ai-sdk/openai": "^0.0.68",
"@asteasolutions/zod-to-openapi": "^7.2.0",
"@auth/core": "^0.37.2",
Expand Down
27 changes: 25 additions & 2 deletions apps/web/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,27 @@ export function isOpenAIRetryError(error: unknown): boolean {
);
}

// we don't want to capture these errors in Sentry
export function isGroqInvalidApiKeyError(error: APICallError): boolean {
return (
error.message.includes("Invalid API key") ||
error.message.includes("Authentication failed")
);
}

export function isGroqRateLimitError(error: APICallError): boolean {
return (
error.message.includes("Rate limit exceeded") ||
error.message.includes("Too many requests")
);
}

export function isGroqQuotaExceededError(error: APICallError): boolean {
return (
error.message.includes("Quota exceeded") ||
error.message.includes("Usage limit exceeded")
);
}

export function isKnownApiError(error: unknown): boolean {
return (
isGmailInsufficientPermissionsError(error) ||
Expand All @@ -113,6 +133,9 @@ export function isKnownApiError(error: unknown): boolean {
isInvalidOpenAIModelError(error) ||
isOpenAIAPIKeyDeactivatedError(error) ||
isOpenAIRetryError(error) ||
isAnthropicInsufficientBalanceError(error)))
isAnthropicInsufficientBalanceError(error) ||
isGroqInvalidApiKeyError(error) ||
isGroqRateLimitError(error) ||
isGroqQuotaExceededError(error)))
0xrushi marked this conversation as resolved.
Show resolved Hide resolved
);
}
13 changes: 11 additions & 2 deletions apps/web/utils/llms/config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
export const Provider = {
OPEN_AI: "openai",
ANTHROPIC: "anthropic",
};
GROQ: "groq",
} as const;

export const Model = {
GPT_4O: "gpt-4o",
GPT_4O_MINI: "gpt-4o-mini",
CLAUDE_3_5_SONNET_BEDROCK: "anthropic.claude-3-5-sonnet-20241022-v2:0",
CLAUDE_3_5_SONNET_ANTHROPIC: "claude-3-5-sonnet-20241022",
};
LLAMA_3_70B_GROQ: "llama3-groq-70b-8192-tool-use-preview",
} as const;

export const providerOptions = [
{ label: "OpenAI", value: Provider.OPEN_AI },
{ label: "Anthropic", value: Provider.ANTHROPIC },
{ label: "Groq", value: Provider.GROQ },
];

export const modelOptions: Record<string, { label: string; value: string }[]> =
Expand All @@ -27,4 +30,10 @@ export const modelOptions: Record<string, { label: string; value: string }[]> =
value: "claude-3-5-sonnet", // used in ui only. can be either anthropic or bedrock
},
],
[Provider.GROQ]: [
{
label: "Llama 3 70B",
value: Model.LLAMA_3_70B_GROQ,
},
],
};
10 changes: 10 additions & 0 deletions apps/web/utils/llms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "ai";
import { createOpenAI } from "@ai-sdk/openai";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createGroq } from "@ai-sdk/groq";
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
import { env } from "@/env";
import { saveAiUsage } from "@/utils/usage";
Expand Down Expand Up @@ -65,6 +66,15 @@ function getModel({ aiProvider, aiModel, aiApiKey }: UserAIFields) {
};
}

if (provider === Provider.GROQ) {
const model = aiModel || Model.LLAMA_3_70B_GROQ;
return {
provider: Provider.GROQ,
model,
llmModel: createGroq({ apiKey: aiApiKey || env.GROQ_API_KEY })(model),
};
}
0xrushi marked this conversation as resolved.
Show resolved Hide resolved

throw new Error("AI provider not supported");
}

Expand Down
45 changes: 43 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.