#How to use a googling or search agent in GroupChat.

1 messages · Page 1 of 1 (latest)

topaz hinge
#

Hi All,
I am making a autogen solution with groupchat.
I want to know how to configure a groupchat so that googling agent provide some information if the question(user_proxy's message) needs online or real-time data by searching.

vocal night
#

Using the serper api is how i’ve done it and seen others do it.

topaz hinge
vocal night
#

def google_search(search_keyword):
"""
Function for google search and get relavant information for the given search keyword
:param search_keyword:
:return:
"""
url = "https://google.serper.dev/search"

payload = json.dumps({"q": search_keyword})

headers = {"X-API-KEY": serper_api_key, "Content-Type": "application/json"}

response = requests.request("POST", url, headers=headers, data=payload)
print("RESPONSE:", response.text)
return response.text

def web_scraping(objective: str, url: str):
"""
scrape website, and also will summarize the content based on objective if the content is too large
objective is the original objective & task that user give to the agent, url is the url of the website to be scraped
:param objective:
:param url:
:return:
"""

print("Scraping website...")
# Define the headers for the request
headers = {
    "Cache-Control": "no-cache",
    "Content-Type": "application/json",
}

# Define the data to be sent in the request
data = {"url": url}

# Convert Python object to JSON string
data_json = json.dumps(data)

# Send the POST request
response = requests.post(
    f"https://chrome.browserless.io/content?token={browserless_api_key}",
    headers=headers,
    data=data_json,
)

# Check the response status code
if response.status_code == 200:
    soup = BeautifulSoup(response.content, "html.parser")
    text = soup.get_text()
    print("CONTENTTTTTT:", text)
    if len(text) > 10000:
        output = summary(objective, text)
        return output
    else:
        return text
else:
    print(f"HTTP request failed with status code {response.status_code}")
#

sorry im on phone so couldn’t put in codeblock. But with that you pass it as a function to an agent and they should br able to get search results and you’ll likely need scraping too.

There are libraries for these things but for proof of concept api is the easiest, they’re free for basic usage though.