@genkit-ai/vertexai
Version:
Genkit AI framework plugin for Google Cloud Vertex AI APIs including Gemini APIs, Imagen, and more.
1 lines • 5.17 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @license\n *\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @module /\n */\n\nimport { Genkit } from 'genkit';\nimport { GenkitPlugin, genkitPlugin } from 'genkit/plugin';\nimport { getDerivedParams } from './common/index.js';\nimport { PluginOptions } from './common/types.js';\nimport {\n SUPPORTED_EMBEDDER_MODELS,\n defineVertexAIEmbedder,\n multimodalEmbedding001,\n textEmbedding004,\n textEmbedding005,\n textEmbeddingGecko003,\n textEmbeddingGeckoMultilingual001,\n textMultilingualEmbedding002,\n} from './embedder.js';\nimport {\n SUPPORTED_GEMINI_MODELS,\n defineGeminiKnownModel,\n defineGeminiModel,\n gemini,\n gemini10Pro,\n gemini15Flash,\n gemini15Pro,\n gemini20Flash,\n gemini20Flash001,\n gemini20FlashLite,\n gemini20FlashLitePreview0205,\n gemini20ProExp0205,\n gemini25ProExp0325,\n gemini25ProPreview0325,\n type GeminiConfig,\n} from './gemini.js';\nimport {\n SUPPORTED_IMAGEN_MODELS,\n imagen2,\n imagen3,\n imagen3Fast,\n imagenModel,\n} from './imagen.js';\nexport { type PluginOptions } from './common/types.js';\nexport {\n gemini,\n gemini10Pro,\n gemini15Flash,\n gemini15Pro,\n gemini20Flash,\n gemini20Flash001,\n gemini20FlashLite,\n gemini20FlashLitePreview0205,\n gemini20ProExp0205,\n gemini25ProExp0325,\n gemini25ProPreview0325,\n imagen2,\n imagen3,\n imagen3Fast,\n multimodalEmbedding001,\n textEmbedding004,\n textEmbedding005,\n textEmbeddingGecko003,\n textEmbeddingGeckoMultilingual001,\n textMultilingualEmbedding002,\n type GeminiConfig,\n};\n\n/**\n * Add Google Cloud Vertex AI to Genkit. Includes Gemini and Imagen models and text embedder.\n */\nexport function vertexAI(options?: PluginOptions): GenkitPlugin {\n return genkitPlugin('vertexai', async (ai: Genkit) => {\n const { projectId, location, vertexClientFactory, authClient } =\n await getDerivedParams(options);\n\n Object.keys(SUPPORTED_IMAGEN_MODELS).map((name) =>\n imagenModel(ai, name, authClient, { projectId, location })\n );\n Object.keys(SUPPORTED_GEMINI_MODELS).map((name) =>\n defineGeminiKnownModel(\n ai,\n name,\n vertexClientFactory,\n {\n projectId,\n location,\n },\n options?.experimental_debugTraces\n )\n );\n if (options?.models) {\n for (const modelOrRef of options?.models) {\n const modelName =\n typeof modelOrRef === 'string'\n ? modelOrRef\n : // strip out the `vertexai/` prefix\n modelOrRef.name.split('/')[1];\n const modelRef =\n typeof modelOrRef === 'string' ? gemini(modelOrRef) : modelOrRef;\n defineGeminiModel({\n ai,\n modelName: modelRef.name,\n version: modelName,\n modelInfo: modelRef.info,\n vertexClientFactory,\n options: {\n projectId,\n location,\n },\n debugTraces: options.experimental_debugTraces,\n });\n }\n }\n\n Object.keys(SUPPORTED_EMBEDDER_MODELS).map((name) =>\n defineVertexAIEmbedder(ai, name, authClient, { projectId, location })\n );\n });\n}\n\nexport default vertexAI;\n"],"mappings":"AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,SAAuB,oBAAoB;AAC3C,SAAS,wBAAwB;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA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