-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LmChatMistralCloud Node): Implement MistralCloud Chat & Embeddin…
…gs nodes Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
- Loading branch information
1 parent
8a78ae1
commit b1b93e9
Showing
8 changed files
with
440 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
packages/@n8n/nodes-langchain/credentials/MistralCloudApi.credentials.ts
This file contains 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,42 @@ | ||
import type { | ||
IAuthenticateGeneric, | ||
ICredentialTestRequest, | ||
ICredentialType, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
export class MistralCloudApi implements ICredentialType { | ||
name = 'mistralCloudApi'; | ||
|
||
displayName = 'Mistral Cloud API'; | ||
|
||
documentationUrl = 'mistralCloud'; | ||
|
||
properties: INodeProperties[] = [ | ||
{ | ||
displayName: 'API Key', | ||
name: 'apiKey', | ||
type: 'string', | ||
typeOptions: { password: true }, | ||
required: true, | ||
default: '', | ||
}, | ||
]; | ||
|
||
authenticate: IAuthenticateGeneric = { | ||
type: 'generic', | ||
properties: { | ||
headers: { | ||
Authorization: '=Bearer {{$credentials.apiKey}}', | ||
}, | ||
}, | ||
}; | ||
|
||
test: ICredentialTestRequest = { | ||
request: { | ||
baseURL: 'https://api.mistral.ai/v1', | ||
url: '/models', | ||
method: 'GET' | ||
}, | ||
}; | ||
} |
151 changes: 151 additions & 0 deletions
151
...8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts
This file contains 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,151 @@ | ||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */ | ||
import { | ||
NodeConnectionType, | ||
type IExecuteFunctions, | ||
type INodeType, | ||
type INodeTypeDescription, | ||
type SupplyData, | ||
} from 'n8n-workflow'; | ||
import { logWrapper } from '../../../utils/logWrapper'; | ||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; | ||
import { MistralAIEmbeddings, MistralAIEmbeddingsParams } from "@langchain/mistralai"; | ||
Check warning on line 11 in packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts GitHub Actions / Lint changes
Check failure on line 11 in packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts GitHub Actions / Lint changes
|
||
|
||
export class EmbeddingsMistralCloud implements INodeType { | ||
description: INodeTypeDescription = { | ||
displayName: 'Embeddings Mistral Cloud', | ||
name: 'embeddingsMistralCloud', | ||
icon: 'file:mistral.svg', | ||
credentials: [ | ||
{ | ||
name: 'mistralCloudApi', | ||
required: true, | ||
}, | ||
], | ||
group: ['transform'], | ||
version: 1, | ||
description: 'Use Embeddings Mistral Cloud', | ||
defaults: { | ||
name: 'Embeddings Mistral Cloud', | ||
}, | ||
|
||
codex: { | ||
categories: ['AI'], | ||
subcategories: { | ||
AI: ['Embeddings'], | ||
}, | ||
resources: { | ||
primaryDocumentation: [ | ||
{ | ||
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsmistralcloud/', | ||
}, | ||
], | ||
}, | ||
}, | ||
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node | ||
inputs: [], | ||
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong | ||
outputs: [NodeConnectionType.AiEmbedding], | ||
outputNames: ['Embeddings'], | ||
requestDefaults: { | ||
ignoreHttpStatusErrors: true, | ||
baseURL: "https://api.mistral.ai/v1", | ||
}, | ||
properties: [ | ||
getConnectionHintNoticeField([NodeConnectionType.AiVectorStore]), | ||
{ | ||
displayName: 'Model', | ||
name: 'model', | ||
type: 'options', | ||
description: | ||
'The model which will compute the embeddings. <a href="https://docs.mistral.ai/platform/endpoints/">Learn more</a>.', | ||
typeOptions: { | ||
loadOptions: { | ||
routing: { | ||
request: { | ||
method: 'GET', | ||
url: '/models', | ||
}, | ||
output: { | ||
postReceive: [ | ||
{ | ||
type: 'rootProperty', | ||
properties: { | ||
property: 'data', | ||
}, | ||
}, | ||
{ | ||
type: 'filter', | ||
properties: { | ||
pass: "={{ $responseItem.id.includes('embed') }}", | ||
}, | ||
}, | ||
{ | ||
type: 'setKeyValue', | ||
properties: { | ||
name: '={{ $responseItem.id }}', | ||
value: '={{ $responseItem.id }}', | ||
}, | ||
}, | ||
{ | ||
type: 'sort', | ||
properties: { | ||
key: 'name', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
routing: { | ||
send: { | ||
type: 'body', | ||
property: 'model', | ||
}, | ||
}, | ||
default: 'mistral-embed', | ||
}, | ||
{ | ||
displayName: 'Options', | ||
name: 'options', | ||
placeholder: 'Add Option', | ||
description: 'Additional options to add', | ||
type: 'collection', | ||
default: {}, | ||
options: [ | ||
{ | ||
displayName: 'Batch Size', | ||
name: 'batchSize', | ||
default: 512, | ||
typeOptions: { maxValue: 2048 }, | ||
description: 'Maximum number of documents to send in each request', | ||
type: 'number', | ||
}, | ||
{ | ||
displayName: 'Strip New Lines', | ||
name: 'stripNewLines', | ||
default: true, | ||
description: 'Whether to strip new lines from the input text', | ||
type: 'boolean', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> { | ||
const credentials = await this.getCredentials('mistralCloudApi'); | ||
const modelName = this.getNodeParameter('model', itemIndex) as string; | ||
const options = this.getNodeParameter('options', itemIndex, {}) as Partial<MistralAIEmbeddingsParams>; | ||
|
||
const embeddings = new MistralAIEmbeddings({ | ||
apiKey: credentials!.apiKey as string, | ||
Check warning on line 142 in packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.ts GitHub Actions / Lint changes
|
||
modelName, | ||
...options, | ||
}); | ||
|
||
return { | ||
response: logWrapper(embeddings, this), | ||
}; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsMistralCloud/mistral.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.