-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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
Community: Fix DuckDuckGo search tool Output Format #27479
Community: Fix DuckDuckGo search tool Output Format #27479
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@AndrewEffendi thank you for the contribution! i updated the change to make it backwards compatible. The behavior you introduced is still available, it just requires specifying |
Looks good, thanks! |
**Issue:** : langchain-ai#22961 **Description:** Previously, the documentation for `DuckDuckGoSearchResults` said that it returns a JSON string, however the code returns a regular string that can't be parsed as is. for example running ```python from langchain_community.tools import DuckDuckGoSearchResults # Create a DuckDuckGo search instance search = DuckDuckGoSearchResults() # Invoke the search result = search.invoke("Obama") # Print the result print(result) # Print the type of the result print("Result Type:", type(result)) ``` will return ``` snippet: Harris will hold a campaign event with former President Barack Obama in Georgia next Thursday, the first time the pair has campaigned side by side, a senior campaign official said. A week from ..., title: Obamas to hit the campaign trail in first joint appearances with Harris, link: https://www.nbcnews.com/politics/2024-election/obamas-hit-campaign-trail-first-joint-appearances-harris-rcna176034, snippet: Item 1 of 3 Former U.S. first lady Michelle Obama and her husband, former U.S. President Barack Obama, stand on stage during Day 2 of the Democratic National Convention (DNC) in Chicago, Illinois ..., title: Obamas set to hit campaign trail with Kamala Harris for first time, link: https://www.reuters.com/world/us/obamas-set-hit-campaign-trail-with-kamala-harris-first-time-2024-10-18/, snippet: Barack and Michelle Obama will make their first campaign appearances alongside Kamala Harris at rallies in Georgia and Michigan. By Reid J. Epstein Reporting from Ashwaubenon, Wis. Here come the ..., title: Harris Will Join Michelle Obama and Barack Obama on Campaign Trail, link: https://www.nytimes.com/2024/10/18/us/politics/kamala-harris-michelle-obama-barack-obama.html, snippet: Obama's leaving office was "a turning point," Mirsky said. "That was the last time anybody felt normal." A few feet over, a 64-year-old physics professor named Eric Swanson who had grown ..., title: Obama's reemergence on the campaign trail for Harris comes as he ..., link: https://www.cnn.com/2024/10/13/politics/obama-campaign-trail-harris-biden/index.html Result Type: <class 'str'> ``` After the change in this PR, `DuckDuckGoSearchResults` takes an additional `output_format = "list" | "json" | "string"` ("string" = current behavior, default). For example, invoking `DuckDuckGoSearchResults(output_format="list")` return a list of dictionaries in the format ``` [{'snippet': '...', 'title': '...', 'link': '...'}, ...] ``` e.g. ``` [{'snippet': "Obama has in a sense been wrestling with Trump's impact since the real estate magnate broke onto the political stage in 2015. Trump's victory the next year, defeating Obama's secretary of ...", 'title': "Obama's fears about Trump drive his stepped-up campaigning", 'link': 'https://www.washingtonpost.com/politics/2024/10/18/obama-trump-anxiety-harris-campaign/'}, {'snippet': 'Harris will hold a campaign event with former President Barack Obama in Georgia next Thursday, the first time the pair has campaigned side by side, a senior campaign official said. A week from ...', 'title': 'Obamas to hit the campaign trail in first joint appearances with Harris', 'link': 'https://www.nbcnews.com/politics/2024-election/obamas-hit-campaign-trail-first-joint-appearances-harris-rcna176034'}, {'snippet': 'Item 1 of 3 Former U.S. first lady Michelle Obama and her husband, former U.S. President Barack Obama, stand on stage during Day 2 of the Democratic National Convention (DNC) in Chicago, Illinois ...', 'title': 'Obamas set to hit campaign trail with Kamala Harris for first time', 'link': 'https://www.reuters.com/world/us/obamas-set-hit-campaign-trail-with-kamala-harris-first-time-2024-10-18/'}, {'snippet': 'Barack and Michelle Obama will make their first campaign appearances alongside Kamala Harris at rallies in Georgia and Michigan. By Reid J. Epstein Reporting from Ashwaubenon, Wis. Here come the ...', 'title': 'Harris Will Join Michelle Obama and Barack Obama on Campaign Trail', 'link': 'https://www.nytimes.com/2024/10/18/us/politics/kamala-harris-michelle-obama-barack-obama.html'}] Result Type: <class 'list'> ``` --------- Co-authored-by: vbarda <vadym@langchain.dev>
Issue: : #22961
Description:
Previously, the documentation for
DuckDuckGoSearchResults
said that it returns a JSON string, however the code returns a regular string that can't be parsed as is.for example running
will return
After the change in this PR,
DuckDuckGoSearchResults
takes an additionaloutput_format = "list" | "json" | "string"
("string" = current behavior, default). For example, invokingDuckDuckGoSearchResults(output_format="list")
return a list of dictionaries in the formate.g.