-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Zep cloud setup #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Zep cloud setup #1760
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
76ac97f
wip
paul-paliychuk 29c86f7
feat: Update @qdrant/openapi-typescript-fetch resolution
paul-paliychuk 9da7a1b
feat: Finalize zep-cloud integration, update naming
paul-paliychuk aec0645
chore: Update labels + get rid of dev urls
paul-paliychuk 7728178
fix: Linter errors
paul-paliychuk 6819d5f
chore: Revert node names changes + update new node names to correct f…
paul-paliychuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,5 +53,8 @@ | |
| }, | ||
| "engines": { | ||
| "node": ">=18.15.0" | ||
| }, | ||
| "resolutions": { | ||
| "@qdrant/openapi-typescript-fetch": "1.2.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
packages/components/nodes/memory/ZepMemoryCloud/ZepMemoryCloud.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { IMessage, INode, INodeData, INodeParams, MemoryMethods, MessageType } from '../../../src/Interface' | ||
| import { convertBaseMessagetoIMessage, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
| import { ZepMemory, ZepMemoryInput } from '@getzep/zep-cloud/langchain' | ||
|
|
||
| import { ICommonObject } from '../../../src' | ||
| import { InputValues, MemoryVariables, OutputValues } from 'langchain/memory' | ||
| import { BaseMessage } from 'langchain/schema' | ||
|
|
||
| class ZepMemoryCloud_Memory implements INode { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| type: string | ||
| icon: string | ||
| category: string | ||
| baseClasses: string[] | ||
| credential: INodeParams | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Zep Memory - Cloud' | ||
| this.name = 'ZepMemoryCloud' | ||
| this.version = 2.0 | ||
| this.type = 'ZepMemory' | ||
| this.icon = 'zep.svg' | ||
| this.category = 'Memory' | ||
| this.description = 'Summarizes the conversation and stores the memory in zep server' | ||
| this.baseClasses = [this.type, ...getBaseClasses(ZepMemory)] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| optional: true, | ||
| description: 'Configure JWT authentication on your Zep instance (Optional)', | ||
| credentialNames: ['zepMemoryApi'] | ||
| } | ||
| this.inputs = [ | ||
| { | ||
| label: 'Session Id', | ||
| name: 'sessionId', | ||
| type: 'string', | ||
| description: | ||
| '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>', | ||
| default: '', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Memory Type', | ||
| name: 'memoryType', | ||
| type: 'string', | ||
| default: 'perpetual', | ||
| description: 'Zep Memory Type, can be perpetual or message_window', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'AI Prefix', | ||
| name: 'aiPrefix', | ||
| type: 'string', | ||
| default: 'ai', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Human Prefix', | ||
| name: 'humanPrefix', | ||
| type: 'string', | ||
| default: 'human', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Memory Key', | ||
| name: 'memoryKey', | ||
| type: 'string', | ||
| default: 'chat_history', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Input Key', | ||
| name: 'inputKey', | ||
| type: 'string', | ||
| default: 'input', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Output Key', | ||
| name: 'outputKey', | ||
| type: 'string', | ||
| default: 'text', | ||
| additionalParams: true | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| return await initializeZep(nodeData, options) | ||
| } | ||
| } | ||
|
|
||
| const initializeZep = async (nodeData: INodeData, options: ICommonObject): Promise<ZepMemory> => { | ||
| const aiPrefix = nodeData.inputs?.aiPrefix as string | ||
| const humanPrefix = nodeData.inputs?.humanPrefix as string | ||
| const memoryKey = nodeData.inputs?.memoryKey as string | ||
| const inputKey = nodeData.inputs?.inputKey as string | ||
|
|
||
| const memoryType = nodeData.inputs?.memoryType as 'perpetual' | 'message_window' | ||
| const sessionId = nodeData.inputs?.sessionId as string | ||
|
|
||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
| const obj: ZepMemoryInput & ZepMemoryExtendedInput = { | ||
| apiKey, | ||
| aiPrefix, | ||
| humanPrefix, | ||
| memoryKey, | ||
| sessionId, | ||
| inputKey, | ||
| memoryType: memoryType, | ||
| returnMessages: true | ||
| } | ||
|
|
||
| return new ZepMemoryExtended(obj) | ||
| } | ||
|
|
||
| interface ZepMemoryExtendedInput { | ||
| memoryType?: 'perpetual' | 'message_window' | ||
| } | ||
|
|
||
| class ZepMemoryExtended extends ZepMemory implements MemoryMethods { | ||
| memoryType: 'perpetual' | 'message_window' | ||
|
|
||
| constructor(fields: ZepMemoryInput & ZepMemoryExtendedInput) { | ||
| super(fields) | ||
| this.memoryType = fields.memoryType ?? 'perpetual' | ||
| } | ||
|
|
||
| async loadMemoryVariables(values: InputValues, overrideSessionId = ''): Promise<MemoryVariables> { | ||
| if (overrideSessionId) { | ||
| this.sessionId = overrideSessionId | ||
| } | ||
| return super.loadMemoryVariables({ ...values, memoryType: this.memoryType }) | ||
| } | ||
|
|
||
| async saveContext(inputValues: InputValues, outputValues: OutputValues, overrideSessionId = ''): Promise<void> { | ||
| if (overrideSessionId) { | ||
| this.sessionId = overrideSessionId | ||
| } | ||
| return super.saveContext(inputValues, outputValues) | ||
| } | ||
|
|
||
| async clear(overrideSessionId = ''): Promise<void> { | ||
| if (overrideSessionId) { | ||
| this.sessionId = overrideSessionId | ||
| } | ||
| return super.clear() | ||
| } | ||
|
|
||
| async getChatMessages(overrideSessionId = '', returnBaseMessages = false): Promise<IMessage[] | BaseMessage[]> { | ||
| const id = overrideSessionId ? overrideSessionId : this.sessionId | ||
| const memoryVariables = await this.loadMemoryVariables({}, id) | ||
| const baseMessages = memoryVariables[this.memoryKey] | ||
| return returnBaseMessages ? baseMessages : convertBaseMessagetoIMessage(baseMessages) | ||
| } | ||
|
|
||
| async addChatMessages(msgArray: { text: string; type: MessageType }[], overrideSessionId = ''): Promise<void> { | ||
| const id = overrideSessionId ? overrideSessionId : this.sessionId | ||
| const input = msgArray.find((msg) => msg.type === 'userMessage') | ||
| const output = msgArray.find((msg) => msg.type === 'apiMessage') | ||
| const inputValues = { [this.inputKey ?? 'input']: input?.text } | ||
| const outputValues = { output: output?.text } | ||
|
|
||
| await this.saveContext(inputValues, outputValues, id) | ||
| } | ||
|
|
||
| async clearChatMessages(overrideSessionId = ''): Promise<void> { | ||
| const id = overrideSessionId ? overrideSessionId : this.sessionId | ||
| await this.clear(id) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: ZepMemoryCloud_Memory } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of creating a new node, what do u think if we just add a new
optionsfield to theZepMemorythat allow users to select OpenSource or Cloud, then according to selection, use the respective library for initThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be doable, but I have some reservations.
Our interfaces are not the same for open source and cloud sdk. For memory, for example, we don't offer the ability to specify
memoryTypeon Open Source version, whereas this is one of the new things we have introduced with Zep Cloud. The same applies to vector stores, in cloud fro example we don't accept embeddings and embedding dimensions any more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we would have to have a lot of additional if blocks in the nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay i thought the difference is only the initialization. In that case, make sense to have separate nodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Marked it as ready for review then!