@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 8.12 kB
Source Map (JSON)
{"version":3,"file":"zep.d.ts","names":["ZepClient","InputValues","OutputValues","MemoryVariables","BaseMessage","HumanMessage","BaseChatMemory","BaseChatMemoryInput","ZepMemoryData","Array","zepMemoryContextToSystemPrompt","condenseZepMemoryIntoHumanMessage","_langchain_core_messages4","MessageToolSet","MessageStructure","zepMemoryToMessages","MessageType","ZepMemoryInput","ZepMemory","Promise"],"sources":["../../src/memory/zep.d.ts"],"sourcesContent":["import { ZepClient } from \"@getzep/zep-js\";\nimport { InputValues, OutputValues, MemoryVariables } from \"@langchain/core/memory\";\nimport { BaseMessage, HumanMessage } from \"@langchain/core/messages\";\nimport { BaseChatMemory, BaseChatMemoryInput } from \"./chat_memory.js\";\ninterface ZepMemoryData {\n messages: Array<{\n role: string;\n content: string;\n }>;\n summary?: {\n content?: string;\n };\n}\n/**\n * Extracts summary from Zep memory and composes a system prompt.\n * @param memory - The memory object containing potential summary.\n * @returns A string containing the summary as a system prompt.\n */\nexport declare const zepMemoryContextToSystemPrompt: (memory: ZepMemoryData) => string;\n/**\n * Condenses Zep memory context into a single HumanMessage.\n * This is particularly useful for models like Claude that have limitations with system messages\n * (e.g., Anthropic's Claude only supports one system message and doesn't support multiple user messages in a row).\n *\n * @param memory - The memory object containing conversation history.\n * @param humanPrefix - The prefix to use for human messages (default: \"Human\").\n * @param aiPrefix - The prefix to use for AI messages (default: \"AI\").\n * @returns A HumanMessage containing the condensed memory context.\n */\nexport declare const condenseZepMemoryIntoHumanMessage: (memory: ZepMemoryData) => HumanMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>>;\n/**\n * Converts Zep Memory to a list of BaseMessages, preserving the structure.\n * Creates a SystemMessage from summary and facts, and converts the rest of the messages\n * to their corresponding message types.\n *\n * @param memory - The memory object containing conversation history.\n * @param humanPrefix - The prefix to use for human messages (default: \"Human\").\n * @param aiPrefix - The prefix to use for AI messages (default: \"AI\").\n * @returns An array of BaseMessage objects representing the conversation history.\n */\nexport declare const zepMemoryToMessages: (memory: ZepMemoryData, humanPrefix?: string, aiPrefix?: string) => BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[];\n/**\n * Interface defining the structure of the input data for the ZepMemory\n * class. It includes properties like humanPrefix, aiPrefix, memoryKey,\n * baseURL, sessionId, apiKey, and separateMessages.\n */\nexport interface ZepMemoryInput extends BaseChatMemoryInput {\n humanPrefix?: string;\n aiPrefix?: string;\n memoryKey?: string;\n baseURL: string;\n sessionId: string;\n apiKey?: string;\n /**\n * Whether to return separate messages for chat history with a SystemMessage containing facts and summary,\n * or return a single HumanMessage with the entire memory context.\n * Defaults to true (preserving message types) for backward compatibility.\n *\n * Keep as true for models that fully support system messages.\n * Set to false for models like Claude that have limitations with system messages.\n */\n separateMessages?: boolean;\n}\n/**\n * Class used to manage the memory of a chat session, including loading\n * and saving the chat history, and clearing the memory when needed. It\n * uses the ZepClient to interact with the Zep service for managing the\n * chat session's memory.\n *\n * The class provides options for handling different LLM requirements:\n * - Use separateMessages=true (default) for models that fully support system messages\n * - Use separateMessages=false for models like Claude that have limitations with system messages\n *\n * @example\n * ```typescript\n * const sessionId = randomUUID();\n * const zepURL = \"http://your-zep-url\";\n *\n * // Initialize ZepMemory with session ID, base URL, and API key\n * const memory = new ZepMemory({\n * sessionId,\n * baseURL: zepURL,\n * apiKey: \"change_this_key\",\n * // Set to false for models like Claude that have limitations with system messages\n * // Defaults to true for backward compatibility\n * separateMessages: false,\n * });\n *\n * // Create a ChatOpenAI model instance with specific parameters\n * const model = new ChatOpenAI({\n * model: \"gpt-3.5-turbo\",\n * temperature: 0,\n * });\n *\n * // Create a ConversationChain with the model and memory\n * const chain = new ConversationChain({ llm: model, memory });\n *\n * // Example of calling the chain with an input\n * const res1 = await chain.call({ input: \"Hi! I'm Jim.\" });\n * console.log({ res1 });\n *\n * // Follow-up call to the chain to demonstrate memory usage\n * const res2 = await chain.call({ input: \"What did I just say my name was?\" });\n * console.log({ res2 });\n *\n * // Output the session ID and the current state of memory\n * console.log(\"Session ID: \", sessionId);\n * console.log(\"Memory: \", await memory.loadMemoryVariables({}));\n *\n * ```\n */\nexport declare class ZepMemory extends BaseChatMemory implements ZepMemoryInput {\n humanPrefix: string;\n aiPrefix: string;\n memoryKey: string;\n baseURL: string;\n sessionId: string;\n zepClientPromise: Promise<ZepClient>;\n private readonly zepInitFailMsg;\n /**\n * Whether to return separate messages for chat history with a SystemMessage containing facts and summary,\n * or return a single HumanMessage with the entire memory context.\n * Defaults to true (preserving message types) for backward compatibility.\n *\n * Keep as true for models that fully support system messages.\n * Set to false for models like Claude that have limitations with system messages.\n */\n separateMessages: boolean;\n constructor(fields: ZepMemoryInput);\n get memoryKeys(): string[];\n /**\n * Method that retrieves the chat history from the Zep service and formats\n * it into a list of messages.\n * @param values Input values for the method.\n * @returns Promise that resolves with the chat history formatted into a list of messages.\n */\n loadMemoryVariables(values: InputValues): Promise<MemoryVariables>;\n /**\n * Method that saves the input and output messages to the Zep service.\n * @param inputValues Input messages to be saved.\n * @param outputValues Output messages to be saved.\n * @returns Promise that resolves when the messages have been saved.\n */\n saveContext(inputValues: InputValues, outputValues: OutputValues): Promise<void>;\n /**\n * Method that deletes the chat history from the Zep service.\n * @returns Promise that resolves when the chat history has been deleted.\n */\n clear(): Promise<void>;\n}\nexport {};\n//# sourceMappingURL=zep.d.ts.map"],"mappings":";;;;;;;UAIUQ,aAAAA;YACIC;;IADJD,OAAAA,EAAAA,MAAa;EAcFE,CAAAA,CAAAA;EAWAC,OAAAA,CAAAA,EAAAA;IAA4CH,OAAAA,CAAAA,EAAAA,MAAAA;EAAaI,CAAAA;;;AAAiB;AAW/F;;;AAA+NA,cAtB1MF,8BAsBwII,EAAAA,CAAAA,MAAAA,EAtB/FN,aAsB+FM,EAAAA,GAAAA,MAAAA;;;AAApC;AAMzH;AAiEA;;;;;;AAyB8CK,cA3GzBR,iCA2GyBQ,EAAAA,CAAAA,MAAAA,EA3GmBX,aA2GnBW,EAAAA,GA3GqCd,YA2GrCc,CA3GuJP,yBAAAA,CAAlEE,gBA2GrFK,CA3GgCP,yBAAAA,CAAyGC,cAAAA,CA2GzIM,CAAAA;;;;;;;AAzBiC;;;;cAvE1DJ,8BAA8BP,2DAA2DJ,YAAiHQ,yBAAAA,CAAlEE,iBAA7FF,yBAAAA,CAAiJC,cAAAA,GAApCD,yBAAAA,CAAwFI,WAAAA;;;;;;UAMpPC,cAAAA,SAAuBV,qBAAAA,CAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiEnBW,SAAAA,SAAkBZ,qBAAAA,CAAAA,cAAAA,YAA0BW;;;;;;oBAM3CE,QAAQnB;;;;;;;;;;;sBAWNiB;;;;;;;;8BAQQhB,cAAckB,QAAQhB;;;;;;;2BAOzBF,2BAA2BC,eAAeiB;;;;;WAK1DA"}