Class that provides a concrete implementation of the conversation memory. It includes methods for loading memory variables, saving context, and clearing the memory.

Example

const memory = new ConversationSummaryMemory({
memoryKey: "chat_history",
llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo", temperature: 0 }),
});

const model = new ChatOpenAI();
const prompt =
PromptTemplate.fromTemplate(`The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.

Current conversation:
{chat_history}
Human: {input}
AI:`);
const chain = new LLMChain({ llm: model, prompt, memory });

const res1 = await chain.call({ input: "Hi! I'm Jim." });
console.log({ res1, memory: await memory.loadMemoryVariables({}) });

const res2 = await chain.call({ input: "What's my name?" });
console.log({ res2, memory: await memory.loadMemoryVariables({}) });

Hierarchy

Constructors

Properties

aiPrefix: string = "AI"
buffer: string = ""
humanPrefix: string = "Human"
memoryKey: string = "history"
prompt: BasePromptTemplate<any, BasePromptValue, any> = SUMMARY_PROMPT
returnMessages: boolean
summaryChatMessageClass: (new (content) => BaseMessage) = SystemMessage

Type declaration

inputKey?: string
outputKey?: string

Accessors

Methods

  • Predicts a new summary for the conversation given the existing messages and summary.

    Parameters

    • messages: BaseMessage[]

      Existing messages in the conversation.

    • existingSummary: string

      Current summary of the conversation.

    Returns Promise<string>

    A promise that resolves to a new summary string.

Generated using TypeDoc