switch ai model to google

This commit is contained in:
Sahaj Jain
2025-06-25 23:05:45 +05:30
parent 0e6ac7e21b
commit 27209af024
3 changed files with 1 additions and 43 deletions
+1 -13
View File
@@ -2,11 +2,9 @@ import { auth } from "@/lib/auth";
import { AI_PROMPT_CHARACTER_LIMIT } from "@/lib/constants";
import { themeStylePropsSchema } from "@/types/theme";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { createGroq } from "@ai-sdk/groq";
import { Ratelimit } from "@upstash/ratelimit";
import { kv } from "@vercel/kv";
import { generateObject } from "ai";
import { createFallback } from "ai-fallback";
import { NextRequest } from "next/server";
import { z } from "zod";
import { headers } from "next/headers";
@@ -72,21 +70,11 @@ export async function POST(req: NextRequest) {
const body = await req.json();
const { prompt } = requestSchema.parse(body);
const groq = createGroq({
apiKey: process.env.GROQ_API_KEY,
});
const google = createGoogleGenerativeAI({
apiKey: process.env.GOOGLE_API_KEY,
});
const model = createFallback({
models: [groq("llama-3.3-70b-versatile"), google("gemini-2.0-flash-lite")],
onError: (error, modelId) => {
console.error(`Error with model ${modelId}:`, error);
},
modelResetInterval: 60000, // Reset to first model after 1 minute of the first error
});
const model = google("gemini-2.0-flash");
const { object: theme } = await generateObject({
model,
-2
View File
@@ -12,7 +12,6 @@
},
"dependencies": {
"@ai-sdk/google": "^1.2.14",
"@ai-sdk/groq": "^1.2.8",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/modifiers": "^9.0.0",
"@dnd-kit/sortable": "^10.0.0",
@@ -59,7 +58,6 @@
"@vercel/kv": "^3.0.0",
"@vercel/og": "^0.6.8",
"ai": "^4.3.13",
"ai-fallback": "^0.1.3",
"better-auth": "^1.2.7",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
-28
View File
@@ -11,9 +11,6 @@ importers:
'@ai-sdk/google':
specifier: ^1.2.14
version: 1.2.14(zod@3.24.2)
'@ai-sdk/groq':
specifier: ^1.2.8
version: 1.2.8(zod@3.24.2)
'@dnd-kit/core':
specifier: ^6.3.1
version: 6.3.1(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
@@ -152,9 +149,6 @@ importers:
ai:
specifier: ^4.3.13
version: 4.3.13(react@19.1.0)(zod@3.24.2)
ai-fallback:
specifier: ^0.1.3
version: 0.1.3(zod@3.24.2)
better-auth:
specifier: ^1.2.7
version: 1.2.7
@@ -336,12 +330,6 @@ packages:
peerDependencies:
zod: ^3.0.0
'@ai-sdk/groq@1.2.8':
resolution: {integrity: sha512-DRq0b4twVUh52DFnIhVC4F14Po8w+76sCdigMRRIcAiSmGRr9I3Vyot36tun1q4tBZMYSvQUss60W3eiaoa6mg==}
engines: {node: '>=18'}
peerDependencies:
zod: ^3.0.0
'@ai-sdk/provider-utils@2.2.7':
resolution: {integrity: sha512-kM0xS3GWg3aMChh9zfeM+80vEZfXzR3JEUBdycZLtbRZ2TRT8xOj3WodGHPb06sUK5yD7pAXC/P7ctsi2fvUGQ==}
engines: {node: '>=18'}
@@ -3108,9 +3096,6 @@ packages:
resolution: {integrity: sha512-kja8j7PjmncONqaTsB8fQ+wE2mSU2DJ9D4XKoJ5PFWIdRMa6SLSN1ff4mOr4jCbfRSsxR4keIiySJU0N9T5hIQ==}
engines: {node: '>= 8.0.0'}
ai-fallback@0.1.3:
resolution: {integrity: sha512-yS5Kk3ytsc6IrVks05OV1mcAc/gZ4jJuv/4bk7JPQVFtRMGEYIRZNxCuEITJUPl1th5VAZbdGAqFZ7b1h4BC4g==}
ai@4.3.13:
resolution: {integrity: sha512-cC5HXItuOwGykSMacCPzNp6+NMTxeuTjOenztVgSJhdC9Z4OrzBxwkyeDAf4h1QP938ZFi7IBdq3u4lxVoVmvw==}
engines: {node: '>=18'}
@@ -6032,12 +6017,6 @@ snapshots:
'@ai-sdk/provider-utils': 2.2.7(zod@3.24.2)
zod: 3.24.2
'@ai-sdk/groq@1.2.8(zod@3.24.2)':
dependencies:
'@ai-sdk/provider': 1.1.3
'@ai-sdk/provider-utils': 2.2.7(zod@3.24.2)
zod: 3.24.2
'@ai-sdk/provider-utils@2.2.7(zod@3.24.2)':
dependencies:
'@ai-sdk/provider': 1.1.3
@@ -8983,13 +8962,6 @@ snapshots:
dependencies:
humanize-ms: 1.2.1
ai-fallback@0.1.3(zod@3.24.2):
dependencies:
'@ai-sdk/provider': 1.1.3
'@ai-sdk/provider-utils': 2.2.7(zod@3.24.2)
transitivePeerDependencies:
- zod
ai@4.3.13(react@19.1.0)(zod@3.24.2):
dependencies:
'@ai-sdk/provider': 1.1.3