langchain 0.0.204-rc.0 → 0.0.204-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/toolkits/aws_sfn.cjs +3 -75
- package/dist/agents/toolkits/aws_sfn.d.ts +2 -45
- package/dist/agents/toolkits/aws_sfn.js +2 -73
- package/dist/agents/toolkits/base.cjs +15 -9
- package/dist/agents/toolkits/base.d.ts +1 -9
- package/dist/agents/toolkits/base.js +1 -7
- package/dist/agents/toolkits/connery/index.cjs +15 -37
- package/dist/agents/toolkits/connery/index.d.ts +1 -23
- package/dist/agents/toolkits/connery/index.js +1 -35
- package/dist/cache/ioredis.cjs +15 -77
- package/dist/cache/ioredis.d.ts +1 -40
- package/dist/cache/ioredis.js +1 -75
- package/dist/memory/chat_memory.cjs +15 -61
- package/dist/memory/chat_memory.d.ts +1 -36
- package/dist/memory/chat_memory.js +1 -59
- package/dist/memory/motorhead_memory.cjs +15 -161
- package/dist/memory/motorhead_memory.d.ts +1 -63
- package/dist/memory/motorhead_memory.js +1 -159
- package/dist/memory/zep.cjs +15 -222
- package/dist/memory/zep.d.ts +1 -86
- package/dist/memory/zep.js +1 -220
- package/dist/stores/message/in_memory.cjs +15 -49
- package/dist/stores/message/in_memory.d.ts +1 -28
- package/dist/stores/message/in_memory.js +1 -47
- package/dist/tools/aws_lambda.cjs +15 -83
- package/dist/tools/aws_lambda.d.ts +1 -25
- package/dist/tools/aws_lambda.js +1 -82
- package/dist/tools/dynamic.cjs +15 -87
- package/dist/tools/dynamic.d.ts +1 -48
- package/dist/tools/dynamic.js +1 -84
- package/dist/util/convex.cjs +15 -75
- package/dist/util/convex.d.ts +1 -26
- package/dist/util/convex.js +1 -74
- package/dist/vectorstores/memory.cjs +143 -15
- package/dist/vectorstores/memory.d.ts +92 -1
- package/dist/vectorstores/memory.js +141 -1
- package/package.json +2 -241
- package/dist/util/chunk.cjs +0 -11
- package/dist/util/chunk.d.ts +0 -1
- package/dist/util/chunk.js +0 -7
- package/dist/util/googlevertexai-gauth.cjs +0 -36
- package/dist/util/googlevertexai-gauth.d.ts +0 -8
- package/dist/util/googlevertexai-gauth.js +0 -32
- package/dist/util/googlevertexai-webauth.cjs +0 -96
- package/dist/util/googlevertexai-webauth.d.ts +0 -22
- package/dist/util/googlevertexai-webauth.js +0 -92
- package/dist/util/iflytek_websocket_stream.cjs +0 -81
- package/dist/util/iflytek_websocket_stream.d.ts +0 -27
- package/dist/util/iflytek_websocket_stream.js +0 -77
- package/dist/util/llama_cpp.cjs +0 -34
- package/dist/util/llama_cpp.d.ts +0 -46
- package/dist/util/llama_cpp.js +0 -28
- package/dist/util/momento.cjs +0 -26
- package/dist/util/momento.d.ts +0 -9
- package/dist/util/momento.js +0 -22
package/dist/memory/zep.cjs
CHANGED
|
@@ -1,224 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const index_js_1 = require("../schema/index.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* Class used to manage the memory of a chat session, including loading
|
|
10
|
-
* and saving the chat history, and clearing the memory when needed. It
|
|
11
|
-
* uses the ZepClient to interact with the Zep service for managing the
|
|
12
|
-
* chat session's memory.
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const sessionId = randomUUID();
|
|
16
|
-
* const zepURL = "http://your-zep-url";
|
|
17
|
-
*
|
|
18
|
-
* // Initialize ZepMemory with session ID, base URL, and API key
|
|
19
|
-
* const memory = new ZepMemory({
|
|
20
|
-
* sessionId,
|
|
21
|
-
* baseURL: zepURL,
|
|
22
|
-
* apiKey: "change_this_key",
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* // Create a ChatOpenAI model instance with specific parameters
|
|
26
|
-
* const model = new ChatOpenAI({
|
|
27
|
-
* modelName: "gpt-3.5-turbo",
|
|
28
|
-
* temperature: 0,
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* // Create a ConversationChain with the model and memory
|
|
32
|
-
* const chain = new ConversationChain({ llm: model, memory });
|
|
33
|
-
*
|
|
34
|
-
* // Example of calling the chain with an input
|
|
35
|
-
* const res1 = await chain.call({ input: "Hi! I'm Jim." });
|
|
36
|
-
* console.log({ res1 });
|
|
37
|
-
*
|
|
38
|
-
* // Follow-up call to the chain to demonstrate memory usage
|
|
39
|
-
* const res2 = await chain.call({ input: "What did I just say my name was?" });
|
|
40
|
-
* console.log({ res2 });
|
|
41
|
-
*
|
|
42
|
-
* // Output the session ID and the current state of memory
|
|
43
|
-
* console.log("Session ID: ", sessionId);
|
|
44
|
-
* console.log("Memory: ", await memory.loadMemoryVariables({}));
|
|
45
|
-
*
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
class ZepMemory extends chat_memory_js_1.BaseChatMemory {
|
|
49
|
-
constructor(fields) {
|
|
50
|
-
super({
|
|
51
|
-
returnMessages: fields?.returnMessages ?? false,
|
|
52
|
-
inputKey: fields?.inputKey,
|
|
53
|
-
outputKey: fields?.outputKey,
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "humanPrefix", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: "Human"
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, "aiPrefix", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: "AI"
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, "memoryKey", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: "history"
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "baseURL", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: void 0
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, "sessionId", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: void 0
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(this, "zepClientPromise", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
configurable: true,
|
|
88
|
-
writable: true,
|
|
89
|
-
value: void 0
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(this, "zepInitFailMsg", {
|
|
92
|
-
enumerable: true,
|
|
93
|
-
configurable: true,
|
|
94
|
-
writable: true,
|
|
95
|
-
value: "ZepClient is not initialized"
|
|
96
|
-
});
|
|
97
|
-
this.humanPrefix = fields.humanPrefix ?? this.humanPrefix;
|
|
98
|
-
this.aiPrefix = fields.aiPrefix ?? this.aiPrefix;
|
|
99
|
-
this.memoryKey = fields.memoryKey ?? this.memoryKey;
|
|
100
|
-
this.baseURL = fields.baseURL;
|
|
101
|
-
this.sessionId = fields.sessionId;
|
|
102
|
-
this.zepClientPromise = zep_js_1.ZepClient.init(this.baseURL, fields.apiKey);
|
|
103
|
-
}
|
|
104
|
-
get memoryKeys() {
|
|
105
|
-
return [this.memoryKey];
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Method that retrieves the chat history from the Zep service and formats
|
|
109
|
-
* it into a list of messages.
|
|
110
|
-
* @param values Input values for the method.
|
|
111
|
-
* @returns Promise that resolves with the chat history formatted into a list of messages.
|
|
112
|
-
*/
|
|
113
|
-
async loadMemoryVariables(values) {
|
|
114
|
-
// use either lastN provided by developer or undefined to use the
|
|
115
|
-
// server preset.
|
|
116
|
-
// Wait for ZepClient to be initialized
|
|
117
|
-
const zepClient = await this.zepClientPromise;
|
|
118
|
-
if (!zepClient) {
|
|
119
|
-
throw new Error(this.zepInitFailMsg);
|
|
120
|
-
}
|
|
121
|
-
const lastN = values.lastN ?? undefined;
|
|
122
|
-
let memory = null;
|
|
123
|
-
try {
|
|
124
|
-
memory = await zepClient.memory.getMemory(this.sessionId, lastN);
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
128
|
-
if (error instanceof zep_js_1.NotFoundError) {
|
|
129
|
-
const result = this.returnMessages
|
|
130
|
-
? { [this.memoryKey]: [] }
|
|
131
|
-
: { [this.memoryKey]: "" };
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
let messages = memory && memory.summary?.content
|
|
139
|
-
? [new index_js_1.SystemMessage(memory.summary.content)]
|
|
140
|
-
: [];
|
|
141
|
-
if (memory) {
|
|
142
|
-
messages = messages.concat(memory.messages.map((message) => {
|
|
143
|
-
const { content, role } = message;
|
|
144
|
-
if (role === this.humanPrefix) {
|
|
145
|
-
return new index_js_1.HumanMessage(content);
|
|
146
|
-
}
|
|
147
|
-
else if (role === this.aiPrefix) {
|
|
148
|
-
return new index_js_1.AIMessage(content);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
// default to generic ChatMessage
|
|
152
|
-
return new index_js_1.ChatMessage(content, role);
|
|
153
|
-
}
|
|
154
|
-
}));
|
|
155
|
-
}
|
|
156
|
-
if (this.returnMessages) {
|
|
157
|
-
return {
|
|
158
|
-
[this.memoryKey]: messages,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
[this.memoryKey]: (0, base_js_1.getBufferString)(messages, this.humanPrefix, this.aiPrefix),
|
|
163
|
-
};
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
164
7
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const memory = new zep_js_1.Memory({
|
|
176
|
-
messages: [
|
|
177
|
-
new zep_js_1.Message({
|
|
178
|
-
role: this.humanPrefix,
|
|
179
|
-
content: `${input}`,
|
|
180
|
-
}),
|
|
181
|
-
new zep_js_1.Message({
|
|
182
|
-
role: this.aiPrefix,
|
|
183
|
-
content: `${output}`,
|
|
184
|
-
}),
|
|
185
|
-
],
|
|
186
|
-
});
|
|
187
|
-
// Wait for ZepClient to be initialized
|
|
188
|
-
const zepClient = await this.zepClientPromise;
|
|
189
|
-
if (!zepClient) {
|
|
190
|
-
throw new Error(this.zepInitFailMsg);
|
|
191
|
-
}
|
|
192
|
-
// Add the new memory to the session using the ZepClient
|
|
193
|
-
if (this.sessionId) {
|
|
194
|
-
try {
|
|
195
|
-
await zepClient.memory.addMemory(this.sessionId, memory);
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
console.error("Error adding memory: ", error);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// Call the superclass's saveContext method
|
|
202
|
-
await super.saveContext(inputValues, outputValues);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Method that deletes the chat history from the Zep service.
|
|
206
|
-
* @returns Promise that resolves when the chat history has been deleted.
|
|
207
|
-
*/
|
|
208
|
-
async clear() {
|
|
209
|
-
// Wait for ZepClient to be initialized
|
|
210
|
-
const zepClient = await this.zepClientPromise;
|
|
211
|
-
if (!zepClient) {
|
|
212
|
-
throw new Error(this.zepInitFailMsg);
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
await zepClient.memory.deleteMemory(this.sessionId);
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
console.error("Error deleting session: ", error);
|
|
219
|
-
}
|
|
220
|
-
// Clear the superclass's chat history
|
|
221
|
-
await super.clear();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.ZepMemory = ZepMemory;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@langchain/community/memory/zep"), exports);
|
package/dist/memory/zep.d.ts
CHANGED
|
@@ -1,86 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { InputValues, MemoryVariables, OutputValues } from "./base.js";
|
|
3
|
-
import { BaseChatMemory, BaseChatMemoryInput } from "./chat_memory.js";
|
|
4
|
-
/**
|
|
5
|
-
* Interface defining the structure of the input data for the ZepMemory
|
|
6
|
-
* class. It includes properties like humanPrefix, aiPrefix, memoryKey,
|
|
7
|
-
* baseURL, sessionId, and apiKey.
|
|
8
|
-
*/
|
|
9
|
-
export interface ZepMemoryInput extends BaseChatMemoryInput {
|
|
10
|
-
humanPrefix?: string;
|
|
11
|
-
aiPrefix?: string;
|
|
12
|
-
memoryKey?: string;
|
|
13
|
-
baseURL: string;
|
|
14
|
-
sessionId: string;
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Class used to manage the memory of a chat session, including loading
|
|
19
|
-
* and saving the chat history, and clearing the memory when needed. It
|
|
20
|
-
* uses the ZepClient to interact with the Zep service for managing the
|
|
21
|
-
* chat session's memory.
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const sessionId = randomUUID();
|
|
25
|
-
* const zepURL = "http://your-zep-url";
|
|
26
|
-
*
|
|
27
|
-
* // Initialize ZepMemory with session ID, base URL, and API key
|
|
28
|
-
* const memory = new ZepMemory({
|
|
29
|
-
* sessionId,
|
|
30
|
-
* baseURL: zepURL,
|
|
31
|
-
* apiKey: "change_this_key",
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // Create a ChatOpenAI model instance with specific parameters
|
|
35
|
-
* const model = new ChatOpenAI({
|
|
36
|
-
* modelName: "gpt-3.5-turbo",
|
|
37
|
-
* temperature: 0,
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* // Create a ConversationChain with the model and memory
|
|
41
|
-
* const chain = new ConversationChain({ llm: model, memory });
|
|
42
|
-
*
|
|
43
|
-
* // Example of calling the chain with an input
|
|
44
|
-
* const res1 = await chain.call({ input: "Hi! I'm Jim." });
|
|
45
|
-
* console.log({ res1 });
|
|
46
|
-
*
|
|
47
|
-
* // Follow-up call to the chain to demonstrate memory usage
|
|
48
|
-
* const res2 = await chain.call({ input: "What did I just say my name was?" });
|
|
49
|
-
* console.log({ res2 });
|
|
50
|
-
*
|
|
51
|
-
* // Output the session ID and the current state of memory
|
|
52
|
-
* console.log("Session ID: ", sessionId);
|
|
53
|
-
* console.log("Memory: ", await memory.loadMemoryVariables({}));
|
|
54
|
-
*
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare class ZepMemory extends BaseChatMemory implements ZepMemoryInput {
|
|
58
|
-
humanPrefix: string;
|
|
59
|
-
aiPrefix: string;
|
|
60
|
-
memoryKey: string;
|
|
61
|
-
baseURL: string;
|
|
62
|
-
sessionId: string;
|
|
63
|
-
zepClientPromise: Promise<ZepClient>;
|
|
64
|
-
private readonly zepInitFailMsg;
|
|
65
|
-
constructor(fields: ZepMemoryInput);
|
|
66
|
-
get memoryKeys(): string[];
|
|
67
|
-
/**
|
|
68
|
-
* Method that retrieves the chat history from the Zep service and formats
|
|
69
|
-
* it into a list of messages.
|
|
70
|
-
* @param values Input values for the method.
|
|
71
|
-
* @returns Promise that resolves with the chat history formatted into a list of messages.
|
|
72
|
-
*/
|
|
73
|
-
loadMemoryVariables(values: InputValues): Promise<MemoryVariables>;
|
|
74
|
-
/**
|
|
75
|
-
* Method that saves the input and output messages to the Zep service.
|
|
76
|
-
* @param inputValues Input messages to be saved.
|
|
77
|
-
* @param outputValues Output messages to be saved.
|
|
78
|
-
* @returns Promise that resolves when the messages have been saved.
|
|
79
|
-
*/
|
|
80
|
-
saveContext(inputValues: InputValues, outputValues: OutputValues): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Method that deletes the chat history from the Zep service.
|
|
83
|
-
* @returns Promise that resolves when the chat history has been deleted.
|
|
84
|
-
*/
|
|
85
|
-
clear(): Promise<void>;
|
|
86
|
-
}
|
|
1
|
+
export * from "@langchain/community/memory/zep";
|
package/dist/memory/zep.js
CHANGED
|
@@ -1,220 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { getBufferString, getInputValue, getOutputValue, } from "./base.js";
|
|
3
|
-
import { BaseChatMemory } from "./chat_memory.js";
|
|
4
|
-
import { AIMessage, ChatMessage, HumanMessage, SystemMessage, } from "../schema/index.js";
|
|
5
|
-
/**
|
|
6
|
-
* Class used to manage the memory of a chat session, including loading
|
|
7
|
-
* and saving the chat history, and clearing the memory when needed. It
|
|
8
|
-
* uses the ZepClient to interact with the Zep service for managing the
|
|
9
|
-
* chat session's memory.
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const sessionId = randomUUID();
|
|
13
|
-
* const zepURL = "http://your-zep-url";
|
|
14
|
-
*
|
|
15
|
-
* // Initialize ZepMemory with session ID, base URL, and API key
|
|
16
|
-
* const memory = new ZepMemory({
|
|
17
|
-
* sessionId,
|
|
18
|
-
* baseURL: zepURL,
|
|
19
|
-
* apiKey: "change_this_key",
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Create a ChatOpenAI model instance with specific parameters
|
|
23
|
-
* const model = new ChatOpenAI({
|
|
24
|
-
* modelName: "gpt-3.5-turbo",
|
|
25
|
-
* temperature: 0,
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* // Create a ConversationChain with the model and memory
|
|
29
|
-
* const chain = new ConversationChain({ llm: model, memory });
|
|
30
|
-
*
|
|
31
|
-
* // Example of calling the chain with an input
|
|
32
|
-
* const res1 = await chain.call({ input: "Hi! I'm Jim." });
|
|
33
|
-
* console.log({ res1 });
|
|
34
|
-
*
|
|
35
|
-
* // Follow-up call to the chain to demonstrate memory usage
|
|
36
|
-
* const res2 = await chain.call({ input: "What did I just say my name was?" });
|
|
37
|
-
* console.log({ res2 });
|
|
38
|
-
*
|
|
39
|
-
* // Output the session ID and the current state of memory
|
|
40
|
-
* console.log("Session ID: ", sessionId);
|
|
41
|
-
* console.log("Memory: ", await memory.loadMemoryVariables({}));
|
|
42
|
-
*
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export class ZepMemory extends BaseChatMemory {
|
|
46
|
-
constructor(fields) {
|
|
47
|
-
super({
|
|
48
|
-
returnMessages: fields?.returnMessages ?? false,
|
|
49
|
-
inputKey: fields?.inputKey,
|
|
50
|
-
outputKey: fields?.outputKey,
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "humanPrefix", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: "Human"
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(this, "aiPrefix", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: "AI"
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(this, "memoryKey", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: "history"
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(this, "baseURL", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: void 0
|
|
75
|
-
});
|
|
76
|
-
Object.defineProperty(this, "sessionId", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
configurable: true,
|
|
79
|
-
writable: true,
|
|
80
|
-
value: void 0
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(this, "zepClientPromise", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: true,
|
|
85
|
-
writable: true,
|
|
86
|
-
value: void 0
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(this, "zepInitFailMsg", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: "ZepClient is not initialized"
|
|
93
|
-
});
|
|
94
|
-
this.humanPrefix = fields.humanPrefix ?? this.humanPrefix;
|
|
95
|
-
this.aiPrefix = fields.aiPrefix ?? this.aiPrefix;
|
|
96
|
-
this.memoryKey = fields.memoryKey ?? this.memoryKey;
|
|
97
|
-
this.baseURL = fields.baseURL;
|
|
98
|
-
this.sessionId = fields.sessionId;
|
|
99
|
-
this.zepClientPromise = ZepClient.init(this.baseURL, fields.apiKey);
|
|
100
|
-
}
|
|
101
|
-
get memoryKeys() {
|
|
102
|
-
return [this.memoryKey];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Method that retrieves the chat history from the Zep service and formats
|
|
106
|
-
* it into a list of messages.
|
|
107
|
-
* @param values Input values for the method.
|
|
108
|
-
* @returns Promise that resolves with the chat history formatted into a list of messages.
|
|
109
|
-
*/
|
|
110
|
-
async loadMemoryVariables(values) {
|
|
111
|
-
// use either lastN provided by developer or undefined to use the
|
|
112
|
-
// server preset.
|
|
113
|
-
// Wait for ZepClient to be initialized
|
|
114
|
-
const zepClient = await this.zepClientPromise;
|
|
115
|
-
if (!zepClient) {
|
|
116
|
-
throw new Error(this.zepInitFailMsg);
|
|
117
|
-
}
|
|
118
|
-
const lastN = values.lastN ?? undefined;
|
|
119
|
-
let memory = null;
|
|
120
|
-
try {
|
|
121
|
-
memory = await zepClient.memory.getMemory(this.sessionId, lastN);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
125
|
-
if (error instanceof NotFoundError) {
|
|
126
|
-
const result = this.returnMessages
|
|
127
|
-
? { [this.memoryKey]: [] }
|
|
128
|
-
: { [this.memoryKey]: "" };
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
let messages = memory && memory.summary?.content
|
|
136
|
-
? [new SystemMessage(memory.summary.content)]
|
|
137
|
-
: [];
|
|
138
|
-
if (memory) {
|
|
139
|
-
messages = messages.concat(memory.messages.map((message) => {
|
|
140
|
-
const { content, role } = message;
|
|
141
|
-
if (role === this.humanPrefix) {
|
|
142
|
-
return new HumanMessage(content);
|
|
143
|
-
}
|
|
144
|
-
else if (role === this.aiPrefix) {
|
|
145
|
-
return new AIMessage(content);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
// default to generic ChatMessage
|
|
149
|
-
return new ChatMessage(content, role);
|
|
150
|
-
}
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
if (this.returnMessages) {
|
|
154
|
-
return {
|
|
155
|
-
[this.memoryKey]: messages,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
[this.memoryKey]: getBufferString(messages, this.humanPrefix, this.aiPrefix),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Method that saves the input and output messages to the Zep service.
|
|
164
|
-
* @param inputValues Input messages to be saved.
|
|
165
|
-
* @param outputValues Output messages to be saved.
|
|
166
|
-
* @returns Promise that resolves when the messages have been saved.
|
|
167
|
-
*/
|
|
168
|
-
async saveContext(inputValues, outputValues) {
|
|
169
|
-
const input = getInputValue(inputValues, this.inputKey);
|
|
170
|
-
const output = getOutputValue(outputValues, this.outputKey);
|
|
171
|
-
// Create new Memory and Message instances
|
|
172
|
-
const memory = new Memory({
|
|
173
|
-
messages: [
|
|
174
|
-
new Message({
|
|
175
|
-
role: this.humanPrefix,
|
|
176
|
-
content: `${input}`,
|
|
177
|
-
}),
|
|
178
|
-
new Message({
|
|
179
|
-
role: this.aiPrefix,
|
|
180
|
-
content: `${output}`,
|
|
181
|
-
}),
|
|
182
|
-
],
|
|
183
|
-
});
|
|
184
|
-
// Wait for ZepClient to be initialized
|
|
185
|
-
const zepClient = await this.zepClientPromise;
|
|
186
|
-
if (!zepClient) {
|
|
187
|
-
throw new Error(this.zepInitFailMsg);
|
|
188
|
-
}
|
|
189
|
-
// Add the new memory to the session using the ZepClient
|
|
190
|
-
if (this.sessionId) {
|
|
191
|
-
try {
|
|
192
|
-
await zepClient.memory.addMemory(this.sessionId, memory);
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
console.error("Error adding memory: ", error);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Call the superclass's saveContext method
|
|
199
|
-
await super.saveContext(inputValues, outputValues);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Method that deletes the chat history from the Zep service.
|
|
203
|
-
* @returns Promise that resolves when the chat history has been deleted.
|
|
204
|
-
*/
|
|
205
|
-
async clear() {
|
|
206
|
-
// Wait for ZepClient to be initialized
|
|
207
|
-
const zepClient = await this.zepClientPromise;
|
|
208
|
-
if (!zepClient) {
|
|
209
|
-
throw new Error(this.zepInitFailMsg);
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
await zepClient.memory.deleteMemory(this.sessionId);
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
console.error("Error deleting session: ", error);
|
|
216
|
-
}
|
|
217
|
-
// Clear the superclass's chat history
|
|
218
|
-
await super.clear();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
1
|
+
export * from "@langchain/community/memory/zep";
|
|
@@ -1,51 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* BaseListChatMessageHistory class and provides methods to get, add, and
|
|
8
|
-
* clear messages.
|
|
9
|
-
*/
|
|
10
|
-
class ChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
11
|
-
constructor(messages) {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: ["langchain", "stores", "message", "in_memory"]
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "messages", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: []
|
|
24
|
-
});
|
|
25
|
-
this.messages = messages ?? [];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Method to get all the messages stored in the ChatMessageHistory
|
|
29
|
-
* instance.
|
|
30
|
-
* @returns Array of stored BaseMessage instances.
|
|
31
|
-
*/
|
|
32
|
-
async getMessages() {
|
|
33
|
-
return this.messages;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Method to add a new message to the ChatMessageHistory instance.
|
|
37
|
-
* @param message The BaseMessage instance to add.
|
|
38
|
-
* @returns A promise that resolves when the message has been added.
|
|
39
|
-
*/
|
|
40
|
-
async addMessage(message) {
|
|
41
|
-
this.messages.push(message);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
42
7
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
exports
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@langchain/community/stores/message/in_memory"), exports);
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Class for storing chat message history in-memory. It extends the
|
|
4
|
-
* BaseListChatMessageHistory class and provides methods to get, add, and
|
|
5
|
-
* clear messages.
|
|
6
|
-
*/
|
|
7
|
-
export declare class ChatMessageHistory extends BaseListChatMessageHistory {
|
|
8
|
-
lc_namespace: string[];
|
|
9
|
-
private messages;
|
|
10
|
-
constructor(messages?: BaseMessage[]);
|
|
11
|
-
/**
|
|
12
|
-
* Method to get all the messages stored in the ChatMessageHistory
|
|
13
|
-
* instance.
|
|
14
|
-
* @returns Array of stored BaseMessage instances.
|
|
15
|
-
*/
|
|
16
|
-
getMessages(): Promise<BaseMessage[]>;
|
|
17
|
-
/**
|
|
18
|
-
* Method to add a new message to the ChatMessageHistory instance.
|
|
19
|
-
* @param message The BaseMessage instance to add.
|
|
20
|
-
* @returns A promise that resolves when the message has been added.
|
|
21
|
-
*/
|
|
22
|
-
addMessage(message: BaseMessage): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Method to clear all the messages from the ChatMessageHistory instance.
|
|
25
|
-
* @returns A promise that resolves when all messages have been cleared.
|
|
26
|
-
*/
|
|
27
|
-
clear(): Promise<void>;
|
|
28
|
-
}
|
|
1
|
+
export * from "@langchain/community/stores/message/in_memory";
|