我想添加一个ConversationBufferMemory
to pandas_dataframe_agent
但到目前为止我还没有成功。
- 我尝试通过构造函数添加内存:
create_pandas_dataframe_agent(llm, df, verbose=True, memory=memory)
这没有破坏代码,但没有导致代理记住我之前的问题。
- 我还尝试通过这段代码将内存添加到代理中:
pd_agent.agent.llm_chain.memory = memory
。这导致了ValueError: One input key expected got ['input', 'agent_scratchpad']
这是我到目前为止的代码(不起作用):
llm = ChatOpenAI(temperature=0, model_name="gpt-4-0613")
memory = ConversationBufferMemory()
pd_agent = create_pandas_dataframe_agent(llm, df, verbose=True, memory=memory)
#pd_agent.agent.llm_chain.memory = memory #Or if I use this approach the code breaks when calling the .run() methods
pd_agent.run("Look into the data in step 12. Are there any weird patterns? What can we say about this part of the dataset.")
pd_agent.run("What was my previouse question?") #Agent doesn't rember
添加到 Jakub 的答案中,我们可以跳过手动步骤prompt.py
通过传递文件修改prefix
参数到create_pandas_dataframe_agent
功能。
PREFIX = """
You are working with a pandas dataframe in Python. The name of the dataframe is `df`.
You should use the tools below to answer the question posed of you:
Summary of the whole conversation:
{chat_history_summary}
Last few messages between you and user:
{chat_history_buffer}
Entities that the conversation is about:
{chat_history_KG}
"""
pd_agent = create_pandas_dataframe_agent(
llm_code,
df,
prefix=PREFIX,
verbose=True,
agent_executor_kwargs={"memory": memory},
input_variables=['df_head', 'input', 'agent_scratchpad', 'chat_history_buffer', 'chat_history_summary', 'chat_history_KG']
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)