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

regex in langchain/agents/mrkl/base.py #2898

Closed
captainst opened this issue Apr 14, 2023 · 4 comments
Closed

regex in langchain/agents/mrkl/base.py #2898

captainst opened this issue Apr 14, 2023 · 4 comments

Comments

@captainst
Copy link

When use agent to answer question "Who is Leo DiCaprio's current girlfriend? What is her current age raised to the 0.43 power?"
I saw openAI gives the following initial reply:

I should use Google Search to find out who is Leo DiCaprio's current girlfriend. For the second part of the question, I should use the calculator to calculate her age raised to the 0.43 power.
Action 1: Google Search
Action 1 Input: "Leo DiCaprio current girlfriend"

Instead of "Action" and "Action Input" keywords, we have "Action 1" and "Action 1 Input" instead.

The regex in langchain/agents/mrkl/base.py:
regex = r"Action: (.?)[\n]Action Input:[\s](.)"
is better to be changed to
regex = r"Action.?: (.?)[\n]Action.? Input:[\s](.)"

In order to avoid tool not found error.

@azamiftikhar1000
Copy link
Contributor

@captainst Could you please provide the example where its Action 1 Input and Action 1 instead of Action and Action Input. I tested with openAI its giving correct results. Thanks!

@captainst
Copy link
Author

captainst commented Apr 15, 2023

hi @azamiftikhar1000 The test code I used is the following snippet:

from langchain.llms import OpenAI
from langchain.agents import load_tools
from langchain.agents import initialize_agent
import json
import os

os.environ["GOOGLE_CSE_ID"] = "xxxxxx"
os.environ["GOOGLE_API_KEY"] = "xxxxxx"
openai_api_key = "xxxxxx"

llm = OpenAI(model_name="gpt-3.5-turbo", openai_api_key=openai_api_key, temperature=0.8)

toolkit = load_tools(["google-search", "llm-math"], llm=llm)

agent = initialize_agent(toolkit, llm, agent="zero-shot-react-description", verbose=True)

agent.run("Who is Leo DiCaprio's current girlfriend? What is her current age raised to the 0.43 power?")

besides, you can also type the following prompt generated by Langchain to chat.openai.com to see the reply:

Answer the following questions as best you can. You have access to the following tools:

Google Search: A wrapper around Google Search. Useful for when you need to answer questions about current events. Input should be a search query.
Calculator: Useful for when you need to answer questions about math.

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Google Search, Calculator]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: Who is Leo DiCaprio's current girlfriend? What is her current age raised to the 0.43 power?
Thought: 

@azamiftikhar1000
Copy link
Contributor

@captainst Thank you for that, It seems that when we use gpt-3.5-turbo it is giving
Action 1: in the output.

Screenshot 2023-04-15 at 12 30 35 PM

Where as gpt-4 is giving Action:

Screenshot 2023-04-15 at 12 33 24 PM

I will shortly create the PR with the solution.

Thanks!

hwchase17 pushed a commit that referenced this issue Apr 16, 2023
###  #2898
Instead of `"Action" and "Action Input"` keywords, we are getting
`"Action 1" and "Action 1 Input" or "Action Input 1" ` from
**gpt-3.5-turbo**

 Updated the Regular expression to handle all these cases
 
Attaching the screenshot of the result from the updated Regular
expression.
 
<img width="1036" alt="Screenshot 2023-04-16 at 1 39 00 AM"
src="https://user-images.githubusercontent.com/55012400/232251184-23ca6cc2-7229-411a-b6e1-53b2f5ec18a5.png">
wertycn pushed a commit to wertycn/langchain-zh that referenced this issue Apr 26, 2023
###  langchain-ai/langchain#2898
Instead of `"Action" and "Action Input"` keywords, we are getting
`"Action 1" and "Action 1 Input" or "Action Input 1" ` from
**gpt-3.5-turbo**

 Updated the Regular expression to handle all these cases
 
Attaching the screenshot of the result from the updated Regular
expression.
 
<img width="1036" alt="Screenshot 2023-04-16 at 1 39 00 AM"
src="https://user-images.githubusercontent.com/55012400/232251184-23ca6cc2-7229-411a-b6e1-53b2f5ec18a5.png">
samching pushed a commit to samching/langchain that referenced this issue May 1, 2023
###  langchain-ai#2898
Instead of `"Action" and "Action Input"` keywords, we are getting
`"Action 1" and "Action 1 Input" or "Action Input 1" ` from
**gpt-3.5-turbo**

 Updated the Regular expression to handle all these cases
 
Attaching the screenshot of the result from the updated Regular
expression.
 
<img width="1036" alt="Screenshot 2023-04-16 at 1 39 00 AM"
src="https://user-images.githubusercontent.com/55012400/232251184-23ca6cc2-7229-411a-b6e1-53b2f5ec18a5.png">
@dosubot
Copy link

dosubot bot commented Sep 7, 2023

Hi, @captainst! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue is about a regex pattern in the file langchain/agents/mrkl/base.py that needs to be updated to avoid a "tool not found" error. You provided a test code snippet, and the maintainer confirmed the issue and mentioned that they will create a pull request with the solution.

Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us 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 contribution, and we appreciate your understanding as we work to keep our issue tracker up to date. Let us know if you have any further questions or concerns!

Best regards,
Dosu

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Sep 7, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants