例子:
Thought: I need to filter the dataframe to get the rows that match the criteria
Action: python_repl_ast
Action Input: df[(df['COUNTRY'] == 'USA') & (df['PRODUCTLINE'] == 'Motorcycles') & (df['YEAR_ID'] == 2003)]
我的代理的动作输入是正确的,它尝试执行此操作,但此操作的结果违反了给定模型的
max_token
限制。在这种情况下,我想检索此操作输入,即它生成的 python 代码。怎么办?
我尝试了回调和中间步骤。但是两者都不能解决问题。要确定它是否违反了令牌限制,我必须执行
agent.run(query)
。但如果我执行,我的令牌就会被破坏,当它们被破坏时,我无法检索中间步骤。
复制错误的代码
from langchain.llms import OpenAI
from langchain.agents import create_pandas_dataframe_agent
import pandas as pd
df = pd.read_excel("")
agent = create_pandas_dataframe_agent(OpenAI(temperature=0, model_kwargs = {"model":'text-davinci-003'}), df, verbose=True, max_iterations=3)
query = ""
agent.run(query)
使用任何 excel 文件并以这样的方式查询它,当查询转换为 pandas 代码时,结果应该是一个数据框而不是一个单一的值