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';
|
documentationUrl = 'zep';
|
||||||
|
|
||||||
properties: INodeProperties[] = [
|
properties: INodeProperties[] = [
|
||||||
{
|
|
||||||
displayName: 'API URL',
|
|
||||||
name: 'apiUrl',
|
|
||||||
required: true,
|
|
||||||
type: 'string',
|
|
||||||
default: 'http://localhost:8000',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'API Key',
|
displayName: 'API Key',
|
||||||
name: 'apiKey',
|
name: 'apiKey',
|
||||||
|
@ -28,21 +21,41 @@ export class ZepApi implements ICredentialType {
|
||||||
required: false,
|
required: false,
|
||||||
default: '',
|
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 = {
|
authenticate: IAuthenticateGeneric = {
|
||||||
type: 'generic',
|
type: 'generic',
|
||||||
properties: {
|
properties: {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: '={{$credentials.apiKey ? "Bearer " + $credentials.apiKey : undefined }}',
|
Authorization:
|
||||||
|
'={{$credentials.apiKey && !$credentials.cloud ? "Bearer " + $credentials.apiKey : "Api-Key " + $credentials.apiKey }}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
test: ICredentialTestRequest = {
|
test: ICredentialTestRequest = {
|
||||||
request: {
|
request: {
|
||||||
baseURL: '={{$credentials.apiUrl}}',
|
baseURL: '={{!$credentials.cloud ? $credentials.apiUrl : "https://api.getzep.com"}}',
|
||||||
url: '/api/v1/collection',
|
url: '={{!$credentials.cloud ? "/api/v1/collection" : "/api/v2/collections"}}',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,29 @@ import {
|
||||||
type INodeType,
|
type INodeType,
|
||||||
type INodeTypeDescription,
|
type INodeTypeDescription,
|
||||||
type SupplyData,
|
type SupplyData,
|
||||||
|
NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { ZepMemory } from '@langchain/community/memory/zep';
|
import { ZepMemory } from '@langchain/community/memory/zep';
|
||||||
|
import { ZepCloudMemory } from '@langchain/community/memory/zep_cloud';
|
||||||
|
|
||||||
import { logWrapper } from '../../../utils/logWrapper';
|
import { logWrapper } from '../../../utils/logWrapper';
|
||||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||||
import { sessionIdOption, sessionKeyProperty } from '../descriptions';
|
import { sessionIdOption, sessionKeyProperty } from '../descriptions';
|
||||||
import { getSessionId } from '../../../utils/helpers';
|
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 {
|
export class MemoryZep implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -89,7 +106,8 @@ export class MemoryZep implements INodeType {
|
||||||
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
|
||||||
const credentials = (await this.getCredentials('zepApi')) as {
|
const credentials = (await this.getCredentials('zepApi')) as {
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
apiUrl: string;
|
apiUrl?: string;
|
||||||
|
cloud?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodeVersion = this.getNode().typeVersion;
|
const nodeVersion = this.getNode().typeVersion;
|
||||||
|
@ -102,7 +120,27 @@ export class MemoryZep implements INodeType {
|
||||||
sessionId = this.getNodeParameter('sessionId', itemIndex) as string;
|
sessionId = this.getNodeParameter('sessionId', itemIndex) as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memory = new ZepMemory({
|
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,
|
sessionId,
|
||||||
baseURL: credentials.apiUrl,
|
baseURL: credentials.apiUrl,
|
||||||
apiKey: credentials.apiKey,
|
apiKey: credentials.apiKey,
|
||||||
|
@ -111,6 +149,7 @@ export class MemoryZep implements INodeType {
|
||||||
inputKey: 'input',
|
inputKey: 'input',
|
||||||
outputKey: 'output',
|
outputKey: 'output',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response: logWrapper(memory, this),
|
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/client-bedrock-runtime": "3.535.0",
|
||||||
"@aws-sdk/credential-provider-node": "3.535.0",
|
"@aws-sdk/credential-provider-node": "3.535.0",
|
||||||
"@getzep/zep-js": "0.9.0",
|
"@getzep/zep-js": "0.9.0",
|
||||||
|
"@getzep/zep-cloud": "1.0.6",
|
||||||
"@google-ai/generativelanguage": "2.5.0",
|
"@google-ai/generativelanguage": "2.5.0",
|
||||||
"@google/generative-ai": "0.11.4",
|
"@google/generative-ai": "0.11.4",
|
||||||
"@huggingface/inference": "2.7.0",
|
"@huggingface/inference": "2.7.0",
|
||||||
"@langchain/anthropic": "0.1.21",
|
"@langchain/anthropic": "0.1.21",
|
||||||
"@langchain/cohere": "0.0.10",
|
"@langchain/cohere": "0.0.10",
|
||||||
"@langchain/community": "0.2.2",
|
"@langchain/community": "0.2.13",
|
||||||
"@langchain/core": "0.2.0",
|
"@langchain/core": "0.2.9",
|
||||||
"@langchain/google-genai": "0.0.16",
|
"@langchain/google-genai": "0.0.16",
|
||||||
"@langchain/groq": "0.0.12",
|
"@langchain/groq": "0.0.12",
|
||||||
"@langchain/mistralai": "0.0.22",
|
"@langchain/mistralai": "0.0.22",
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@langchain/community": "0.2.2",
|
"@langchain/community": "0.2.2",
|
||||||
"@langchain/core": "0.2.0",
|
"@langchain/core": "0.2.9",
|
||||||
"@langchain/openai": "0.0.33",
|
"@langchain/openai": "0.0.33",
|
||||||
"@langchain/pinecone": "0.0.6",
|
"@langchain/pinecone": "0.0.6",
|
||||||
"@n8n/client-oauth2": "workspace:*",
|
"@n8n/client-oauth2": "workspace:*",
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
"dist/**/*"
|
"dist/**/*"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@langchain/core": "^0.2.0",
|
"@langchain/core": "^0.2.9",
|
||||||
"@types/deep-equal": "^1.0.1",
|
"@types/deep-equal": "^1.0.1",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/jmespath": "^0.15.0",
|
"@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