Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap in Sympy instead of numexpr for more expressive LLMMath tool #8627

Closed
wants to merge 11 commits into from

Conversation

zoeqevans
Copy link
Contributor

@zoeqevans zoeqevans commented Aug 2, 2023

Note that we already use sympy in the symbolic math tool, so this actually removes a dependency!

numexpr is actually quite fragile to input, whereas sympify is really quite hard to break. Take the iconic Langchain tool example mixing information retrieval and numerical calculation: "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?" (from this tutorial page).

If you make the maths more exotic ("What is the first prime number larger than her age?", "What is the factorial of her age?", etc.) numexpr will raise an exception. sympy handles these with flying colours.

I used the chain from that example, with the prompt:

"In the sky, I am the number of sisters who dance, Bound by myth, in a celestial trance. On Earth, I am the continents that span, Holding diverse life, since time began.
What number am I?

Now multiply that number by the age of Zoe Saldana's partner, and raise it to the 2.43rd power.
Take the fourth digit of the answer, then take the factorial of that, and call it X.
What's the smallest prime number greater than X?
"""

and with sympy, my chain passed with flying colours :)

@vercel
Copy link

vercel bot commented Aug 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Aug 2, 2023 0:07am

@dosubot dosubot bot added the 🤖:improvement Medium size change to existing code to handle new use-cases label Aug 2, 2023
@zoeqevans zoeqevans changed the title Mevans/fixing sympy Swap in Sympy instead of numexpr for more expressive LLMMath tool Aug 2, 2023
@baskaryan
Copy link
Collaborator

i wonder if for backwards compatibility / flexibility we should introduce something like an "engine" parameter that lets' folks choose which they want to use (and uses appropriate prompt based on that)

@leo-gan
Copy link
Collaborator

leo-gan commented Sep 20, 2023

@montyevans Hi , could you, please, resolve the merging issues and address the last comments (if needed)? After that, ping me and I push this PR for the review. Thanks!

@efriis
Copy link
Member

efriis commented Nov 10, 2023

Looks like this isn't being worked on anymore. I'll close for now, and if you resume work, feel free to reopen!

@efriis efriis closed this Nov 10, 2023
@nloeff
Copy link

nloeff commented Nov 20, 2023

@efriis if there is interest I can restart work on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants