如何在兰链中使用模板从链中插入结果以进一步推理? 我正在与Langchain和Openai合作开发对话AI。我已经将多个工具集成到链条中,并且正在使用模板来构建对话。但是,我坚持如何...

问题描述 投票:0回答:1
如何修改模板或调用,以便鲍勃可以在持续的对话中使用链(...)的结果。例如,在获得天气和总和后,我希望AI在其下一个交互中使用这些结果。关于如何构建此或示例的任何建议将不胜感激! 我使用

langchain==0.3.20 langchain-community==0.3.19 langchain-openai==0.3.8 openai==1.66.3 python-dotenv==1.0.1
    

您可以使用内存。例如,首先创建A

ConversaionBufferMemory

来存储遵守的结果:

from langchain.memory import ConversationBufferMemory

mmemory = ConversationBufferMemory(
    memory_key="context", return_messages=True
)
python artificial-intelligence chatbot langchain large-language-model
1个回答
0
投票

@tool def weather(city: str) -> str: """Gives the weather in a given city""" weather_info = f"The weather in {city} is sunny." memory.save_context({"context": weather_info}, {}) # Store weather in memory return weather_info

,然后在您的llmcahin中使用它如下:

chain = LLMChain(llm=llm_with_tools, prompt=prompt, memory=memory)

您可以从现在开始管理内存,以控制应传递给上下文的内容,并相应地传递给使用相同的链的所有链条。


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.