farizrahman4u / loopgpt

Modular Auto-GPT Framework
MIT License
1.43k stars 131 forks source link

How to get a Google Search API key? #11

Closed thanpolas closed 1 year ago

thanpolas commented 1 year ago

hey, apologies for the noobish question but Google Developers portal is huge and highly confusing...

I have a google application created and issued an API key... I now understand that I need to enable "API & Services" for this application and API key, I could not find "Google Search" specifically in their list of services ( https://console.cloud.google.com/apis/library ), I was only able to find and enable the "Custom Search API", which I understood is search for a single or a set of websites (so you can enable search for your website).

I have added the (single) API key that I generated to both the GOOGLE_API_KEY and CUSTOM_SEARCH_ENGINE_ID environment variables, but loopgpt will error with various error messages when performing a "google_search" operation, errors like:

Command "google_search" failed with error: run() got an unexpected keyword argument 'response_format'

Command "google_search" failed with error: run() got an unexpected keyword argument 'results'

Command "google_search" failed with error: run() got an unexpected keyword argument 'params'

So I am a bit confused as to how create an appropriate API key to fill in the GOOGLE_API_KEY env variable that's needed for loopgpt to perform queries... Could you kindly point me to the right direction?

Also please clarify if we need both the GOOGLE_API_KEY and CUSTOM_SEARCH_ENGINE_ID and what each one does respectively.

Thank you for building this awesome tool :pray:

FayazRahman commented 1 year ago

Hey @thanpolas! Thanks a lot for trying out L♾️pGPT. We will work on fixing LoopGPT passing wrong arguments to google_search. For setting up the official google search, go to Google Programmable Search Engine, where you can create a custom search engine. Select "Search the entire web". This will give you your CUSTOM_SEARCH_ENGINE_ID. And then you need to enable "Custom Search API" and provide the CUSTOM_SEARCH_ENGINE_ID there too.

FYI, L♾️pGPT falls back on DuckDuckGo search (which doesn't require any API keys) if the official google search doesn't work (for example if you don't have all the api keys) so feel free to remove both API keys and it will automatically use DuckDuckGo search.

Let me know how it goes!

FayazRahman commented 1 year ago

@thanpolas PS. It will also be great if you can tell us the goals that produced this result.

thanpolas commented 1 year ago

Thank you for this, I will submit a PR to include this information on the README.

As to the query I cannot exactly recall it, is there a history of goals stored somewhere?

I did try to force a search by giving the following goal:

search for 1 news rss feed and show it to me

First step it searched for the rss with google_search, however, I am not sure if the result that got returned was sourced from google or duck... and then something weird happened, it thought it showed me the results but only pasted the template tag, see bellow:

image

FayazRahman commented 1 year ago

We don't have a history of the goals but thanks for taking the time @thanpolas! The repetition is a problem we're working on, need to find a way to make it more solid.