0

Example:

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)]

My agent's action input is correct and it tries to execute this but the result of this breaches the max_token limit for the model given. In such cases, I want to retrieve this action input i.e., the python code it generated. How to go about it?

I tried callbacks and intermediate steps. But both doesnt solve the problem. To identify if it has breached token limit, I have to execute agent.run(query). But if I execute, my tokens are breached and when they are breached, I cant retrieve the intermediate steps.

Code to replicate error

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)

use any excel file and query it in such a way that when the query is converted to pandas code, the result should be a dataframe and not a singluar value

Random Davis
  • 6,662
  • 4
  • 14
  • 24

0 Answers0