Skip to content

feat: add Groq support as alternative LLM provider #19

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here
# AI Model Configuration
MODEL_PROVIDER=openai # Options: 'openai' or 'groq'
OPENAI_API_KEY= # Required if MODEL_PROVIDER=openai
GROQ_API_KEY= # Required if MODEL_PROVIDER=groq

# Browserbase Configuration
BROWSERBASE_API_KEY=your_browserbase_api_key_here
BROWSERBASE_PROJECT_ID=your_browserbase_project_id_here
BROWSERBASE_API_KEY=
BROWSERBASE_PROJECT_ID=
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ You'll need to set up your API keys:

Update `.env.local` with your API keys:

- `OPENAI_API_KEY`: Your OpenAI API key
- `MODEL_PROVIDER`: Choose between 'openai' or 'groq' for the AI model provider
- `OPENAI_API_KEY`: Your OpenAI API key (required if using OpenAI)
- `GROQ_API_KEY`: Your Groq API key (required if using Groq)
- `BROWSERBASE_API_KEY`: Your Browserbase API key
- `BROWSERBASE_PROJECT_ID`: Your Browserbase project ID

Expand Down
19 changes: 18 additions & 1 deletion app/api/agent/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { NextResponse } from 'next/server';
import { openai } from "@ai-sdk/openai";
import { groq } from "@ai-sdk/groq";
import { CoreMessage, generateObject, UserContent } from "ai";
import { z } from "zod";
import { ObserveResult, Stagehand } from "@browserbasehq/stagehand";

const LLMClient = openai("gpt-4o");
// Model configuration
const MODEL_PROVIDER = process.env.MODEL_PROVIDER || 'openai';
const MODEL_CONFIG = {
openai: {
provider: openai,
model: "gpt-4o"
},
groq: {
provider: groq,
model: "deepseek-r1-distill-llama-70b"
}
};

// Initialize LLM client based on provider
const LLMClient = MODEL_CONFIG[MODEL_PROVIDER as keyof typeof MODEL_CONFIG].provider(
MODEL_CONFIG[MODEL_PROVIDER as keyof typeof MODEL_CONFIG].model
);

type Step = {
text: string;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@ai-sdk/openai": "^1.1.2",
"@ai-sdk/groq": "^1.0.0",
"@ai-sdk/provider": "^1.0.6",
"@browserbasehq/sdk": "^2.0.0",
"@browserbasehq/stagehand": "^1.10.1",
Expand Down
13 changes: 13 additions & 0 deletions types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
MODEL_PROVIDER: 'openai' | 'groq';
OPENAI_API_KEY?: string;
GROQ_API_KEY?: string;
BROWSERBASE_API_KEY: string;
BROWSERBASE_PROJECT_ID: string;
}
}
}

export {};