langchain icon indicating copy to clipboard operation
langchain copied to clipboard

fix: provider the latest duckduckgo_search API

Open Undertone0809 opened this issue 1 year ago • 8 comments

Provider the latest duckduckgo_search API

The Git commit contents involve two files related to some DuckDuckGo query operations, and an upgrade of the DuckDuckGo module to version 3.2.0. A suitable commit message could be "Upgrade DuckDuckGo module to version 3.2.0, including query operations". Specifically, in the duckduckgo_search.py file, a DDGS() class instance is newly added to replace the previous ddg() function, and the time parameter name in the get_snippets() and results() methods is changed from "time" to "timelimit" to accommodate recent changes. In the pyproject.toml file, the duckduckgo-search module is upgraded to version 3.2.0.

Who can review?

@vowelparrot

Undertone0809 avatar May 24 '23 09:05 Undertone0809

duckduckgo_search readme attention: Versions before v2.9.4 no longer work as of May 12, 2023

Undertone0809 avatar May 24 '23 09:05 Undertone0809

@vowelparrot I wonder why duckduckgo_search has release v3.2.0 but checks failed and said Because langchain depends on duckduckgo-search (^3.2.0) which doesn't match any versions, version solving failed.

Undertone0809 avatar May 24 '23 09:05 Undertone0809

The poetry.lock file needs to be updated as well! (running poetry lock will update)

vowelparrot avatar May 24 '23 11:05 vowelparrot

@vowelparrot I got the following problem. Do you have ideas to solve the problem?

And because weaviate-client (3.19.0) depends on requests (>=2.28.0,<2.29.0)
 and weaviate-client (3.19.1) depends on requests (>=2.28.0,<2.29.0), weaviate-client (>=3.15.5,<4) requires requests (>=2.28.0,<2.29.0).
And because duckduckgo-search (3.2.0) depends on requests (>=2.31.0)
 and no versions of duckduckgo-search match >3.2.0,<4.0.0, weaviate-client (>=3.15.5,<4) is incompatible with duckduckgo-search (>=3.2.0,<4.0.0).
So, because langchain depends on both weaviate-client (>=3.15.5,<4) and duckduckgo-search (^3.2.0), version solving failed.

Undertone0809 avatar May 24 '23 12:05 Undertone0809

I'll try to get back to this later - opened a PR on the weaviate client to bump the upper bound. the Dep resolution issue seems fairly common : https://github.com/python-poetry/poetry/issues/697

vowelparrot avatar May 24 '23 13:05 vowelparrot

Oh I see. It's a very common problem.

Undertone0809 avatar May 24 '23 13:05 Undertone0809

We can harness the self.max_results to limit the search results, for example:

    for i, res in enumerate(results, 1):
        snippets.append(res['body'])
        if i == self.max_results:
            break
    return snippets

Generator is much simple:

...
    for i, res in enumerate(results, 1):
        yield res['body']
        if i == self.max_results:
            return
...

In the latest version of duckduckgo_search, it is recommand to use context manager with DDGS:

with DDGS() as ddgs:
    ddgs.text(...)

rrcgat avatar Jun 15 '23 12:06 rrcgat

ok I fix it later. Previously, due to dependency version conflicts, I was unable to pass the test.

Undertone0809 avatar Jun 15 '23 12:06 Undertone0809

@Undertone0809 is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 19 '23 03:06 vercel[bot]

Oh, I don't know why make so many commit. Perhaps I should create a new PR #6409

Undertone0809 avatar Jun 19 '23 06:06 Undertone0809