From 9fcf33cfb12370aa07b24e772b545ad3e436e729 Mon Sep 17 00:00:00 2001 From: Torantulino Date: Sat, 18 Mar 2023 01:40:50 +0000 Subject: [PATCH] Implements functioning google search --- AutonomousAI/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/AutonomousAI/main.py b/AutonomousAI/main.py index 409c910b..2090233a 100644 --- a/AutonomousAI/main.py +++ b/AutonomousAI/main.py @@ -1,5 +1,6 @@ import openai import json +from googlesearch import search def create_chat_message(role, content): """ Create a chat message with the given role and content. @@ -88,10 +89,12 @@ def execute_command(response): # except Exception as e: # return "Error: " + str(e) -def google_search(search): - _text = "Executing Google Search with term " + search - print(_text) - return _text +def google_search(query, num_results = 3): + search_results = [] + for j in search(query, num_results=num_results): + search_results.append(j) + + return json.dumps(search_results, ensure_ascii=False, indent=4) def check_news(source): _text = "Checking news from " + source