feat(core): Add AWS Bedrock support to chat hub (no-changelog) (#22033)

This commit is contained in:
Jaakko Husso 2025-11-19 17:12:20 +02:00 committed by GitHub
parent da2446ead3
commit e1fef800d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 137 additions and 4 deletions

View File

@ -17,6 +17,7 @@ export const chatHubLLMProviderSchema = z.enum([
'google',
'azureOpenAi',
'ollama',
'awsBedrock',
]);
export type ChatHubLLMProvider = z.infer<typeof chatHubLLMProviderSchema>;
@ -40,6 +41,7 @@ export const PROVIDER_CREDENTIAL_TYPE_MAP: Record<
google: 'googlePalmApi',
ollama: 'ollamaApi',
azureOpenAi: 'azureOpenAiApi',
awsBedrock: 'aws',
};
export type ChatHubAgentTool = typeof JINA_AI_TOOL_NODE_TYPE | typeof SEAR_XNG_TOOL_NODE_TYPE;
@ -72,6 +74,11 @@ const ollamaModelSchema = z.object({
model: z.string(),
});
const awsBedrockModelSchema = z.object({
provider: z.literal('awsBedrock'),
model: z.string(),
});
const n8nModelSchema = z.object({
provider: z.literal('n8n'),
workflowId: z.string(),
@ -88,6 +95,7 @@ export const chatHubConversationModelSchema = z.discriminatedUnion('provider', [
googleModelSchema,
azureOpenAIModelSchema,
ollamaModelSchema,
awsBedrockModelSchema,
n8nModelSchema,
chatAgentSchema,
]);
@ -97,12 +105,14 @@ export type ChatHubAnthropicModel = z.infer<typeof anthropicModelSchema>;
export type ChatHubGoogleModel = z.infer<typeof googleModelSchema>;
export type ChatHubAzureOpenAIModel = z.infer<typeof azureOpenAIModelSchema>;
export type ChatHubOllamaModel = z.infer<typeof ollamaModelSchema>;
export type ChatHubAwsBedrockModel = z.infer<typeof awsBedrockModelSchema>;
export type ChatHubBaseLLMModel =
| ChatHubOpenAIModel
| ChatHubAnthropicModel
| ChatHubGoogleModel
| ChatHubAzureOpenAIModel
| ChatHubOllamaModel;
| ChatHubOllamaModel
| ChatHubAwsBedrockModel;
export type ChatHubN8nModel = z.infer<typeof n8nModelSchema>;
export type ChatHubCustomAgentModel = z.infer<typeof chatAgentSchema>;
@ -143,6 +153,7 @@ export const emptyChatModelsResponse: ChatModelsResponse = {
google: { models: [] },
azureOpenAi: { models: [] },
ollama: { models: [] },
awsBedrock: { models: [] },
n8n: { models: [] },
// eslint-disable-next-line @typescript-eslint/naming-convention
'custom-agent': { models: [] },

View File

@ -452,7 +452,7 @@ export class ChatHubWorkflowService {
return {
...common,
parameters: {
model: { __rl: true, mode: 'id', value: model },
model,
options: {},
},
};
@ -465,6 +465,15 @@ export class ChatHubWorkflowService {
},
};
}
case 'awsBedrock': {
return {
...common,
parameters: {
model,
options: {},
},
};
}
default:
throw new OperationalError('Unsupported model provider');
}

View File

@ -32,6 +32,10 @@ export const PROVIDER_NODE_TYPE_MAP: Record<ChatHubLLMProvider, INodeTypeNameVer
name: '@n8n/n8n-nodes-langchain.lmChatAzureOpenAi',
version: 1,
},
awsBedrock: {
name: '@n8n/n8n-nodes-langchain.lmChatAwsBedrock',
version: 1.1,
},
};
export const NODE_NAMES = {

View File

@ -159,6 +159,8 @@ export class ChatHubService {
return await this.fetchOllamaModels(credentials, additionalData);
case 'azureOpenAi':
return await this.fetchAzureOpenAiModels(credentials, additionalData);
case 'awsBedrock':
return await this.fetchAwsBedrockModels(credentials, additionalData);
case 'n8n':
return await this.fetchAgentWorkflowsAsModels(user);
case 'custom-agent':
@ -273,7 +275,7 @@ export class ChatHubService {
return {
models: results.map((result) => ({
name: String(result.value),
name: result.name,
description: result.description ?? null,
model: {
provider: 'google',
@ -331,7 +333,7 @@ export class ChatHubService {
return {
models: results.map((result) => ({
name: String(result.value),
name: result.name,
description: result.description ?? null,
model: {
provider: 'ollama',
@ -355,6 +357,111 @@ export class ChatHubService {
};
}
private async fetchAwsBedrockModels(
credentials: INodeCredentials,
additionalData: IWorkflowExecuteAdditionalData,
): Promise<ChatModelsResponse['awsBedrock']> {
// From AWS Bedrock node
// https://github.com/n8n-io/n8n/blob/master/packages/%40n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts#L100
// https://github.com/n8n-io/n8n/blob/master/packages/%40n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts#L155
const foundationModelsRequest = this.nodeParametersService.getOptionsViaLoadOptions(
{
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',
},
},
],
},
},
},
additionalData,
PROVIDER_NODE_TYPE_MAP.awsBedrock,
{},
credentials,
);
const inferenceProfileModelsRequest = this.nodeParametersService.getOptionsViaLoadOptions(
{
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',
},
},
],
},
},
},
additionalData,
PROVIDER_NODE_TYPE_MAP.awsBedrock,
{},
credentials,
);
const [foundationModels, inferenceProfileModels] = await Promise.all([
foundationModelsRequest,
inferenceProfileModelsRequest,
]);
return {
models: foundationModels.concat(inferenceProfileModels).map((result) => ({
name: result.name,
description: result.description ?? String(result.value),
model: {
provider: 'awsBedrock',
model: String(result.value),
},
createdAt: null,
updatedAt: null,
})),
};
}
private async fetchAgentWorkflowsAsModels(user: User): Promise<ChatModelsResponse['n8n']> {
const nodeTypes = [CHAT_TRIGGER_NODE_TYPE];
const workflows = await this.workflowService.getWorkflowsWithNodesIncluded(

View File

@ -139,6 +139,7 @@ export const maxContextWindowTokens: Record<ChatHubLLMProvider, Record<string, n
},
azureOpenAi: {},
ollama: {},
awsBedrock: {},
};
export const getMaxContextWindowTokens = (

View File

@ -13,6 +13,7 @@ export const providerDisplayNames: Record<ChatHubProvider, string> = {
google: 'Google',
azureOpenAi: 'Azure OpenAI',
ollama: 'Ollama',
awsBedrock: 'AWS Bedrock',
n8n: 'n8n',
'custom-agent': 'Custom Agent',
};