Skip to content

Commit

Permalink
Add Mistral Plugin (#19)
Browse files Browse the repository at this point in the history
* first commit

* copy template from openai plugin

* workaround for CommonJS import error + setting types to mistral library

* still adjusting the types to Mistral

* fixed all type errors

* fixed dep issue

* model registered

* first inference done

* json mode working

* changed conventions

* aligning the version of genkit

---------

Co-authored-by: BENDINELLI Tommaso <tommaso.bendinelli@csem.ch>
Co-authored-by: David Oort Alonso <davidoort@hotmail.com>
  • Loading branch information
3 people authored May 14, 2024
1 parent ddab7c9 commit e1763a3
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ node_modules/
.nx/
lib/
.env
temp
2 changes: 1 addition & 1 deletion examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default configureGenkit({
groq(),
cohere(),
anthropic(),
// mistral(),
mistral(),
dotprompt(),
],
logLevel: 'debug',
Expand Down
4 changes: 2 additions & 2 deletions plugins/mistral/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"author": "TheFireCo",
"license": "Apache-2.0",
"dependencies": {
"@genkit-ai/ai": "0.5.0-rc.8",
"@genkit-ai/core": "0.5.0-rc.8",
"@genkit-ai/ai": "0.5.0",
"@genkit-ai/core": "0.5.0",
"@mistralai/mistralai": "^0.2.0",
"zod": "^3.22.4"
},
Expand Down
39 changes: 39 additions & 0 deletions plugins/mistral/src/embedders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2024 The Fire Company
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import { defineEmbedder, embedderRef } from '@genkit-ai/ai/embedder';
import { z } from 'zod';
export const TextEmbeddingConfigSchema = z.object({
dimensions: z.number().optional(),
encodingFormat: z.union([z.literal('float'), z.literal('base64')]).optional(),
});


export const mistralembed = embedderRef({
name: 'mistral/mistral-embed',
configSchema: TextEmbeddingConfigSchema,
info: {
dimensions: 1024,
label: 'Mistral - Mistral Embed',
supports: {
input: ['text'],
},
},
});
export const SUPPORTED_EMBEDDING_MODELS = {
'mistral-embed': mistralembed
}
18 changes: 15 additions & 3 deletions plugins/mistral/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

import { genkitPlugin, Plugin } from '@genkit-ai/core';
import MistralClient from '@mistralai/mistralai';
import { SUPPORTED_MISTRAL_MODELS,mistralModel } from './mistral_llms';


export interface PluginOptions {
apiKey?: string;
Expand All @@ -30,14 +31,25 @@ export const mistral: Plugin<[PluginOptions] | []> = genkitPlugin(
throw new Error(
'Please pass in the API key or set the MISTRALAI_API_KEY environment variable'
);
// Dynamically import the MistralClient
const { default: MistralClient } = await import("@mistralai/mistralai");

const client = new MistralClient(apiKey);
return {
models: [
// TODO: Add Mistral AI models as needed
],
...Object.keys(SUPPORTED_MISTRAL_MODELS).map((name) => mistralModel(name,client))]

// TODO: Add Embedders
// embedders: [...Object.keys(SUPPORTED_MISTRAL_MODELS).map((name) => {
// return {
// name,
// model: SUPPORTED_MISTRAL_MODELS[name],
// };
// })],
};
}
);

export default mistral;

// TODO: Add Mistral AI models as needed
Loading

0 comments on commit e1763a3

Please sign in to comment.