admin管理员组文章数量:1567013
LangChain学习文档
- Chains(链)
- 【LangChain】不同的调用方式(Different call methods)
- 【LangChain】自定义chain
- 【LangChain】调试Chain(Debugging chains)
- 【LangChain】从LangChainHub加载(Loading from LangChainHub)
- 【LangChain】持久化(Adding memory (state))
概述
可以使用 Memory
对象来初始化Chain
,该对象将在对Chain
的调用之间保留数据。这使得Chain
有状态。
内容
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
conversation = ConversationChain(
llm=chat,
memory=ConversationBufferMemory()
)
conversation.run("Answer briefly. What are the first 3 colors of a rainbow?")
# -> The first three colors of a rainbow are red, orange, and yellow.
conversation.run("And the next 4?")
# -> The next four colors of a rainbow are green, blue, indigo, and violet.
本质上,BaseMemory
定义了 langchain
如何存储的接口。它允许通过 load_memory_variables
方法读取存储的数据并通过 save_context
方法存储新数据。您可以在Memory
部分了解更多信息。
总结
聊天GPT,应该就是这么它吧。大模型增加记忆后,就可以聊天了。
- 构建
Chain
时,增加memory
参数,其实拥有记忆
参考地址:
Adding memory (state)
本文标签: 上下文记忆LangChainStateMemory
版权声明:本文标题:【LangChain】添加上下文记忆(Adding memory (state)) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1725458482a1024496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论