Add support for Google Gemini AI

This commit is contained in:
microgod
2025-08-12 04:46:12 +01:00
parent efdef874d7
commit e73fa13b1f
7 changed files with 40 additions and 5 deletions
+3
View File
@@ -13,5 +13,8 @@ ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Get yours at https://platform.openai.com # Get yours at https://platform.openai.com
OPENAI_API_KEY=your_openai_api_key_here OPENAI_API_KEY=your_openai_api_key_here
# Get yours at https://aistudio.google.com/app/apikey
GEMINI_API_KEY=your_gemini_api_key_here
# Get yours at https://console.groq.com # Get yours at https://console.groq.com
GROQ_API_KEY=your_groq_api_key_here GROQ_API_KEY=your_groq_api_key_here
+1
View File
@@ -26,6 +26,7 @@ FIRECRAWL_API_KEY=your_firecrawl_api_key # Get from https://firecrawl.dev (Web
# Optional (need at least one AI provider) # Optional (need at least one AI provider)
ANTHROPIC_API_KEY=your_anthropic_api_key # Get from https://console.anthropic.com ANTHROPIC_API_KEY=your_anthropic_api_key # Get from https://console.anthropic.com
OPENAI_API_KEY=your_openai_api_key # Get from https://platform.openai.com (GPT-5) OPENAI_API_KEY=your_openai_api_key # Get from https://platform.openai.com (GPT-5)
GEMINI_API_KEY=your_gemini_api_key # Get from https://aistudio.google.com/app/apikey
GROQ_API_KEY=your_groq_api_key # Get from https://console.groq.com (Fast inference - Kimi K2 recommended) GROQ_API_KEY=your_groq_api_key # Get from https://console.groq.com (Fast inference - Kimi K2 recommended)
``` ```
+3
View File
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { createGroq } from '@ai-sdk/groq'; import { createGroq } from '@ai-sdk/groq';
import { createAnthropic } from '@ai-sdk/anthropic'; import { createAnthropic } from '@ai-sdk/anthropic';
import { createOpenAI } from '@ai-sdk/openai'; import { createOpenAI } from '@ai-sdk/openai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { generateObject } from 'ai'; import { generateObject } from 'ai';
import { z } from 'zod'; import { z } from 'zod';
import type { FileManifest } from '@/types/file-manifest'; import type { FileManifest } from '@/types/file-manifest';
@@ -102,6 +103,8 @@ export async function POST(request: NextRequest) {
} else { } else {
aiModel = openai(model.replace('openai/', '')); aiModel = openai(model.replace('openai/', ''));
} }
} else if (model.startsWith('google/')) {
aiModel = createGoogleGenerativeAI(model.replace('google/', ''));
} else { } else {
// Default to groq if model format is unclear // Default to groq if model format is unclear
aiModel = groq(model); aiModel = groq(model);
+10 -3
View File
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { createGroq } from '@ai-sdk/groq'; import { createGroq } from '@ai-sdk/groq';
import { createAnthropic } from '@ai-sdk/anthropic'; import { createAnthropic } from '@ai-sdk/anthropic';
import { createOpenAI } from '@ai-sdk/openai'; import { createOpenAI } from '@ai-sdk/openai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { streamText } from 'ai'; import { streamText } from 'ai';
import type { SandboxState } from '@/types/sandbox'; import type { SandboxState } from '@/types/sandbox';
import { selectFilesForEdit, getFileContents, formatFilesForAI } from '@/lib/context-selector'; import { selectFilesForEdit, getFileContents, formatFilesForAI } from '@/lib/context-selector';
@@ -19,6 +20,10 @@ const anthropic = createAnthropic({
baseURL: process.env.ANTHROPIC_BASE_URL || 'https://api.anthropic.com/v1', baseURL: process.env.ANTHROPIC_BASE_URL || 'https://api.anthropic.com/v1',
}); });
const googleGenerativeAI = createGoogleGenerativeAI({
apiKey: process.env.GEMINI_API_KEY,
});
const openai = createOpenAI({ const openai = createOpenAI({
apiKey: process.env.OPENAI_API_KEY, apiKey: process.env.OPENAI_API_KEY,
}); });
@@ -1148,11 +1153,13 @@ CRITICAL: When files are provided in the context:
// Determine which provider to use based on model // Determine which provider to use based on model
const isAnthropic = model.startsWith('anthropic/'); const isAnthropic = model.startsWith('anthropic/');
const isGoogle = model.startsWith('google/');
const isOpenAI = model.startsWith('openai/gpt-5'); const isOpenAI = model.startsWith('openai/gpt-5');
const modelProvider = isAnthropic ? anthropic : (isOpenAI ? openai : groq); const modelProvider = isAnthropic ? anthropic : (isOpenAI ? openai : (isGoogle ? googleGenerativeAI : groq));
const actualModel = isAnthropic ? model.replace('anthropic/', '') : const actualModel = isAnthropic ? model.replace('anthropic/', '') :
(model === 'openai/gpt-5') ? 'gpt-5' : model; (model === 'openai/gpt-5') ? 'gpt-5' :
(isGoogle ? model.replace('google/', '') : model);
// Make streaming API call with appropriate provider // Make streaming API call with appropriate provider
const streamOptions: any = { const streamOptions: any = {
model: modelProvider(actualModel), model: modelProvider(actualModel),
+4 -2
View File
@@ -34,14 +34,16 @@ export const appConfig = {
availableModels: [ availableModels: [
'openai/gpt-5', 'openai/gpt-5',
'moonshotai/kimi-k2-instruct', 'moonshotai/kimi-k2-instruct',
'anthropic/claude-sonnet-4-20250514' 'anthropic/claude-sonnet-4-20250514',
'google/gemini-2.5-pro'
], ],
// Model display names // Model display names
modelDisplayNames: { modelDisplayNames: {
'openai/gpt-5': 'GPT-5', 'openai/gpt-5': 'GPT-5',
'moonshotai/kimi-k2-instruct': 'Kimi K2 Instruct', 'moonshotai/kimi-k2-instruct': 'Kimi K2 Instruct',
'anthropic/claude-sonnet-4-20250514': 'Sonnet 4' 'anthropic/claude-sonnet-4-20250514': 'Sonnet 4',
'google/gemini-2.5-pro': 'Gemini 2.5 Pro'
}, },
// Temperature settings for non-reasoning models // Temperature settings for non-reasoning models
+1
View File
@@ -15,6 +15,7 @@
}, },
"dependencies": { "dependencies": {
"@ai-sdk/anthropic": "^2.0.1", "@ai-sdk/anthropic": "^2.0.1",
"@ai-sdk/google": "^2.0.4",
"@ai-sdk/groq": "^2.0.0", "@ai-sdk/groq": "^2.0.0",
"@ai-sdk/openai": "^2.0.4", "@ai-sdk/openai": "^2.0.4",
"@anthropic-ai/sdk": "^0.57.0", "@anthropic-ai/sdk": "^0.57.0",
+18
View File
@@ -11,6 +11,9 @@ importers:
'@ai-sdk/anthropic': '@ai-sdk/anthropic':
specifier: ^2.0.1 specifier: ^2.0.1
version: 2.0.1(zod@3.25.76) version: 2.0.1(zod@3.25.76)
'@ai-sdk/google':
specifier: ^2.0.4
version: 2.0.4(zod@3.25.76)
'@ai-sdk/groq': '@ai-sdk/groq':
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.3(zod@3.25.76) version: 2.0.3(zod@3.25.76)
@@ -86,6 +89,9 @@ importers:
tailwindcss-animate: tailwindcss-animate:
specifier: ^1.0.7 specifier: ^1.0.7
version: 1.0.7(tailwindcss@4.1.11) version: 1.0.7(tailwindcss@4.1.11)
zod:
specifier: ^3.25.76
version: 3.25.76
devDependencies: devDependencies:
'@eslint/eslintrc': '@eslint/eslintrc':
specifier: ^3 specifier: ^3
@@ -129,6 +135,12 @@ packages:
peerDependencies: peerDependencies:
zod: ^3.25.76 || ^4 zod: ^3.25.76 || ^4
'@ai-sdk/google@2.0.4':
resolution: {integrity: sha512-d8CF3uzabVqxPwcuXLVv5OIq55bM5oKKNNMQacYQMEv3I9W6EYYYeaM9Buo+/yi1IdKsRIPsa9LQO/H9S9x8yQ==}
engines: {node: '>=18'}
peerDependencies:
zod: ^3.25.76 || ^4
'@ai-sdk/groq@2.0.3': '@ai-sdk/groq@2.0.3':
resolution: {integrity: sha512-6U1iXh2P33YFSHcFdmESq7YZ3nHs50YQQZDSumwPFKs+iNKSPqrbfYQi/1lLKDhDtCrCEimYtyT+zMD7NlnCBQ==} resolution: {integrity: sha512-6U1iXh2P33YFSHcFdmESq7YZ3nHs50YQQZDSumwPFKs+iNKSPqrbfYQi/1lLKDhDtCrCEimYtyT+zMD7NlnCBQ==}
engines: {node: '>=18'} engines: {node: '>=18'}
@@ -2523,6 +2535,12 @@ snapshots:
'@ai-sdk/provider-utils': 3.0.1(zod@3.25.76) '@ai-sdk/provider-utils': 3.0.1(zod@3.25.76)
zod: 3.25.76 zod: 3.25.76
'@ai-sdk/google@2.0.4(zod@3.25.76)':
dependencies:
'@ai-sdk/provider': 2.0.0
'@ai-sdk/provider-utils': 3.0.1(zod@3.25.76)
zod: 3.25.76
'@ai-sdk/groq@2.0.3(zod@3.25.76)': '@ai-sdk/groq@2.0.3(zod@3.25.76)':
dependencies: dependencies:
'@ai-sdk/provider': 2.0.0 '@ai-sdk/provider': 2.0.0