Merge branch 'master' into dev

This commit is contained in:
Andres Caicedo
2023-04-03 13:51:36 +02:00
26 changed files with 716 additions and 183 deletions

View File

@@ -8,16 +8,28 @@ from config import Config
import ai_functions as ai
from file_operations import read_file, write_to_file, append_to_file, delete_file
from execute_code import execute_python_file
from json_parser import fix_and_parse_json
from googlesearch import search
cfg = Config()
def get_command(response):
"""Parse the response and return the command name and arguments"""
try:
response_json = json.loads(response)
response_json = fix_and_parse_json(response)
if "command" not in response_json:
return "Error:" , "Missing 'command' object in JSON"
command = response_json["command"]
if "name" not in command:
return "Error:", "Missing 'name' field in 'command' object"
command_name = command["name"]
arguments = command["args"]
# Use an empty dictionary if 'args' field is not present in 'command' object
arguments = command.get("args", {})
if not arguments:
arguments = {}
@@ -35,8 +47,6 @@ def execute_command(command_name, arguments):
try:
if command_name == "google":
return google_search(arguments["input"])
elif command_name == "check_notifications":
return check_notifications(arguments["website"])
elif command_name == "memory_add":
return commit_memory(arguments["string"])
elif command_name == "memory_del":
@@ -54,12 +64,6 @@ def execute_command(command_name, arguments):
return list_agents()
elif command_name == "delete_agent":
return delete_agent(arguments["key"])
elif command_name == "navigate_website":
return navigate_website(arguments["action"], arguments["username"])
elif command_name == "register_account":
return register_account(
arguments["username"],
arguments["website"])
elif command_name == "get_text_summary":
return get_text_summary(arguments["url"])
elif command_name == "get_hyperlinks":
@@ -103,7 +107,7 @@ def get_datetime():
def google_search(query, num_results=8):
"""Return the results of a google search"""
search_results = []
for j in browse.search(query, num_results=num_results):
for j in search(query, num_results=num_results):
search_results.append(j)
return json.dumps(search_results, ensure_ascii=False, indent=4)
@@ -156,8 +160,8 @@ def delete_memory(key):
def overwrite_memory(key, string):
"""Overwrite a memory with a given key"""
if key >= 0 and key < len(mem.permanent_memory):
"""Overwrite a memory with a given key and string"""
if int(key) >= 0 and key < len(mem.permanent_memory):
_text = "Overwriting memory with key " + \
str(key) + " and string " + string
mem.permanent_memory[key] = string
@@ -174,7 +178,7 @@ def shutdown():
quit()
def start_agent(name, task, prompt, model="gpt-3.5-turbo"):
def start_agent(name, task, prompt, model=cfg.fast_llm_model):
"""Start an agent with a given name, task, and prompt"""
global cfg
@@ -220,23 +224,4 @@ def delete_agent(key):
result = agents.delete_agent(key)
if not result:
return f"Agent {key} does not exist."
return f"Agent {key} deleted."
def navigate_website(action, username):
_text = "Navigating website with action " + action + " and username " + username
print(_text)
return "Command not implemented yet."
def register_account(username, website):
_text = "Registering account with username " + \
username + " and website " + website
print(_text)
return "Command not implemented yet."
def check_notifications(website):
_text = "Checking notifications from " + website
print(_text)
return "Command not implemented yet."
return f"Agent {key} deleted."