langchain: Toolkits - Pandas Dataframe Agent failed to call "python_repl_ast" consistently
Please ask: how many rows
Entering new AgentExecutor chain… Thought: I need to find the number of rows in the dataframe Action: python_repl_ast Action Input: len(df) Observation: 45 Thought:I have the number of rows Final Answer: 45
Finished chain. 45
Please ask: does fg-40f support local report
Entering new AgentExecutor chain… Thought: We need to check if the “FG-40F Series” row has “Yes” in the “Local Reporting” column. Action: Use pandas boolean indexing to filter the dataframe to only the “FG-40F Series” row and check the value in the “Local Reporting” column. Action Input:
df[df['Product'] == 'FG-40F Series']['Local Reporting']
Observation: Use pandas boolean indexing to filter the dataframe to only the “FG-40F Series” row and check the value in the “Local Reporting” column. is not a valid tool, try another one. Thought:I made a mistake, I should use python_repl_ast instead of Observation. Action: Use python_repl_ast to execute the previous input. Action Input:python_repl_ast(df[df['Product'] == 'FG-40F Series']['Local Reporting'])
Observation: Use python_repl_ast to execute the previous input. is not a valid tool, try another one. Thought:I made another mistake, I should use print() to display the result. Action: Use python_repl_ast to execute the previous input with print(). Action Input:python_repl_ast(print(df[df['Product'] == 'FG-40F Series']['Local Reporting']))
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15 (3 by maintainers)
@MohammedAlhajji I am kind of making a hardcode solution working with ChatGPT-3.5-turbo. It is not good for general purposes but just want to share some ideas with you.
Action: python_repl_ast to force LLM to pick python_repl_ast as the tool Action Input: the input to the action, never add backticks “`” around the action input to tell LLM NOT to add backticks
Using
agent_type=AgentType.OPENAI_FUNCTIONS
with gpt-3.5-turbo might fix the issueHi! Any update on the fix? The agent (using llm gpt-35-turbo) goes into a loop until max iterations is reached and throws error “Agent stopped due to iteration limit or time limit”.
If anyone visits here because of the
python is not a valid tool, try one of [python_repl_ast].
Try to add
if function_name == "python": function_name = "python_repl_ast"
tolib/site-packages/langchain/agents/ouput_parsers/openai_functions.py
before the content_msg where its at approximately 70th line.return_direct = True,response就可以获取大模型回答的结果了
By changing Action: python_repl_ast to Action: the tool name which should be “python_repl_ast”
And clone my own PythonAstREPLTool to ignore surrounded backticks if any.
I can get the Python tool running quite stably. However, ChatGPT3.5-turbo failed to generate good python code consistently.