diff --git a/.gitignore b/.gitignore index 0edd3047..2d603801 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ outputs/* ai_settings.yaml .vscode auto-gpt.json +log.txt diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 1d5832c1..2a4854cb 100644 --- a/scripts/ai_config.py +++ b/scripts/ai_config.py @@ -92,4 +92,3 @@ class AIConfig: full_prompt += f"\n\n{data.load_prompt()}" return full_prompt - diff --git a/scripts/browse.py b/scripts/browse.py index 09f376a7..b0c745ef 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -15,7 +15,7 @@ def scrape_text(url): # Most basic check if the URL is valid: if not url.startswith('http'): return "Error: Invalid URL" - + # Restrict access to local files if check_local_file_access(url): return "Error: Access to local files is restricted" diff --git a/scripts/chat.py b/scripts/chat.py index c00e4d4a..23e5b501 100644 --- a/scripts/chat.py +++ b/scripts/chat.py @@ -63,10 +63,10 @@ def chat_with_ai( """ model = cfg.fast_llm_model # TODO: Change model from hardcode to argument # Reserve 1000 tokens for the response - + if cfg.debug: print(f"Token limit: {token_limit}") - + send_token_limit = token_limit - 1000 relevant_memory = permanent_memory.get_relevant(str(full_message_history[-5:]), 10) diff --git a/scripts/file_operations.py b/scripts/file_operations.py index 1b87cc28..c6066ef9 100644 --- a/scripts/file_operations.py +++ b/scripts/file_operations.py @@ -24,7 +24,7 @@ def read_file(filename): """Read a file and return the contents""" try: filepath = safe_join(working_directory, filename) - with open(filepath, "r") as f: + with open(filepath, "r", encoding='utf-8') as f: content = f.read() return content except Exception as e: diff --git a/scripts/json_parser.py b/scripts/json_parser.py index 1fd68244..8c17dfa2 100644 --- a/scripts/json_parser.py +++ b/scripts/json_parser.py @@ -71,11 +71,11 @@ def fix_and_parse_json( return json_str else: raise e - - + + def fix_json(json_str: str, schema: str) -> str: """Fix the given JSON string to make it parseable and fully complient with the provided schema.""" - + # Try to fix the JSON using gpt: function_string = "def fix_json(json_str: str, schema:str=None) -> str:" args = [f"'''{json_str}'''", f"'''{schema}'''"] diff --git a/scripts/json_utils.py b/scripts/json_utils.py index b3ffe4b9..80aab192 100644 --- a/scripts/json_utils.py +++ b/scripts/json_utils.py @@ -76,7 +76,7 @@ def balance_braces(json_string: str) -> str: json.loads(json_string) return json_string except json.JSONDecodeError as e: - raise e + pass def fix_invalid_escape(json_str: str, error_message: str) -> str: @@ -88,7 +88,7 @@ def fix_invalid_escape(json_str: str, error_message: str) -> str: json.loads(json_str) return json_str except json.JSONDecodeError as e: - if cfg.debug: + if cfg.debug_mode: print('json loads error - fix invalid escape', e) error_message = str(e) return json_str @@ -103,12 +103,12 @@ def correct_json(json_str: str) -> str: """ try: - if cfg.debug: + if cfg.debug_mode: print("json", json_str) json.loads(json_str) return json_str except json.JSONDecodeError as e: - if cfg.debug: + if cfg.debug_mode: print('json loads error', e) error_message = str(e) if error_message.startswith('Invalid \\escape'): @@ -119,7 +119,7 @@ def correct_json(json_str: str) -> str: json.loads(json_str) return json_str except json.JSONDecodeError as e: - if cfg.debug: + if cfg.debug_mode: print('json loads error - add quotes', e) error_message = str(e) if balanced_str := balance_braces(json_str): diff --git a/scripts/main.py b/scripts/main.py index 4be0b2aa..d84e1508 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -9,8 +9,6 @@ from colorama import Fore, Style from spinner import Spinner import time import speak -from enum import Enum, auto -import sys from config import Config from json_parser import fix_and_parse_json from ai_config import AIConfig @@ -172,7 +170,7 @@ def load_variables(config_file="config.yaml"): documents = yaml.dump(config, file) prompt = data.load_prompt() - prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.""" + prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as a LLM and pursue simple strategies with no legal complications.""" # Construct full prompt full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n" @@ -290,17 +288,10 @@ def parse_arguments(): print_to_console("Speak Mode: ", Fore.GREEN, "ENABLED") cfg.set_speak_mode(True) - if args.debug: - print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED") - cfg.set_debug_mode(True) - if args.gpt3only: print_to_console("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED") cfg.set_smart_llm_model(cfg.fast_llm_model) - if args.debug: - print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED") - cfg.set_debug_mode(True) # TODO: fill in llm values here @@ -417,4 +408,3 @@ while True: chat.create_chat_message( "system", "Unable to execute command")) print_to_console("SYSTEM: ", Fore.YELLOW, "Unable to execute command") -