Skip to content

Commit 89307b1

Browse files
authored
Merge pull request #1760 from getzep/zep-cloud-setup
Zep cloud setup
2 parents 850e506 + 6819d5f commit 89307b1

File tree

9 files changed

+457
-6
lines changed

9 files changed

+457
-6
lines changed

packages/components/nodes/memory/ZepMemory/ZepMemory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ZepMemory_Memory implements INode {
1717
inputs: INodeParams[]
1818

1919
constructor() {
20-
this.label = 'Zep Memory'
20+
this.label = 'Zep Memory - Open Source'
2121
this.name = 'ZepMemory'
2222
this.version = 2.0
2323
this.type = 'ZepMemory'
@@ -97,11 +97,11 @@ class ZepMemory_Memory implements INode {
9797
}
9898

9999
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
100-
return await initalizeZep(nodeData, options)
100+
return await initializeZep(nodeData, options)
101101
}
102102
}
103103

104-
const initalizeZep = async (nodeData: INodeData, options: ICommonObject): Promise<ZepMemory> => {
104+
const initializeZep = async (nodeData: INodeData, options: ICommonObject): Promise<ZepMemory> => {
105105
const baseURL = nodeData.inputs?.baseURL as string
106106
const aiPrefix = nodeData.inputs?.aiPrefix as string
107107
const humanPrefix = nodeData.inputs?.humanPrefix as string
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import { IMessage, INode, INodeData, INodeParams, MemoryMethods, MessageType } from '../../../src/Interface'
2+
import { convertBaseMessagetoIMessage, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
3+
import { ZepMemory, ZepMemoryInput } from '@getzep/zep-cloud/langchain'
4+
5+
import { ICommonObject } from '../../../src'
6+
import { InputValues, MemoryVariables, OutputValues } from 'langchain/memory'
7+
import { BaseMessage } from 'langchain/schema'
8+
9+
class ZepMemoryCloud_Memory implements INode {
10+
label: string
11+
name: string
12+
version: number
13+
description: string
14+
type: string
15+
icon: string
16+
category: string
17+
baseClasses: string[]
18+
credential: INodeParams
19+
inputs: INodeParams[]
20+
21+
constructor() {
22+
this.label = 'Zep Memory - Cloud'
23+
this.name = 'ZepMemoryCloud'
24+
this.version = 2.0
25+
this.type = 'ZepMemory'
26+
this.icon = 'zep.svg'
27+
this.category = 'Memory'
28+
this.description = 'Summarizes the conversation and stores the memory in zep server'
29+
this.baseClasses = [this.type, ...getBaseClasses(ZepMemory)]
30+
this.credential = {
31+
label: 'Connect Credential',
32+
name: 'credential',
33+
type: 'credential',
34+
optional: true,
35+
description: 'Configure JWT authentication on your Zep instance (Optional)',
36+
credentialNames: ['zepMemoryApi']
37+
}
38+
this.inputs = [
39+
{
40+
label: 'Session Id',
41+
name: 'sessionId',
42+
type: 'string',
43+
description:
44+
'If not specified, a random id will be used. Learn <a target="_blank" href="https://docs.flowiseai.com/memory/long-term-memory#ui-and-embedded-chat">more</a>',
45+
default: '',
46+
additionalParams: true,
47+
optional: true
48+
},
49+
{
50+
label: 'Memory Type',
51+
name: 'memoryType',
52+
type: 'string',
53+
default: 'perpetual',
54+
description: 'Zep Memory Type, can be perpetual or message_window',
55+
additionalParams: true
56+
},
57+
{
58+
label: 'AI Prefix',
59+
name: 'aiPrefix',
60+
type: 'string',
61+
default: 'ai',
62+
additionalParams: true
63+
},
64+
{
65+
label: 'Human Prefix',
66+
name: 'humanPrefix',
67+
type: 'string',
68+
default: 'human',
69+
additionalParams: true
70+
},
71+
{
72+
label: 'Memory Key',
73+
name: 'memoryKey',
74+
type: 'string',
75+
default: 'chat_history',
76+
additionalParams: true
77+
},
78+
{
79+
label: 'Input Key',
80+
name: 'inputKey',
81+
type: 'string',
82+
default: 'input',
83+
additionalParams: true
84+
},
85+
{
86+
label: 'Output Key',
87+
name: 'outputKey',
88+
type: 'string',
89+
default: 'text',
90+
additionalParams: true
91+
}
92+
]
93+
}
94+
95+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
96+
return await initializeZep(nodeData, options)
97+
}
98+
}
99+
100+
const initializeZep = async (nodeData: INodeData, options: ICommonObject): Promise<ZepMemory> => {
101+
const aiPrefix = nodeData.inputs?.aiPrefix as string
102+
const humanPrefix = nodeData.inputs?.humanPrefix as string
103+
const memoryKey = nodeData.inputs?.memoryKey as string
104+
const inputKey = nodeData.inputs?.inputKey as string
105+
106+
const memoryType = nodeData.inputs?.memoryType as 'perpetual' | 'message_window'
107+
const sessionId = nodeData.inputs?.sessionId as string
108+
109+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
110+
const apiKey = getCredentialParam('apiKey', credentialData, nodeData)
111+
const obj: ZepMemoryInput & ZepMemoryExtendedInput = {
112+
apiKey,
113+
aiPrefix,
114+
humanPrefix,
115+
memoryKey,
116+
sessionId,
117+
inputKey,
118+
memoryType: memoryType,
119+
returnMessages: true
120+
}
121+
122+
return new ZepMemoryExtended(obj)
123+
}
124+
125+
interface ZepMemoryExtendedInput {
126+
memoryType?: 'perpetual' | 'message_window'
127+
}
128+
129+
class ZepMemoryExtended extends ZepMemory implements MemoryMethods {
130+
memoryType: 'perpetual' | 'message_window'
131+
132+
constructor(fields: ZepMemoryInput & ZepMemoryExtendedInput) {
133+
super(fields)
134+
this.memoryType = fields.memoryType ?? 'perpetual'
135+
}
136+
137+
async loadMemoryVariables(values: InputValues, overrideSessionId = ''): Promise<MemoryVariables> {
138+
if (overrideSessionId) {
139+
this.sessionId = overrideSessionId
140+
}
141+
return super.loadMemoryVariables({ ...values, memoryType: this.memoryType })
142+
}
143+
144+
async saveContext(inputValues: InputValues, outputValues: OutputValues, overrideSessionId = ''): Promise<void> {
145+
if (overrideSessionId) {
146+
this.sessionId = overrideSessionId
147+
}
148+
return super.saveContext(inputValues, outputValues)
149+
}
150+
151+
async clear(overrideSessionId = ''): Promise<void> {
152+
if (overrideSessionId) {
153+
this.sessionId = overrideSessionId
154+
}
155+
return super.clear()
156+
}
157+
158+
async getChatMessages(overrideSessionId = '', returnBaseMessages = false): Promise<IMessage[] | BaseMessage[]> {
159+
const id = overrideSessionId ? overrideSessionId : this.sessionId
160+
const memoryVariables = await this.loadMemoryVariables({}, id)
161+
const baseMessages = memoryVariables[this.memoryKey]
162+
return returnBaseMessages ? baseMessages : convertBaseMessagetoIMessage(baseMessages)
163+
}
164+
165+
async addChatMessages(msgArray: { text: string; type: MessageType }[], overrideSessionId = ''): Promise<void> {
166+
const id = overrideSessionId ? overrideSessionId : this.sessionId
167+
const input = msgArray.find((msg) => msg.type === 'userMessage')
168+
const output = msgArray.find((msg) => msg.type === 'apiMessage')
169+
const inputValues = { [this.inputKey ?? 'input']: input?.text }
170+
const outputValues = { output: output?.text }
171+
172+
await this.saveContext(inputValues, outputValues, id)
173+
}
174+
175+
async clearChatMessages(overrideSessionId = ''): Promise<void> {
176+
const id = overrideSessionId ? overrideSessionId : this.sessionId
177+
await this.clear(id)
178+
}
179+
}
180+
181+
module.exports = { nodeClass: ZepMemoryCloud_Memory }
Lines changed: 19 additions & 0 deletions
Loading

packages/components/nodes/vectorstores/Zep/Zep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Zep_VectorStores implements INode {
2222
outputs: INodeOutputsValue[]
2323

2424
constructor() {
25-
this.label = 'Zep'
25+
this.label = 'Zep Collection - Open Source'
2626
this.name = 'zep'
2727
this.version = 2.0
2828
this.type = 'Zep'

packages/components/nodes/vectorstores/Zep/Zep_Existing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Zep_Existing_VectorStores implements INode {
2020
outputs: INodeOutputsValue[]
2121

2222
constructor() {
23-
this.label = 'Zep Load Existing Index'
23+
this.label = 'Zep Load Existing Index - Open Source'
2424
this.name = 'zepExistingIndex'
2525
this.version = 1.0
2626
this.type = 'Zep'

packages/components/nodes/vectorstores/Zep/Zep_Upsert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Zep_Upsert_VectorStores implements INode {
2020
outputs: INodeOutputsValue[]
2121

2222
constructor() {
23-
this.label = 'Zep Upsert Document'
23+
this.label = 'Zep Upsert Document - Open Source'
2424
this.name = 'zepUpsert'
2525
this.version = 1.0
2626
this.type = 'Zep'

0 commit comments

Comments
 (0)