mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
feat: Add Zep Cloud Memory component (#9657)
This commit is contained in:
parent
55cbc900a4
commit
41c47a28a9
|
@ -13,13 +13,6 @@ export class ZepApi implements ICredentialType {
|
|||
documentationUrl = 'zep';
|
||||
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'API URL',
|
||||
name: 'apiUrl',
|
||||
required: true,
|
||||
type: 'string',
|
||||
default: 'http://localhost:8000',
|
||||
},
|
||||
{
|
||||
displayName: 'API Key',
|
||||
name: 'apiKey',
|
||||
|
@ -28,21 +21,41 @@ export class ZepApi implements ICredentialType {
|
|||
required: false,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Cloud',
|
||||
description: 'Whether you are adding credentials for Zep Cloud instead of Zep Open Source',
|
||||
name: 'cloud',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'API URL',
|
||||
name: 'apiUrl',
|
||||
required: false,
|
||||
type: 'string',
|
||||
default: 'http://localhost:8000',
|
||||
displayOptions: {
|
||||
show: {
|
||||
cloud: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
authenticate: IAuthenticateGeneric = {
|
||||
type: 'generic',
|
||||
properties: {
|
||||
headers: {
|
||||
Authorization: '={{$credentials.apiKey ? "Bearer " + $credentials.apiKey : undefined }}',
|
||||
Authorization:
|
||||
'={{$credentials.apiKey && !$credentials.cloud ? "Bearer " + $credentials.apiKey : "Api-Key " + $credentials.apiKey }}',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
baseURL: '={{$credentials.apiUrl}}',
|
||||
url: '/api/v1/collection',
|
||||
baseURL: '={{!$credentials.cloud ? $credentials.apiUrl : "https://api.getzep.com"}}',
|
||||
url: '={{!$credentials.cloud ? "/api/v1/collection" : "/api/v2/collections"}}',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,12 +5,29 @@ import {
|
|||
type INodeType,
|
||||
type INodeTypeDescription,
|
||||
type SupplyData,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import { ZepMemory } from '@langchain/community/memory/zep';
|
||||
import { ZepCloudMemory } from '@langchain/community/memory/zep_cloud';
|
||||
|
||||
import { logWrapper } from '../../../utils/logWrapper';
|
||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||
import { sessionIdOption, sessionKeyProperty } from '../descriptions';
|
||||
import { getSessionId } from '../../../utils/helpers';
|
||||
import type { BaseChatMemory } from '@langchain/community/dist/memory/chat_memory';
|
||||
import type { InputValues, MemoryVariables } from '@langchain/core/memory';
|
||||
import type { BaseMessage } from '@langchain/core/messages';
|
||||
|
||||
// Extend ZepCloudMemory to trim white space in messages.
|
||||
class WhiteSpaceTrimmedZepCloudMemory extends ZepCloudMemory {
|
||||
override async loadMemoryVariables(values: InputValues): Promise<MemoryVariables> {
|
||||
const memoryVariables = await super.loadMemoryVariables(values);
|
||||
memoryVariables.chat_history = memoryVariables.chat_history.filter((m: BaseMessage) =>
|
||||
m.content.toString().trim(),
|
||||
);
|
||||
return memoryVariables;
|
||||
}
|
||||
}
|
||||
|
||||
export class MemoryZep implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
|
@ -89,7 +106,8 @@ export class MemoryZep implements INodeType {
|
|||
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
||||
const credentials = (await this.getCredentials('zepApi')) as {
|
||||
apiKey?: string;
|
||||
apiUrl: string;
|
||||
apiUrl?: string;
|
||||
cloud?: boolean;
|
||||
};
|
||||
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
|
@ -102,15 +120,36 @@ export class MemoryZep implements INodeType {
|
|||
sessionId = this.getNodeParameter('sessionId', itemIndex) as string;
|
||||
}
|
||||
|
||||
const memory = new ZepMemory({
|
||||
sessionId,
|
||||
baseURL: credentials.apiUrl,
|
||||
apiKey: credentials.apiKey,
|
||||
memoryKey: 'chat_history',
|
||||
returnMessages: true,
|
||||
inputKey: 'input',
|
||||
outputKey: 'output',
|
||||
});
|
||||
let memory: BaseChatMemory;
|
||||
|
||||
if (credentials.cloud) {
|
||||
if (!credentials.apiKey) {
|
||||
throw new NodeOperationError(this.getNode(), 'API key is required to use Zep Cloud');
|
||||
}
|
||||
memory = new WhiteSpaceTrimmedZepCloudMemory({
|
||||
sessionId,
|
||||
apiKey: credentials.apiKey,
|
||||
memoryType: 'perpetual',
|
||||
memoryKey: 'chat_history',
|
||||
returnMessages: true,
|
||||
inputKey: 'input',
|
||||
outputKey: 'output',
|
||||
separateMessages: false,
|
||||
});
|
||||
} else {
|
||||
if (!credentials.apiUrl) {
|
||||
throw new NodeOperationError(this.getNode(), 'API url is required to use Zep Open Source');
|
||||
}
|
||||
memory = new ZepMemory({
|
||||
sessionId,
|
||||
baseURL: credentials.apiUrl,
|
||||
apiKey: credentials.apiKey,
|
||||
memoryKey: 'chat_history',
|
||||
returnMessages: true,
|
||||
inputKey: 'input',
|
||||
outputKey: 'output',
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
response: logWrapper(memory, this),
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 6.5 KiB |
|
@ -135,13 +135,14 @@
|
|||
"@aws-sdk/client-bedrock-runtime": "3.535.0",
|
||||
"@aws-sdk/credential-provider-node": "3.535.0",
|
||||
"@getzep/zep-js": "0.9.0",
|
||||
"@getzep/zep-cloud": "1.0.6",
|
||||
"@google-ai/generativelanguage": "2.5.0",
|
||||
"@google/generative-ai": "0.11.4",
|
||||
"@huggingface/inference": "2.7.0",
|
||||
"@langchain/anthropic": "0.1.21",
|
||||
"@langchain/cohere": "0.0.10",
|
||||
"@langchain/community": "0.2.2",
|
||||
"@langchain/core": "0.2.0",
|
||||
"@langchain/community": "0.2.13",
|
||||
"@langchain/core": "0.2.9",
|
||||
"@langchain/google-genai": "0.0.16",
|
||||
"@langchain/groq": "0.0.12",
|
||||
"@langchain/mistralai": "0.0.22",
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@langchain/community": "0.2.2",
|
||||
"@langchain/core": "0.2.0",
|
||||
"@langchain/core": "0.2.9",
|
||||
"@langchain/openai": "0.0.33",
|
||||
"@langchain/pinecone": "0.0.6",
|
||||
"@n8n/client-oauth2": "workspace:*",
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"dist/**/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@langchain/core": "^0.2.0",
|
||||
"@langchain/core": "^0.2.9",
|
||||
"@types/deep-equal": "^1.0.1",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/jmespath": "^0.15.0",
|
||||
|
|
1114
pnpm-lock.yaml
1114
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue