add Buffer Window Memory

This commit is contained in:
chungyau97 2023-05-23 21:34:37 +07:00
parent 8d45412c38
commit f8232bd201
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,61 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { BufferWindowMemory, BufferWindowMemoryInput } from 'langchain/memory'
class BufferWindowMemory_Memory implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]
constructor() {
this.label = 'Buffer Window Memory'
this.name = 'bufferWindowMemory'
this.type = 'BufferWindowMemory'
this.icon = 'memory.svg'
this.category = 'Memory'
this.description = 'Uses a window of size k to surface the last k back-and-forths to use as memory'
this.baseClasses = [this.type, ...getBaseClasses(BufferWindowMemory)]
this.inputs = [
{
label: 'Memory Key',
name: 'memoryKey',
type: 'string',
default: 'chat_history'
},
{
label: 'Input Key',
name: 'inputKey',
type: 'string',
default: 'input'
},
{
label: 'Size',
name: 'k',
type: 'number',
default: '4'
}
]
}
async init(nodeData: INodeData): Promise<any> {
const memoryKey = nodeData.inputs?.memoryKey as string
const inputKey = nodeData.inputs?.inputKey as string
const k = nodeData.inputs?.k as string
const obj: Partial<BufferWindowMemoryInput> = {
returnMessages: true,
memoryKey: memoryKey,
inputKey: inputKey,
k: parseInt(k, 10)
}
return new BufferWindowMemory(obj)
}
}
module.exports = { nodeClass: BufferWindowMemory_Memory }

View File

@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-book" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0"></path>
<path d="M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0"></path>
<path d="M3 6l0 13"></path>
<path d="M12 6l0 13"></path>
<path d="M21 6l0 13"></path>
</svg>

After

Width:  |  Height:  |  Size: 495 B