langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
43 lines (42 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const memory_1 = require("langchain/memory");
const types_1 = require("../../types");
class BufferMemoryPlugin {
constructor() {
this.name = "bufferMemory";
this.description = "Stores chat messages in memory (non-persistent)";
this.type = types_1.PluginType.Memory;
this.RunConfigExample = {};
this.InitConfigExample = {
memoryKey: "chat_history",
aiPrefix: "AI",
humanPrefix: "Human",
};
this.memory = null;
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
memory: this.memory,
};
}
async init(config) {
this.memory = new memory_1.BufferMemory({
memoryKey: config.memoryKey || "chat_history",
humanPrefix: config.humanPrefix || "Human",
aiPrefix: config.aiPrefix || "AI",
});
}
async run(args) {
if (!this.memory)
throw new Error("Memory is not initialized.");
const history = await this.memory.chatHistory.getMessages();
return history;
}
}
exports.default = BufferMemoryPlugin;