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

An error occurred: 'DDGS' object does not support the context manager protocol #9685

Closed
2 of 14 tasks
ZhuJD-China opened this issue Aug 24, 2023 · 2 comments
Closed
2 of 14 tasks
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@ZhuJD-China
Copy link

System Info

Entering new AgentExecutor chain...

Invoking: duckduckgo_search with 2023年8月的新闻

An error occurred: 'DDGS' object does not support the context manager protocol

Who can help?

@hwchase17
@agola11

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

初始化OpenAI Functions代理

agent = initialize_agent(
# tools,

tools=load_tools(["ddg-search"]),

llm=llm,

agent=AgentType.OPENAI_FUNCTIONS,

verbose=True,
agent_kwargs=agent_kwargs,
memory=memory,
max_iterations=10,
early_stopping_method="generate",
handle_parsing_errors=True,  # 初始化代理并处理解析错误
callbacks=[handler],

)

Entering new AgentExecutor chain...

Invoking: duckduckgo_search with 2023年8月的新闻

An error occurred: 'DDGS' object does not support the context manager protocol

Expected behavior

该类提供了通过 DuckDuckGo 搜索引擎搜索的功能。

from langchain.tools import DuckDuckGoSearchRun
search = DuckDuckGoSearchRun()
search.run("Who is winner of FIFA worldcup 2018?")
你应该期望如下输出:

The 2018 FIFA World Cup was the 21st FIFA World Cup, ... Mario Zagallo (Brazil) and Franz Beckenbauer (Germany) have also achieved the feat.

@dosubot dosubot bot added Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Aug 24, 2023
@dosubot
Copy link

dosubot bot commented Aug 24, 2023

🤖

您好,

根据您提供的信息,我注意到您在尝试使用LangChain框架中的DuckDuckGoSearchRun功能时遇到了问题。这个问题的原因是'DDGS'对象不支持上下文管理器协议,这是因为LangChain框架中的DuckDuckGoSearchRun类没有实现__enter____exit__方法。在Python中,这两个方法是必须的,以便一个对象可以作为上下文管理器与'with'语句一起使用。

如果您想让'DDGS'对象支持上下文管理器协议,您需要在DuckDuckGoSearchRun类中添加这些方法。以下是一个可能的实现方式:

class DuckDuckGoSearchRun(BaseTool):
    # existing code...

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        # clean up resources here, if necessary
        pass

添加了这些方法后,您可以像这样将'DDGS'对象作为上下文管理器使用:

with DuckDuckGoSearchRun() as ddgs:
    # use ddgs here...

然而,这是否必要或适当取决于您的应用程序的具体需求和设计。

关于'DDGS'对象是否需要支持上下文管理器协议以便在LangChain框架中进行预期的使用,我在仓库中没有找到答案,但答案可能在其他地方可用,或者我可能错过了它。

如果您有任何其他问题或需要进一步的帮助,请随时告诉我。

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.

Copy link

dosubot bot commented Nov 23, 2023

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

From what I understand, you encountered an error when using the 'DDGS' object in the context manager protocol. You provided detailed information about the system and reproduction steps. One of our users, "dosubot", suggested modifying the code in the 'DuckDuckGoSearchRun' class by adding the __enter__ and __exit__ methods, which would allow the 'DDGS' object to be used as a context manager. Since then, there haven't been any further updates or responses.

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 understanding and contribution to the LangChain project! Let us know if you have any further questions or concerns.

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 23, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 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 Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: agent Related to agents module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant