| 5 | |
| 6 | |
| 7 | def run_llm_math_chain_factory(llm_math_chain): |
| 8 | def run_llm_math_chain(args): |
| 9 | # since llm math chain returns the answer with a prefix, we need to remove it |
| 10 | try: |
| 11 | response = llm_math_chain.run(args) |
| 12 | try: |
| 13 | r = response.split("Answer:")[-1] |
| 14 | r = r.strip() |
| 15 | r = float(r) |
| 16 | # round to 3 decimal places |
| 17 | r = round(r, 3) |
| 18 | response = "Answer: " + str(r) |
| 19 | except: |
| 20 | pass |
| 21 | except: |
| 22 | response = "Error: Invalid expression. Try with a different expression." |
| 23 | return response |
| 24 | |
| 25 | return run_llm_math_chain |
| 26 | |
| 27 | |
| 28 | web_searcher = ReActWikipedia() |