@n8n/n8n-nodes-langchain
Version:

130 lines • 5.51 kB
JavaScript
;
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