langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
89.21k stars 14.06k forks source link

Issue: Recently, the DuckduckGo search tool seems not working. VQDExtractionException: Could not extract vqd. keywords="keywords" #14233

Closed Suroras closed 5 days ago

Suroras commented 7 months ago

Issue you'd like to raise.

from langchain.agents import AgentType, initialize_agent from langchain.chat_models import ChatOpenAI from langchain.tools import DuckDuckGoSearchRun

llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")

web_search = DuckDuckGoSearchRun() tools = [ web_search,

other tools

]

agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)

agent.run("")

VQDExtractionException: Could not extract vqd. keywords="blah blah blah"


The code above worked fine several weeks ago, but it is not working any more. I tried every version of LangChain released after September.

Maybe there is a change in DuckDuckGo's API. Please help me, thanks.

Suggestion:

No response

dosubot[bot] commented 7 months ago

🤖

Hello @Suroras,

I'm Dosu, a bot created to assist you with your issues, answer your questions, and guide you through contributing to the LangChain project. While we wait for a human maintainer, I'm here to help you. Let's get started with your issue.

Based on the information you provided, it seems like the issue might be related to changes in the DuckDuckGo API or the way LangChain interacts with it. I found two similar issues in the LangChain repository that might be relevant:

  1. An error occurred: 'DDGS' object does not support the context manager protocol: This issue suggests adding __enter__ and __exit__ methods to the DuckDuckGoSearchRun class to make it support the context manager protocol. However, this might not be directly related to your issue if you're not using the DuckDuckGoSearchRun object as a context manager.

  2. DuckDuckGo search always returns "No good DuckDuckGo Search Result was found": This issue suggests modifying the DuckDuckGo search code in the LangChain library to use the DDGS class and the "text" method from the duckduckgo_search python library. This might be more relevant to your issue.

Here is the current implementation of the DuckDuckGoSearchRun class in the LangChain codebase:

class DuckDuckGoSearchRun(BaseTool):
    """Tool that queries the DuckDuckGo search API."""

    name: str = "duckduckgo_search"
    description: str = (
        "A wrapper around DuckDuckGo Search. "
        "Useful for when you need to answer questions about current events. "
        "Input should be a search query."
    )
    api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
        default_factory=DuckDuckGoSearchAPIWrapper
    )
    args_schema: Type[BaseModel] = DDGInput

    def _run(
        self,
        query: str,
        run_manager: Optional[CallbackManagerForToolRun] = None,
    ) -> str:
        """Use the tool."""
        return self.api_wrapper.run(query)

Unfortunately, I couldn't find the exact implementation of the DuckDuckGoSearchAPIWrapper class in the LangChain codebase. It's possible that the issue lies in this class, especially if DuckDuckGo has changed their API recently.

I recommend trying to update the DuckDuckGoSearchAPIWrapper class based on the solution provided in the second issue I mentioned. If that doesn't work, you might need to investigate further into the DuckDuckGoSearchAPIWrapper class and how it interacts with the DuckDuckGo API.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

Sources


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.

robertoshimizu commented 7 months ago

The issue seems to be in duckduckgo-search, as I have tried the api directly from the pypackage, without going through langchain, and I have got the same error message:

VQDExtractionException: Could not extract vqd.
zimpstar commented 7 months ago

@robertoshimizu did you manage to solve it somehow?

dmitryvostryakov commented 7 months ago

The issue seems to be in duckduckgo-search, as I have tried the api directly from the pypackage, without going through langchain, and I have got the same error message:

VQDExtractionException: Could not extract vqd.

In my case I usually got VQD errors when I tried to send a really large query to duckduckgo-search, try with shorter versions. Also, double check if your requirements packages are up to date, especially for langchain and duckduckgo-search.

deedy5 commented 7 months ago

Since some time duckduckgo.com started blocking ip by tls-fingerprint, which caused constant troubles. But since version v4.0.0 duckduckgo_search uses curl-cffi and there are no more problems.

kyjones03 commented 6 months ago

Since some time duckduckgo.com started blocking ip by tls-fingerprint, which caused constant troubles. But since version v4.0.0 duckduckgo_search uses curl-cffi and there are no more problems.

This helped fix the problem for me!

pip install --upgrade duckduckgo_search

trotsky1997 commented 4 months ago

Since some time duckduckgo.com started blocking ip by tls-fingerprint, which caused constant troubles. But since version v4.0.0 duckduckgo_search uses curl-cffi and there are no more problems.

This helped fix the problem for me!

pip install --upgrade duckduckgo_search

You're Amazing!

takimdigital commented 4 months ago

hi i come up with the same issue, its not realted with the upgrade . this is my solution

instead of using :

search online using duckduckgo

search_tool = DuckDuckGoSearchRun()

do this :

@tool('DuckDuckGoSearch') def search(search_query: str): """Search the web for informations """ return DuckDuckGoSearchRun().run(search_query)

here is an example with crewai + ollama + web search :

import

from crewai import Agent, Task, Crew, Process from langchain_openai import ChatOpenAI from langchain_community.llms import Ollama from langchain.agents import tool from langchain.agents import load_tools from langchain_community.tools import DuckDuckGoSearchRun

llm_ollama_dolphin = Ollama(model="dolphin-mistral")

llm_ollama_mistral = Ollama(model="mistral")

@tool('DuckDuckGoSearch') def search(search_query: str): """Search the web for informations """ return DuckDuckGoSearchRun().run(search_query)

researcher = Agent( role='Senior Researcher', goal='Discover groundbreaking technologies', backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.', verbose=True, tools=[search], allow_delegation=False, llm=llm_ollama_dolphin )

.... etc

output :

image

YanSte commented 3 months ago

When encountering the message 'No good DuckDuckGo Search Result was found'

Update the library to the latest version.

Many times this solved my case.

(It's possible that certain versions were blocked due to security reasons.)