Monday, July 29, 2024

Hooked the Dynamic AI Agent Workflow system into Google search

 I got the free edition api key from here:  

https://developers.google.com/custom-search/v1/introduction/?apix=true

It goes in the “header”: “{\“Content-Type\“: \“application/json\“, \“Accept\“: \“application/json\“, \“User-Agent\“: \“My Custom Search Client/1.0\“, \“X-Goog-Api-Key\“: \“Your key\“}”

Created the custom search engine here: 

  https://programmablesearchengine.google.com/controlpanel/all

“url”: “https://www.googleapis.com/customsearch/v1?q=hello+world&cx= Your custom engine number"

There are other "&" options you can do.

I think a &num=100 will get you 100 search results. But not sure.

OK, here is the complete list of options for the custom search:
https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list

The docs says you can do 10,000 searches a day with the free key, they are serving ads through the searches. Don't take my word on that. 

Oh, and it is a get, not a post.

I though a hello world search was apropo.

 
This is my workflow to do the google searches:

"google_search": {
"type": "workflow",
"help": "Do google search, analyze the results.",
"inputs": [
"request"
],
"optional_inputs": [],
"outputs": [
"response"
],
"steps": [
{
"agent": "build_url_request",
"params": {
"protocol": "https",
"host": "www.googleapis.com",
"endpoint": "customsearch/v1?q=",
"request": "$request"
},
"output": [
"url"
]
},
{
"agent": "exec_api_call_get",
"params": {
"url": "https://www.googleapis.com/customsearch/v1?q=
hello+world&cx=YourServerNumber",
"headers": "{\"Content-Type\": \"application/json\",
\"Accept\": \"application/json\",
\"User-Agent\": \"My Custom Search Client/1.0\",
\"X-Goog-Api-Key\": \"Your API Key\"}",
"payload": ""
},
"output": [
"response"
]
}
]
},

I am working on a little function to fully form the google url with all the options built in and some unit testing.

No comments:

Post a Comment