update bedrock

This commit is contained in:
Henry
2023-12-15 17:49:29 +00:00
parent 1b0b1f13fa
commit 6e4822c3bb
3 changed files with 39 additions and 11 deletions
@@ -1,9 +1,9 @@
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatBedrock } from 'langchain/chat_models/bedrock'
import { BedrockChat } from 'langchain/chat_models/bedrock'
import { BaseBedrockInput } from 'langchain/dist/util/bedrock'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'
import { BaseChatModelParams } from 'langchain/chat_models/base'
/**
* I had to run the following to build the component
@@ -25,14 +25,14 @@ class AWSChatBedrock_ChatModels implements INode {
inputs: INodeParams[]
constructor() {
this.label = 'AWS Bedrock'
this.label = 'AWS ChatBedrock'
this.name = 'awsChatBedrock'
this.version = 3.0
this.type = 'AWSChatBedrock'
this.icon = 'awsBedrock.png'
this.category = 'Chat Models'
this.description = 'Wrapper around AWS Bedrock large language models that use the Chat endpoint'
this.baseClasses = [this.type, ...getBaseClasses(ChatBedrock)]
this.baseClasses = [this.type, ...getBaseClasses(BedrockChat)]
this.credential = {
label: 'AWS Credential',
name: 'credential',
@@ -102,6 +102,13 @@ class AWSChatBedrock_ChatModels implements INode {
],
default: 'anthropic.claude-v2'
},
{
label: 'Custom Model Name',
name: 'customModel',
description: 'If provided, will override model selected from Model Name option',
type: 'string',
optional: true
},
{
label: 'Temperature',
name: 'temperature',
@@ -109,6 +116,7 @@ class AWSChatBedrock_ChatModels implements INode {
step: 0.1,
description: 'Temperature parameter may not apply to certain model. Please check available model parameters',
optional: true,
additionalParams: true,
default: 0.7
},
{
@@ -118,6 +126,7 @@ class AWSChatBedrock_ChatModels implements INode {
step: 10,
description: 'Max Tokens parameter may not apply to certain model. Please check available model parameters',
optional: true,
additionalParams: true,
default: 200
}
]
@@ -126,14 +135,15 @@ class AWSChatBedrock_ChatModels implements INode {
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const iRegion = nodeData.inputs?.region as string
const iModel = nodeData.inputs?.model as string
const customModel = nodeData.inputs?.customModel as string
const iTemperature = nodeData.inputs?.temperature as string
const iMax_tokens_to_sample = nodeData.inputs?.max_tokens_to_sample as string
const cache = nodeData.inputs?.cache as BaseCache
const streaming = nodeData.inputs?.streaming as boolean
const obj: BaseBedrockInput & BaseLLMParams = {
const obj: BaseBedrockInput & BaseChatModelParams = {
region: iRegion,
model: iModel,
model: customModel ?? iModel,
maxTokens: parseInt(iMax_tokens_to_sample, 10),
temperature: parseFloat(iTemperature),
streaming: streaming ?? true
@@ -160,7 +170,7 @@ class AWSChatBedrock_ChatModels implements INode {
}
if (cache) obj.cache = cache
const amazonBedrock = new ChatBedrock(obj)
const amazonBedrock = new BedrockChat(obj)
return amazonBedrock
}
}