langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Add more results using snippets, titles, and links metadata

Open conceptofmind opened this issue 3 years ago β€’ 0 comments

Hi @hwchase17,

Per our previous discussion, I am updating the Google and Bing Search API utilities to include a method for returning metadata in the form [{'snippet':'hello world', 'title': 'foo', 'link': 'bar'}].

Usage:

search = GoogleSearchAPIWrapper()
search.results(query="apples", num_results=2)

Output:

[{'snippet': 'Lady Alice. Pink Lady <b>apples</b> aren’t the only lady in the apple family. Lady Alice <b>apples</b> were discovered growing, thanks to bees pollinating, in Washington. They are smaller and slightly more stout in appearance than other varieties. Their skin color appears to have red and yellow stripes running from stem to butt.', 'title': '25 Types of Apples - Jessica Gavin', 'link': 'https://www.jessicagavin.com/types-of-apples/'}, {'snippet': '<b>Apples</b> boast many vitamins and minerals, though not in high amounts. However, <b>apples</b> are usually a good source of vitamin C. Vitamin C. Also called ascorbic acid, this vitamin is a common ...', 'title': 'Apples 101: Nutrition Facts and Health Benefits', 'link': 'https://www.healthline.com/nutrition/foods/apples'}]

I also standardized the GoogleSearchAPIWrapper to allow you to select k number of results similar to the BingSearchAPIWrapper.

Usage:

search = GoogleSearchAPIWrapper(k=1)
search.run("python")

Output: 'The official home of the Python Programming Language.'

I commented out the line, default="https://api.bing.microsoft.com/v7.0/search", in the Bing Search API Wrapper and think it may be worth investigating as this was throwing an error for me.

I updated the documentation to include newer examples as well.

Let me know what you think.

Thank you,

Enrico Shippole

conceptofmind avatar Jan 26 '23 04:01 conceptofmind