From 44ac9b0fb5940b0f0c5a2ba5fdddf73db2af2e0f Mon Sep 17 00:00:00 2001 From: Aakash Amod Rajput Date: Fri, 22 Nov 2024 02:51:29 +0530 Subject: [PATCH] Gemini Integrated Successfully --- package.json | 5 ++-- packages/api/ai/config.mts | 10 ++----- packages/api/package.json | 1 + packages/shared/package.json | 1 + packages/shared/src/ai.mts | 2 +- pnpm-lock.yaml | 53 ++++++++++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 080ab5a3..5ed4963c 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,12 @@ "@changesets/cli": "^2.27.8", "@srcbook/configs": "workspace:^", "@types/node": "^20.14.2", + "eslint": "^8.57.0", "prettier": "^3.3.3", - "typescript": "5.6.2", - "eslint": "^8.57.0" + "typescript": "5.6.2" }, "dependencies": { + "@ai-sdk/google": "^1.0.1", "turbo": "^2.1.1" }, "packageManager": "pnpm@9.12.1", diff --git a/packages/api/ai/config.mts b/packages/api/ai/config.mts index 240d25d5..54c833a1 100644 --- a/packages/api/ai/config.mts +++ b/packages/api/ai/config.mts @@ -3,6 +3,7 @@ import { createAnthropic } from '@ai-sdk/anthropic'; import { getConfig } from '../config.mjs'; import type { LanguageModel } from 'ai'; import { getDefaultModel, type AiProviderType } from '@srcbook/shared'; +import { createGoogleGenerativeAI } from '@ai-sdk/google'; /** * Get the correct client and model configuration. @@ -34,13 +35,8 @@ export async function getModel(): Promise { if (!config.geminiKey) { throw new Error('Gemini API key is not set'); } - const gemini = createOpenAI({ - compatibility: 'compatible', - baseURL: - 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=', - apiKey: config.geminiKey, - }); - return gemini(model); + const google = createGoogleGenerativeAI({apiKey: config.geminiKey}) + return google(model); case 'Xai': if (!config.xaiKey) { diff --git a/packages/api/package.json b/packages/api/package.json index 714c6d07..eda5fb17 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@ai-sdk/anthropic": "catalog:", + "@ai-sdk/google": "^1.0.1", "@ai-sdk/openai": "catalog:", "@srcbook/shared": "workspace:^", "ai": "^3.3.33", diff --git a/packages/shared/package.json b/packages/shared/package.json index 2f9a8204..c768f01f 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -12,6 +12,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { + "@ai-sdk/google": "1.0.1", "@scure/base": "^1.1.8", "zod": "catalog:" }, diff --git a/packages/shared/src/ai.mts b/packages/shared/src/ai.mts index c88d2e09..b6753f5a 100644 --- a/packages/shared/src/ai.mts +++ b/packages/shared/src/ai.mts @@ -13,7 +13,7 @@ export const defaultModels: Record = { [AiProvider.Anthropic]: 'claude-3-5-sonnet-latest', [AiProvider.Custom]: 'mistral-nemo', [AiProvider.XAI]: 'grok-beta', - [AiProvider.Gemini]: 'google-developer-ai', + [AiProvider.Gemini]: 'gemini-1.5-pro-latest', } as const; export function isValidProvider(provider: string): provider is AiProviderType { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f70e944a..5d1f04f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: .: dependencies: + '@ai-sdk/google': + specifier: ^1.0.1 + version: 1.0.1(zod@3.23.8) turbo: specifier: ^2.1.1 version: 2.1.1 @@ -54,6 +57,9 @@ importers: '@ai-sdk/anthropic': specifier: 'catalog:' version: 0.0.49(zod@3.23.8) + '@ai-sdk/google': + specifier: ^1.0.1 + version: 1.0.1(zod@3.23.8) '@ai-sdk/openai': specifier: 'catalog:' version: 0.0.58(zod@3.23.8) @@ -286,6 +292,9 @@ importers: packages/shared: dependencies: + '@ai-sdk/google': + specifier: 1.0.1 + version: 1.0.1(zod@3.23.8) '@scure/base': specifier: ^1.1.8 version: 1.1.8 @@ -490,6 +499,12 @@ packages: peerDependencies: zod: ^3.0.0 + '@ai-sdk/google@1.0.1': + resolution: {integrity: sha512-RnUnx3TjyegrURFXiWWqcpeNiMlfQfotSM198Wdl2XiD+kaqEBzcBB/imHMlqY5VJdnXi0DCleFlcMQldK5SCA==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.0.0 + '@ai-sdk/openai@0.0.58': resolution: {integrity: sha512-Eao1L0vzfXdymgvc5FDHwV2g2A7BCWml1cShNA+wliY1RL7NNREGcuQvBDNoggB9PM24fawzZyk0ZJ5jlo9Q0w==} engines: {node: '>=18'} @@ -505,10 +520,23 @@ packages: zod: optional: true + '@ai-sdk/provider-utils@2.0.1': + resolution: {integrity: sha512-TNg7rPhRtETB2Z9F0JpOvpGii9Fs8EWM8nYy1jEkvSXkrPJ6b/9zVnDdaJsmLFDyrMbOsPJlkblYtmYEQou36w==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.0.0 + peerDependenciesMeta: + zod: + optional: true + '@ai-sdk/provider@0.0.23': resolution: {integrity: sha512-oAc49O5+xypVrKM7EUU5P/Y4DUL4JZUWVxhejoAVOTOl3WZUEWsMbP3QZR+TrimQIsS0WR/n9UuF6U0jPdp0tQ==} engines: {node: '>=18'} + '@ai-sdk/provider@1.0.0': + resolution: {integrity: sha512-Sj29AzooJ7SYvhPd+AAWt/E7j63E9+AzRnoMHUaJPRYzOd/WDrVNxxv85prF9gDcQ7XPVlSk9j6oAZV9/DXYpA==} + engines: {node: '>=18'} + '@ai-sdk/react@0.0.55': resolution: {integrity: sha512-9fUUEEEoH01M6ZhvyZ/2v0DI6tiYnSldBg6RaKoy+qx2tSeKvOpFNZhT/iOvQ7oqAyyp0Ocg5Rj7L/jcLXSMxw==} engines: {node: '>=18'} @@ -3441,6 +3469,10 @@ packages: resolution: {integrity: sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==} engines: {node: '>=14.18'} + eventsource-parser@3.0.0: + resolution: {integrity: sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==} + engines: {node: '>=18.0.0'} + execa@8.0.1: resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==} engines: {node: '>=16.17'} @@ -5527,6 +5559,12 @@ snapshots: '@ai-sdk/provider-utils': 1.0.18(zod@3.23.8) zod: 3.23.8 + '@ai-sdk/google@1.0.1(zod@3.23.8)': + dependencies: + '@ai-sdk/provider': 1.0.0 + '@ai-sdk/provider-utils': 2.0.1(zod@3.23.8) + zod: 3.23.8 + '@ai-sdk/openai@0.0.58(zod@3.23.8)': dependencies: '@ai-sdk/provider': 0.0.23 @@ -5542,10 +5580,23 @@ snapshots: optionalDependencies: zod: 3.23.8 + '@ai-sdk/provider-utils@2.0.1(zod@3.23.8)': + dependencies: + '@ai-sdk/provider': 1.0.0 + eventsource-parser: 3.0.0 + nanoid: 3.3.7 + secure-json-parse: 2.7.0 + optionalDependencies: + zod: 3.23.8 + '@ai-sdk/provider@0.0.23': dependencies: json-schema: 0.4.0 + '@ai-sdk/provider@1.0.0': + dependencies: + json-schema: 0.4.0 + '@ai-sdk/react@0.0.55(react@18.3.1)(zod@3.23.8)': dependencies: '@ai-sdk/provider-utils': 1.0.18(zod@3.23.8) @@ -8692,6 +8743,8 @@ snapshots: eventsource-parser@1.1.2: {} + eventsource-parser@3.0.0: {} + execa@8.0.1: dependencies: cross-spawn: 7.0.3