UNPKG

genkitx-mistral

Version:

Firebase Genkit AI framework plugin for Mistral AI APIs.

1 lines 4.43 kB
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 The Fire Company\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\nimport { type GenerationCommonConfigSchema, Genkit, type ModelReference } from 'genkit';\nimport { genkitPlugin } from 'genkit/plugin';\nimport { Mistral, SDKOptions } from '@mistralai/mistralai';\nimport { mistralEmbedder, SUPPORTED_EMBEDDING_MODELS } from './embedders';\nimport { SUPPORTED_MISTRAL_MODELS, mistralModel } from './mistral_llms';\nimport { OCRModel } from './ocr';\n\nexport {\n openMistral7B,\n openMistral8x7B,\n openMixtral8x22B,\n openMinistral3B,\n openMinistral8B,\n openMistralSmall,\n openMistralMedium,\n openMistralLarge,\n openMistralNemo,\n openCodestralMambda,\n openCodestral,\n openMistralSaba,\n openPixtralLarge,\n openPixtral,\n} from './mistral_llms';\n\nexport { ocr } from './ocr';\n\nexport { mistralembed } from './embedders';\n\nexport interface PluginOptions extends SDKOptions {\n /**\n * Additional models references that the user wants to add to the plugin.\n * These models should be created with the `modelRef` function and then passed in here.\n * @example\n * ```ts\n * const customModel = modelRef({\n * name: 'mistral/custom-model',\n * info: {\n * versions: ['custom-model'],\n * label: 'Custom Model',\n * supports: {\n * multiturn: true,\n * tools: false,\n * media: false,\n * systemRole: true,\n * output: ['text', 'json'],\n * },\n * },\n * configSchema: GenerationCommonConfigSchema,\n * });\n *\n * const ai = genkit({\n * plugins: [\n * mistral({\n * apiKey: process.env.MISTRAL_API_KEY,\n * serverURL: process.env.MISTRAL_ENDPOINT,\n * customModels: {\n * 'custom-model': customModel,\n * },\n * }),\n * ],\n * });\n * ```\n *\n */\n customModels?: Record<string, ModelReference<typeof GenerationCommonConfigSchema>>;\n}\n\nexport const mistral = (options?: PluginOptions) =>\n genkitPlugin('mistral', async (ai: Genkit) => {\n let apiKey = options?.apiKey || process.env.MISTRAL_API_KEY;\n if (!apiKey) {\n throw new Error(\n 'Please pass in the API key or set the MISTRAL_API_KEY environment variable'\n );\n }\n\n // If we have custom models, add them to the SUPPORTED_MISTRAL_MODELS\n let customModels = options?.customModels || {};\n if (Object.keys(customModels).length > 0) {\n for (const [name, model] of Object.entries(customModels)) {\n if (model) {\n SUPPORTED_MISTRAL_MODELS[name] = model;\n }\n }\n }\n\n const client = new Mistral(options);\n\n for (const name of Object.keys(SUPPORTED_MISTRAL_MODELS)) {\n mistralModel(ai, name, client);\n }\n\n for (const name of Object.keys(SUPPORTED_EMBEDDING_MODELS)) {\n mistralEmbedder(ai, name, client);\n }\n\n OCRModel(ai, client);\n });\n\nexport default mistral;\n"],"mappings":";;;AAiBA,SAAS,oBAAoB;AAC7B,SAAS,eAA2B;AACpC,SAAS,iBAAiB,kCAAkC;AAC5D,SAAS,0BAA0B,oBAAoB;AACvD,SAAS,gBAAgB;AAEzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,WAAW;AAEpB,SAAS,oBAAoB;AAyCtB,MAAM,UAAU,CAAC,YACtB,aAAa,WAAW,CAAO,OAAe;AAC5C,MAAI,UAAS,mCAAS,WAAU,QAAQ,IAAI;AAC5C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,MAAI,gBAAe,mCAAS,iBAAgB,CAAC;AAC7C,MAAI,OAAO,KAAK,YAAY,EAAE,SAAS,GAAG;AACxC,eAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,YAAY,GAAG;AACxD,UAAI,OAAO;AACT,iCAAyB,IAAI,IAAI;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,IAAI,QAAQ,OAAO;AAElC,aAAW,QAAQ,OAAO,KAAK,wBAAwB,GAAG;AACxD,iBAAa,IAAI,MAAM,MAAM;AAAA,EAC/B;AAEA,aAAW,QAAQ,OAAO,KAAK,0BAA0B,GAAG;AAC1D,oBAAgB,IAAI,MAAM,MAAM;AAAA,EAClC;AAEA,WAAS,IAAI,MAAM;AACrB,EAAC;AAEH,IAAO,cAAQ;","names":[]}