mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 09:01:06 +03:00
added initial code
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { ICommonObject, INode, INodeData, INodeParams, getBaseClasses } from '../../../src'
|
||||
import { DynamoDBChatMessageHistory } from 'langchain/stores/message/dynamodb'
|
||||
import { BufferMemory } from 'langchain/memory'
|
||||
|
||||
class DynamoDb_Memory implements INode {
|
||||
label: string
|
||||
name: string
|
||||
description: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'DynamoDB Memory'
|
||||
this.name = 'DynamoDbMemory'
|
||||
this.icon = 'dynamodb.svg'
|
||||
this.category = 'Memory'
|
||||
this.description = 'Stores the conversation in dynamo db table'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(DynamoDBChatMessageHistory)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Table Name',
|
||||
name: 'tableName',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
label: 'Partition Key',
|
||||
name: 'partitionKey',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
label: 'Session ID',
|
||||
name: 'sessionId',
|
||||
type: 'string',
|
||||
description: 'if empty, chatId will be used automatically',
|
||||
default: '',
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Region',
|
||||
name: 'region',
|
||||
type: 'string',
|
||||
description: 'The aws region in which table is located',
|
||||
placeholder: 'us-east-1'
|
||||
},
|
||||
{
|
||||
label: 'Access Key',
|
||||
name: 'accessKey',
|
||||
type: 'password'
|
||||
},
|
||||
{
|
||||
label: 'Secret Access Key',
|
||||
name: 'secretAccessKey',
|
||||
type: 'password'
|
||||
}
|
||||
]
|
||||
}
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const tableName = nodeData.inputs?.tableName as string
|
||||
const partitionKey = nodeData.inputs?.partitionKey as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const region = nodeData.inputs?.region as string
|
||||
const accessKey = nodeData.inputs?.accessKey as string
|
||||
const secretAccessKey = nodeData.inputs?.secretAccessKey as string
|
||||
|
||||
const chatId = options.chatId
|
||||
|
||||
const dynamoDb = new DynamoDBChatMessageHistory({
|
||||
tableName,
|
||||
partitionKey,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
config: {
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId: accessKey,
|
||||
secretAccessKey
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const memory = new BufferMemory({
|
||||
chatHistory: dynamoDb
|
||||
})
|
||||
return memory
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: DynamoDb_Memory }
|
||||
Reference in New Issue
Block a user