UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

130 lines 5.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmbeddingsAwsBedrock = void 0; const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime"); const aws_1 = require("@langchain/aws"); const node_http_handler_1 = require("@smithy/node-http-handler"); const ai_utilities_1 = require("@n8n/ai-utilities"); const n8n_workflow_1 = require("n8n-workflow"); class EmbeddingsAwsBedrock { constructor() { this.description = { displayName: 'Embeddings AWS Bedrock', name: 'embeddingsAwsBedrock', icon: 'file:bedrock.svg', credentials: [ { name: 'aws', required: true, }, ], group: ['transform'], version: 1, description: 'Use Embeddings AWS Bedrock', defaults: { name: 'Embeddings AWS Bedrock', }, codex: { categories: ['AI'], subcategories: { AI: ['Embeddings'], }, resources: { primaryDocumentation: [ { url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsawsbedrock/', }, ], }, }, inputs: [], outputs: [n8n_workflow_1.NodeConnectionTypes.AiEmbedding], outputNames: ['Embeddings'], requestDefaults: { ignoreHttpStatusErrors: true, baseURL: '=https://bedrock.{{$credentials?.region ?? "eu-central-1"}}.amazonaws.com', }, properties: [ (0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]), { displayName: 'Model', name: 'model', type: 'options', description: 'The model which will generate the completion. <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/foundation-models.html">Learn more</a>.', typeOptions: { loadOptions: { routing: { request: { method: 'GET', url: '/foundation-models?byInferenceType=ON_DEMAND&byOutputModality=EMBEDDING', }, output: { postReceive: [ { type: 'rootProperty', properties: { property: 'modelSummaries', }, }, { type: 'setKeyValue', properties: { name: '={{$responseItem.modelName}}', description: '={{$responseItem.modelArn}}', value: '={{$responseItem.modelId}}', }, }, { type: 'sort', properties: { key: 'name', }, }, ], }, }, }, }, routing: { send: { type: 'body', property: 'model', }, }, default: '', }, ], }; } async supplyData(itemIndex) { const credentials = await this.getCredentials('aws'); const modelName = this.getNodeParameter('model', itemIndex); const clientConfig = { region: credentials.region, credentials: { secretAccessKey: credentials.secretAccessKey, accessKeyId: credentials.accessKeyId, sessionToken: credentials.sessionToken, }, }; const proxyAgent = (0, ai_utilities_1.getNodeProxyAgent)(); if (proxyAgent) { clientConfig.requestHandler = new node_http_handler_1.NodeHttpHandler({ httpAgent: proxyAgent, httpsAgent: proxyAgent, }); } const client = new client_bedrock_runtime_1.BedrockRuntimeClient(clientConfig); const embeddings = new aws_1.BedrockEmbeddings({ client, model: modelName, maxRetries: 3, region: credentials.region, }); return { response: (0, ai_utilities_1.logWrapper)(embeddings, this), }; } } exports.EmbeddingsAwsBedrock = EmbeddingsAwsBedrock; //# sourceMappingURL=EmbeddingsAwsBedrock.node.js.map