Class ConversationSummaryMemory

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 = ""
chatHistory: BaseChatMessageHistory
humanPrefix: string = "Human"
llm: BaseLanguageModel<any, BaseLanguageModelCallOptions>
memoryKey: string = "history"
prompt: BasePromptTemplate<any, BasePromptValue, any> = SUMMARY_PROMPT
returnMessages: boolean = false
summaryChatMessageClass: (new (content) => BaseMessage) = SystemMessage

Type declaration

    • new (content): BaseMessage
    • Parameters

      • content: string

      Returns BaseMessage

inputKey?: string
outputKey?: string

Accessors

  • get memoryKeys(): string[]
  • Returns string[]

Methods

  • Clears the conversation memory.

    Returns Promise<void>

    A promise that resolves when the memory has been cleared.

  • Loads the memory variables for the conversation memory.

    Parameters

    • _: InputValues

    Returns Promise<MemoryVariables>

    A promise that resolves to an object containing the memory variables.

  • 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.

  • Saves the context of the conversation memory.

    Parameters

    • inputValues: InputValues

      Input values for the conversation.

    • outputValues: OutputValues

      Output values from the conversation.

    Returns Promise<void>

    A promise that resolves when the context has been saved.

Generated using TypeDoc