-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - mistral_ai #16155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - mistral_ai #16155
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
components/mistral_ai/actions/create-batch-job/create-batch-job.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import mistralAI from "../../mistral_ai.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
| import { parseObj } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "mistral_ai-create-batch-job", | ||
| name: "Create Batch Job", | ||
| description: "Create a new batch job, it will be queued for processing. [See the Documentation](https://docs.mistral.ai/api/#tag/batch/operation/jobs_api_routes_batch_get_batch_jobs)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| mistralAI, | ||
| inputFiles: { | ||
| propDefinition: [ | ||
| mistralAI, | ||
| "fileIds", | ||
| ], | ||
| }, | ||
| modelId: { | ||
| propDefinition: [ | ||
| mistralAI, | ||
| "modelId", | ||
| ], | ||
| }, | ||
| endpoint: { | ||
| type: "string", | ||
| label: "Endpoint", | ||
| description: "The endpoint to use for the batch job", | ||
| options: constants.BATCH_JOB_ENDPOINT_OPTIONS, | ||
| }, | ||
| metadata: { | ||
| type: "object", | ||
| label: "Metadata", | ||
| description: "Optional metadata for the batch job in JSON format.", | ||
| optional: true, | ||
| }, | ||
| timeoutHours: { | ||
| type: "integer", | ||
| label: "Timeout Hours", | ||
| description: "Optional timeout duration for the batch job in hours.", | ||
| optional: true, | ||
| default: 24, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.mistralAI.createBatchJob({ | ||
| $, | ||
| data: { | ||
| input_files: this.inputFiles, | ||
| endpoint: this.endpoint, | ||
| model: this.modelId, | ||
| metadata: parseObj(this.metadata), | ||
| timeoutHours: this.timeoutHours, | ||
| }, | ||
| }); | ||
| if (response?.id) { | ||
| $.export("$summary", `Successfully created batch job with ID: ${response.id}`); | ||
| } | ||
| return response; | ||
| }, | ||
| }; |
32 changes: 32 additions & 0 deletions
32
components/mistral_ai/actions/create-embeddings/create-embeddings.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import mistralAI from "../../mistral_ai.app.mjs"; | ||
| import { parseArray } from "../../common/utils.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "mistral_ai-create-embeddings", | ||
| name: "Create Embeddings", | ||
| description: "Create new embedding in Mistral AI. [See the Documentation](https://docs.mistral.ai/api/#tag/embeddings)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| mistralAI, | ||
| input: { | ||
| type: "string", | ||
| label: "Input", | ||
| description: "The input text for which to create an embedding. May be a string or an array of strings.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.mistralAI.createEmbeddings({ | ||
| $, | ||
| data: { | ||
| model: constants.EMBEDDINGS_MODEL, | ||
| input: parseArray(this.input), | ||
| }, | ||
| }); | ||
| if (response?.id) { | ||
| $.export("$summary", `Successfully created embedding with ID: ${response.id}`); | ||
| } | ||
| return response; | ||
| }, | ||
| }; |
76 changes: 76 additions & 0 deletions
76
components/mistral_ai/actions/generate-text/generate-text.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import mistralAI from "../../mistral_ai.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "mistral_ai-generate-text", | ||
| name: "Generate Text", | ||
| description: "Retrieve a list of available Mistral AI models that the user is authorized to access. [See the Documentation](https://docs.mistral.ai/api/#tag/fim/operation/fim_completion_v1_fim_completions_post)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| mistralAI, | ||
| message: { | ||
| type: "string", | ||
| label: "Message", | ||
| description: "The prompt message to send", | ||
| }, | ||
| modelId: { | ||
| propDefinition: [ | ||
| mistralAI, | ||
| "modelId", | ||
| ], | ||
| }, | ||
| temperature: { | ||
| type: "string", | ||
| label: "Temperature", | ||
| description: "The sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both. The default value varies depending on the model you are targeting.", | ||
| optional: true, | ||
| }, | ||
| topP: { | ||
| type: "string", | ||
| label: "Top P", | ||
| description: "Nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.", | ||
| optional: true, | ||
| }, | ||
| maxTokens: { | ||
| type: "integer", | ||
| label: "Max Tokens", | ||
| description: "The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.", | ||
| optional: true, | ||
| }, | ||
| randomSeed: { | ||
| type: "integer", | ||
| label: "Random Seed", | ||
| description: "The seed to use for random sampling. If set, different calls will generate deterministic results.", | ||
| optional: true, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| n: { | ||
| type: "integer", | ||
| label: "N", | ||
| description: "Number of completions to return for each request, input tokens are only billed once.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.mistralAI.sendPrompt({ | ||
| $, | ||
| data: { | ||
| model: this.modelId, | ||
| messages: [ | ||
| { | ||
| content: this.message, | ||
| role: "user", | ||
| }, | ||
| ], | ||
| temperature: this.temperature && +this.temperature, | ||
| top_p: this.topP && +this.topP, | ||
| max_tokens: this.maxTokens, | ||
| random_seed: this.randomSeed, | ||
| n: this.n, | ||
| }, | ||
| }); | ||
| if (response?.id) { | ||
| $.export("$summary", `Successfully retrieved response with ID: ${response.id}`); | ||
| } | ||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import mistralAI from "../../mistral_ai.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "mistral_ai-list-models", | ||
| name: "List Models", | ||
| description: "Retrieve a list of available Mistral AI models that the user is authorized to access. [See the Documentation](https://docs.mistral.ai/api/#tag/models)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| mistralAI, | ||
| }, | ||
| async run({ $ }) { | ||
| const { data } = await this.mistralAI.listModels({ | ||
| $, | ||
| }); | ||
| if (data?.length) { | ||
| $.export("$summary", `Successfully retrieved ${data.length} model${data.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return data; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const DEFAULT_PAGE_SIZE = 100; | ||
|
|
||
| const EMBEDDINGS_MODEL = "mistral-embed"; | ||
|
|
||
| const BATCH_JOB_STATUS_OPTIONS = [ | ||
| "SUCCESS", | ||
| "FAILED", | ||
| "TIMEOUT_EXCEEDED", | ||
| "CANCELLATION_REQUESTED", | ||
| "CANCELLED", | ||
| ]; | ||
|
|
||
| const BATCH_JOB_ENDPOINT_OPTIONS = [ | ||
| "/v1/chat/completions", | ||
| "/v1/embeddings", | ||
| "/v1/fim/completions", | ||
| "/v1/moderations", | ||
| "/v1/chat/moderations", | ||
| ]; | ||
|
|
||
| export default { | ||
| DEFAULT_PAGE_SIZE, | ||
| EMBEDDINGS_MODEL, | ||
| BATCH_JOB_STATUS_OPTIONS, | ||
| BATCH_JOB_ENDPOINT_OPTIONS, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| function parseArray(arr) { | ||
| if (!arr) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (typeof arr === "string") { | ||
| try { | ||
| return JSON.parse(arr); | ||
| } catch { | ||
| return arr; | ||
| } | ||
| } | ||
|
|
||
| return arr; | ||
| } | ||
|
|
||
| function parseObj(obj) { | ||
| if (!obj) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch { | ||
| return obj; | ||
| } | ||
| } | ||
|
|
||
| return obj; | ||
| } | ||
|
|
||
| export { | ||
| parseArray, | ||
| parseObj, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,125 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import constants from "./common/constants.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "mistral_ai", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| fileIds: { | ||
| type: "string[]", | ||
| label: "File IDs", | ||
| description: "Array of input file UUIDs for batch processing", | ||
| async options({ page }) { | ||
| const { data } = await this.listFiles({ | ||
| params: { | ||
| page, | ||
| page_size: constants.DEFAULT_PAGE_SIZE, | ||
| }, | ||
| }); | ||
| return data?.map(({ | ||
| id: value, filename: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| modelId: { | ||
| type: "string", | ||
| label: "Model ID", | ||
| description: "The identifier of the model to use", | ||
| async options() { | ||
| const { data } = await this.listModels(); | ||
| return data?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.mistral.ai/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, | ||
| path, | ||
| ...otherOpts | ||
| }) { | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }); | ||
| }, | ||
| listModels(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/models", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listBatchJobs(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/batch/jobs", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listFiles(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/files", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createEmbeddings(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/embeddings", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| sendPrompt(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/chat/completions", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createBatchJob(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/batch/jobs", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, | ||
| params = {}, | ||
| max, | ||
| }) { | ||
| params = { | ||
| ...params, | ||
| page: 0, | ||
| page_size: constants.DEFAULT_PAGE_SIZE, | ||
| }; | ||
| let total, count = 0; | ||
| do { | ||
| const { data } = await fn({ | ||
| params, | ||
| }); | ||
| for (const item of data) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
| total = data?.length; | ||
| params.page++; | ||
| } while (total); | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.