first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,276 @@
|
||||
import type { BedrockRuntimeClientConfig } from '@aws-sdk/client-bedrock-runtime';
|
||||
import { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime';
|
||||
import { ChatBedrockConverse } from '@langchain/aws';
|
||||
import {
|
||||
getNodeProxyAgent,
|
||||
makeN8nLlmFailedAttemptHandler,
|
||||
N8nLlmTracing,
|
||||
getConnectionHintNoticeField,
|
||||
} from '@n8n/ai-utilities';
|
||||
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
||||
|
||||
import {
|
||||
NodeConnectionTypes,
|
||||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type ISupplyDataFunctions,
|
||||
type SupplyData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class LmChatAwsBedrock implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'AWS Bedrock Chat Model',
|
||||
|
||||
name: 'lmChatAwsBedrock',
|
||||
icon: 'file:bedrock.svg',
|
||||
group: ['transform'],
|
||||
version: [1, 1.1],
|
||||
description: 'Language Model AWS Bedrock',
|
||||
defaults: {
|
||||
name: 'AWS Bedrock Chat Model',
|
||||
},
|
||||
codex: {
|
||||
categories: ['AI'],
|
||||
subcategories: {
|
||||
AI: ['Language Models', 'Root Nodes'],
|
||||
'Language Models': ['Chat Models (Recommended)'],
|
||||
},
|
||||
resources: {
|
||||
primaryDocumentation: [
|
||||
{
|
||||
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatawsbedrock/',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
inputs: [],
|
||||
|
||||
outputs: [NodeConnectionTypes.AiLanguageModel],
|
||||
outputNames: ['Model'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'aws',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
requestDefaults: {
|
||||
ignoreHttpStatusErrors: true,
|
||||
baseURL: '=https://bedrock.{{$credentials?.region ?? "eu-central-1"}}.amazonaws.com',
|
||||
},
|
||||
properties: [
|
||||
getConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiChain]),
|
||||
{
|
||||
displayName: 'Model Source',
|
||||
name: 'modelSource',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'@version': [{ _cnd: { gte: 1.1 } }],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'On-Demand Models',
|
||||
value: 'onDemand',
|
||||
description: 'Standard foundation models with on-demand pricing',
|
||||
},
|
||||
{
|
||||
name: 'Inference Profiles',
|
||||
value: 'inferenceProfile',
|
||||
description:
|
||||
'Cross-region inference profiles (required for models like Claude Sonnet 4 and others)',
|
||||
},
|
||||
],
|
||||
default: 'onDemand',
|
||||
description: 'Choose between on-demand foundation models or inference profiles',
|
||||
},
|
||||
{
|
||||
displayName: 'Model',
|
||||
name: 'model',
|
||||
type: 'options',
|
||||
allowArbitraryValues: true, // Hide issues when model name is specified in the expression and does not match any of the 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>.',
|
||||
displayOptions: {
|
||||
hide: {
|
||||
modelSource: ['inferenceProfile'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['modelSource'],
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/foundation-models?&byOutputModality=TEXT&byInferenceType=ON_DEMAND',
|
||||
},
|
||||
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: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Model',
|
||||
name: 'model',
|
||||
type: 'options',
|
||||
allowArbitraryValues: true,
|
||||
description:
|
||||
'The inference profile which will generate the completion. <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-use.html">Learn more</a>.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
modelSource: ['inferenceProfile'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['modelSource'],
|
||||
loadOptions: {
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/inference-profiles?maxResults=1000',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'inferenceProfileSummaries',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.inferenceProfileName}}',
|
||||
description:
|
||||
'={{$responseItem.description || $responseItem.inferenceProfileArn}}',
|
||||
value: '={{$responseItem.inferenceProfileId}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
send: {
|
||||
type: 'body',
|
||||
property: 'model',
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
placeholder: 'Add Option',
|
||||
description: 'Additional options to add',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Maximum Number of Tokens',
|
||||
name: 'maxTokensToSample',
|
||||
default: 2000,
|
||||
description: 'The maximum number of tokens to generate in the completion',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
displayName: 'Sampling Temperature',
|
||||
name: 'temperature',
|
||||
default: 0.7,
|
||||
typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },
|
||||
description:
|
||||
'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',
|
||||
type: 'number',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
|
||||
const credentials = await this.getCredentials<{
|
||||
region: string;
|
||||
secretAccessKey: string;
|
||||
accessKeyId: string;
|
||||
sessionToken: string;
|
||||
}>('aws');
|
||||
const modelName = this.getNodeParameter('model', itemIndex) as string;
|
||||
const options = this.getNodeParameter('options', itemIndex, {}) as {
|
||||
temperature: number;
|
||||
maxTokensToSample: number;
|
||||
};
|
||||
|
||||
// We set-up client manually to pass httpAgent and httpsAgent
|
||||
const proxyAgent = getNodeProxyAgent();
|
||||
const clientConfig: BedrockRuntimeClientConfig = {
|
||||
region: credentials.region,
|
||||
credentials: {
|
||||
secretAccessKey: credentials.secretAccessKey,
|
||||
accessKeyId: credentials.accessKeyId,
|
||||
...(credentials.sessionToken && { sessionToken: credentials.sessionToken }),
|
||||
},
|
||||
};
|
||||
|
||||
if (proxyAgent) {
|
||||
clientConfig.requestHandler = new NodeHttpHandler({
|
||||
httpAgent: proxyAgent,
|
||||
httpsAgent: proxyAgent,
|
||||
});
|
||||
}
|
||||
|
||||
// Pass the pre-configured client to avoid credential resolution proxy issues
|
||||
const client = new BedrockRuntimeClient(clientConfig);
|
||||
|
||||
const model = new ChatBedrockConverse({
|
||||
client,
|
||||
model: modelName,
|
||||
region: credentials.region,
|
||||
temperature: options.temperature,
|
||||
maxTokens: options.maxTokensToSample,
|
||||
callbacks: [new N8nLlmTracing(this)],
|
||||
onFailedAttempt: makeN8nLlmFailedAttemptHandler(this),
|
||||
});
|
||||
|
||||
return {
|
||||
response: model,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><defs><linearGradient id="a" x1="0%" x2="100%" y1="100%" y2="0%"><stop offset="0%" stop-color="#055F4E"/><stop offset="100%" stop-color="#56C0A7"/></linearGradient></defs><g fill="none" fill-rule="evenodd"><path fill="url(#a)" d="M0 0h24v24H0z"/><path fill="#FFF" d="m12 18.14-2.426.809-.946-.631 1.03-.344-.316-.948-1.768.589L7 17.233V14.5a.5.5 0 0 0-.276-.447L5 13.19v-2.382l1.5-.75 1.5.75v1.69c0 .19.107.364.276.449l2 1 .448-.895L9 12.19v-1.382l1.724-.861A.5.5 0 0 0 11 9.5V8h-1v1.19l-1.5.75L7 9.19V6.769L8 6.1V8h1V5.435l.574-.383L12 5.86zM17.5 17a.5.5 0 1 1-.002 1 .5.5 0 0 1 .002-1m-1-11a.5.5 0 1 1-.002 1 .5.5 0 0 1 .002-1m2 6a.5.5 0 1 1-.002 1 .5.5 0 0 1 .002-1m-1.408 1c.207.58.757 1 1.408 1a1.501 1.501 0 0 0 0-3c-.651 0-1.201.42-1.408 1H13v-2h3.5a.5.5 0 0 0 .5-.5V7.908c.581-.207 1-.757 1-1.408 0-.827-.673-1.5-1.5-1.5S15 5.673 15 6.5c0 .65.419 1.2 1 1.408V9h-3V5.5a.5.5 0 0 0-.342-.474l-3-1a.5.5 0 0 0-.435.058l-3 2A.5.5 0 0 0 6 6.5v2.69l-1.724.863A.5.5 0 0 0 4 10.5v3c0 .19.107.363.276.448l1.724.86V17.5a.5.5 0 0 0 .223.416l3 2a.5.5 0 0 0 .435.058l3-1A.5.5 0 0 0 13 18.5V16h2.293l.853.854.013-.013c-.098.2-.159.422-.159.659 0 .827.673 1.5 1.5 1.5s1.5-.673 1.5-1.5-.673-1.5-1.5-1.5c-.238 0-.46.06-.659.16l.013-.013-1-1A.5.5 0 0 0 15.5 15H13v-2z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
Reference in New Issue
Block a user