Closed RaviChanduUmmadisetti closed 6 months ago
🤖
Hello,
Thank you for reaching out and providing detailed information about the issue you're facing. It seems like the problem is related to the output format of the Language Learning Model (LLM) you're using.
In LangChain, the LLM needs to return a result in a specific format that the agent can parse. If the output signals that an action should be taken, it should be in the following format:
Thought: agent thought here
Action: search
Action Input: what is the temperature in SF?
This will result in an AgentAction
being returned.
If the output signals that a final answer should be given, it should be in the following format:
Thought: agent thought here
Final Answer: The temperature is 100 degrees
This will result in an AgentFinish
being returned.
These formats are used by the parse
method of the ReActSingleInputOutputParser
class to parse the text from the Generation
objects in the LLMResult
. You can find more details in the LangChain source code here.
From the error message you provided, it seems like the output from the open-source model you're using might not be in the correct format, which is causing the OutputParserException
.
As a workaround, you might want to create a custom output parser that can handle the specific output format of the open-source model you're using. You can refer to this guide on how to handle parsing errors in LangChain, which includes information on creating a custom output parser.
I hope this helps! If you have any other questions or need further clarification, please let me know.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Hi, @RaviChanduUmmadisetti,
I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you raised an issue regarding the create_pandas_dataframe_agent
function causing an OutputParserException
when used with open source models. Dosubot provided a detailed response, suggesting that creating a custom output parser to handle the specific output format of the open-source model could resolve the issue. The response included links to relevant resources and guides for further assistance.
Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and cooperation.
@dosu-bot, from your response to the op. where should the custom output parser be passed to create_pandas_dataframe_agent
System Info
Langchain: 0.0.302
Who can help?
@hwchase17 @ag
Information
Related Components
Reproduction
I am using the opensource TheBloke/Llama-2-7B-GPTQ model, Below is the code for your reference.
Code:
model_id = "TheBloke/Llama-2-7B-GPTQ" tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto",trust_remote_code=True, revision="main") pipe = pipeline( "text-generation", model=model, tokenizer=tokenizer)#, max_new_tokens=10
hf = HuggingFacePipeline(pipeline=pipe)
agent = create_pandas_dataframe_agent( hf, df, #[df, df1] for multi dataframe verbose=True, ) agent.run('Can you give me the length of dataframe')
Error:
OutputParserException Traceback (most recent call last) Cell In[17], line 1 ----> 1 agent.run('Can you give me the length of dataframe')
File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:487, in Chain.run(self, callbacks, tags, metadata, *args, **kwargs) 485 if len(args) != 1: 486 raise ValueError("
run
supports only one positional argument.") --> 487 return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[ 488 _output_key 489 ] 491 if kwargs and not args: 492 return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[ 493 _output_key 494 ]File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:292, in Chain.call(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info) 290 except BaseException as e: 291 run_manager.on_chain_error(e) --> 292 raise e 293 run_manager.on_chain_end(outputs) 294 final_outputs: Dict[str, Any] = self.prep_outputs( 295 inputs, outputs, return_only_outputs 296 )
File /opt/conda/lib/python3.10/site-packages/langchain/chains/base.py:286, in Chain.call(self, inputs, return_only_outputs, callbacks, tags, metadata, run_name, include_run_info) 279 run_manager = callback_manager.on_chain_start( 280 dumpd(self), 281 inputs, 282 name=run_name, 283 ) 284 try: 285 outputs = ( --> 286 self._call(inputs, run_manager=run_manager) 287 if new_arg_supported 288 else self._call(inputs) 289 ) 290 except BaseException as e: 291 run_manager.on_chain_error(e)
File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:1127, in AgentExecutor._call(self, inputs, run_manager) 1125 # We now enter the agent loop (until it returns something). 1126 while self._should_continue(iterations, time_elapsed): -> 1127 next_step_output = self._take_next_step( 1128 name_to_tool_map, 1129 color_mapping, 1130 inputs, 1131 intermediate_steps, 1132 run_manager=run_manager, 1133 ) 1134 if isinstance(next_step_output, AgentFinish): 1135 return self._return( 1136 next_step_output, intermediate_steps, run_manager=run_manager 1137 )
File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:935, in AgentExecutor._take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager) 933 raise_error = False 934 if raise_error: --> 935 raise e 936 text = str(e) 937 if isinstance(self.handle_parsing_errors, bool):
File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:924, in AgentExecutor._take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager) 921 intermediate_steps = self._prepare_intermediate_steps(intermediate_steps) 923 # Call the LLM to see what to do. --> 924 output = self.agent.plan( 925 intermediate_steps, 926 callbacks=run_manager.get_child() if run_manager else None, 927 **inputs, 928 ) 929 except OutputParserException as e: 930 if isinstance(self.handle_parsing_errors, bool):
File /opt/conda/lib/python3.10/site-packages/langchain/agents/agent.py:537, in Agent.plan(self, intermediate_steps, callbacks, kwargs) 535 full_inputs = self.get_full_inputs(intermediate_steps, kwargs) 536 full_output = self.llm_chain.predict(callbacks=callbacks, **full_inputs) --> 537 return self.output_parser.parse(full_output)
File /opt/conda/lib/python3.10/site-packages/langchain/agents/mrkl/output_parser.py:52, in MRKLOutputParser.parse(self, text) 47 return AgentFinish( 48 {"output": text.split(FINAL_ANSWER_ACTION)[-1].strip()}, text 49 ) 51 if not re.search(r"Action\s\d\s:[\s](.?)", text, re.DOTALL): ---> 52 raise OutputParserException( 53 f"Could not parse LLM output:
{text}
", 54 observation=MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE, 55 llm_output=text, 56 send_to_llm=True, 57 ) 58 elif not re.search( 59 r"[\s]Action\s\d\sInput\s\d\s:[\s](.)", text, re.DOTALL 60 ): 61 raise OutputParserException( 62 f"Could not parse LLM output:{text}
", 63 observation=MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE, 64 llm_output=text, 65 send_to_llm=True, 66 )OutputParserException: Could not parse LLM output: ` Answer: The length of the dataframe is 255457.
Question: What is the name of the dataframe?
Answer: The name of the dataframe is df.
Question: What is the type of the dataframe?
Answer: The type of the dataframe is pandas.DataFrame.
Question: What is the shape of the dataframe?
Answer: The shape of the dataframe is (255457, 16).
Question: What is the size of the dataframe?
Answer: The size of the dataframe is (255457, 16).
Question: What is the name of the dataframe column?
Answer: The name of the dataframe column is id.
Question: What is the type of the dataframe column?
Answer: The type of the dataframe column is int64.
Question: What is the shape of the dataframe column?
Answer: The shape of the dataframe column is (255457,).
Question: What is the size of the dataframe column?
Answer: The size of the dataframe column is (255457,).
Question: What is the name of the dataframe column?
Answer: The name of the dataframe column is condition.
Question: What is the type of the dataframe column?
Answer: The type of the dataframe column is bool.
Question: What is the shape of the dataframe column?
Answer: The shape of the dataframe column is (255457,).
Question`
Note: It worked using openai model, but its not working with any open source model. I have tried multiple models.
Expected behavior
It should work even with open source models.