langchain: llm-math raising an issue
I’m testing out the tutorial code for Agents:
`from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI
llm = OpenAI(temperature=0) tools = load_tools([“serpapi”, “llm-math”], llm=llm) agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent.run(“What was the high temperature in SF yesterday in Fahrenheit? What is that number raised to the .023 power?”)`
And so far it generates the result:
> Entering new AgentExecutor chain... I need to find the temperature first, then use the calculator to raise it to the .023 power. Action: Search Action Input: "High temperature in SF yesterday" Observation: High: 60.8ºf @3:10 PM Low: 48.2ºf @2:05 AM Approx. Thought: I need to convert the temperature to a number Action: Calculator Action Input: 60.8
But raises an issue and doesn’t calculate 60.8^.023
raise ValueError(f"unknown format from LLM: {llm_output}") ValueError: unknown format from LLM: This is not a math problem and cannot be solved using the numexpr library.
What’s the reason behind this error?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16
Ran into this issue as well. Resolved by changing the temperature from
0
to0.9
.Too early for me to give up on it, I barely understand the details right now. Thanks though.
thanks for breaking it down, I get it now. kind of.
hopefully, will explore more on this. As of now, I was just experimenting (read trying to mash up various things without knowing wth i’m doing most of the time)
When dealing with math questions, you want to set the temperature close to 0 to prevent hallucination. Instead clarify in the tool description that the model only should input math expressions:
For exception
TypeError: 'VariableNode' object is not callable
: LLM-math chain uses numexpr to evaluate the expression. numexpr doesn’t support all operations yet, unfortunaltelyround()
is one among others: https://numexpr.readthedocs.io/en/latest/user_guide.html#supported-functionsInstead I created a custom tool that evaluates the expression with
eval
:It works