From 73bf928c1d252bc9b23f4453eb21caaa4bd836ef Mon Sep 17 00:00:00 2001 From: Bituq Date: Wed, 5 Apr 2023 15:50:28 +0200 Subject: [PATCH 01/13] fixed speech blocking main thread --- requirements.txt | 2 +- scripts/speak.py | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 158e932419..198b1b5046 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ beautifulsoup4 colorama==0.4.6 openai==0.27.2 -playsound==1.3.0 +playsound==1.2.2 python-dotenv==1.0.0 pyyaml==6.0 readability-lxml==0.8.1 diff --git a/scripts/speak.py b/scripts/speak.py index f6242a37dd..f98a9f445d 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -4,6 +4,8 @@ import requests from config import Config cfg = Config() import gtts +import threading +from threading import Lock # TODO: Nicer names for these ids @@ -14,18 +16,21 @@ tts_headers = { "xi-api-key": cfg.elevenlabs_api_key } +mutex_lock = Lock() # Ensure only one sound is played at a time + def eleven_labs_speech(text, voice_index=0): tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format( voice_id=voices[voice_index]) - formatted_message = {"text": text} + formatted_message = {"text": text, "voice_settings": {"stability": 0.05, "similarity_boost": 0.8}} response = requests.post( tts_url, headers=tts_headers, json=formatted_message) if response.status_code == 200: - with open("speech.mpeg", "wb") as f: - f.write(response.content) - playsound("speech.mpeg") - os.remove("speech.mpeg") + with mutex_lock: + with open("speech.mpeg", "wb") as f: + f.write(response.content) + playsound("speech.mpeg", True) + os.remove("speech.mpeg") return True else: print("Request failed with status code:", response.status_code) @@ -34,15 +39,19 @@ def eleven_labs_speech(text, voice_index=0): def gtts_speech(text): tts = gtts.gTTS(text) - tts.save("speech.mp3") - playsound("speech.mp3") - os.remove("speech.mp3") + with mutex_lock: + tts.save("speech.mp3") + playsound("speech.mp3", True) + os.remove("speech.mp3") def say_text(text, voice_index=0): - if not cfg.elevenlabs_api_key: - gtts_speech(text) - else: - success = eleven_labs_speech(text) - if not success: + def speak(): + if not cfg.elevenlabs_api_key: gtts_speech(text) + else: + success = eleven_labs_speech(text) + if not success: + gtts_speech(text) + thread = threading.Thread(target=speak) + thread.start() From 0cbd2bb3d03a18dd6da6cc4db2a15ab717c36b57 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 6 Apr 2023 11:59:46 +0200 Subject: [PATCH 02/13] Fix voice_index not being used --- scripts/speak.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/speak.py b/scripts/speak.py index f98a9f445d..6a966efc37 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -49,9 +49,9 @@ def say_text(text, voice_index=0): if not cfg.elevenlabs_api_key: gtts_speech(text) else: - success = eleven_labs_speech(text) + success = eleven_labs_speech(text, voice_index) if not success: gtts_speech(text) thread = threading.Thread(target=speak) - thread.start() + thread.start() \ No newline at end of file From ef4a02757f9ff55b96df27a7effcaa7685718f23 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 6 Apr 2023 14:02:39 +0200 Subject: [PATCH 03/13] Add semaphore to speak module --- scripts/speak.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/speak.py b/scripts/speak.py index 6a966efc37..0f8c243d50 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -5,7 +5,7 @@ from config import Config cfg = Config() import gtts import threading -from threading import Lock +from threading import Lock, Semaphore # TODO: Nicer names for these ids @@ -17,6 +17,7 @@ tts_headers = { } mutex_lock = Lock() # Ensure only one sound is played at a time +queue_semaphore = Semaphore(1) # The amount of sounds to queue before blocking the main thread def eleven_labs_speech(text, voice_index=0): tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format( @@ -52,6 +53,9 @@ def say_text(text, voice_index=0): success = eleven_labs_speech(text, voice_index) if not success: gtts_speech(text) + + queue_semaphore.release() + queue_semaphore.acquire(True) thread = threading.Thread(target=speak) thread.start() \ No newline at end of file From 5b2d6010dc59bab1026d13bfcd75b37618e573b9 Mon Sep 17 00:00:00 2001 From: kinance Date: Mon, 10 Apr 2023 20:10:11 +0900 Subject: [PATCH 04/13] Resolve the conflict around debug mode flag after pull merge --- scripts/config.py | 7 ++----- scripts/json_utils.py | 8 ++++---- scripts/main.py | 5 +---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 1eb74b2bc7..50432c425f 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -33,7 +33,7 @@ class Config(metaclass=Singleton): def __init__(self): """Initialize the Config class""" - self.debug = False + self.debug_mode = False self.continuous_mode = False self.speak_mode = False @@ -86,9 +86,6 @@ class Config(metaclass=Singleton): """Set the speak mode value.""" self.speak_mode = value - def set_debug_mode(self, value: bool): - self.debug_mode = value - def set_fast_llm_model(self, value: str): """Set the fast LLM model value.""" self.fast_llm_model = value @@ -131,4 +128,4 @@ class Config(metaclass=Singleton): def set_debug_mode(self, value: bool): """Set the debug mode value.""" - self.debug = value + self.debug_mode = value diff --git a/scripts/json_utils.py b/scripts/json_utils.py index b3ffe4b9ab..9f26970eaa 100644 --- a/scripts/json_utils.py +++ b/scripts/json_utils.py @@ -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 844c2375d2..34750fa04d 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -285,9 +285,6 @@ def parse_arguments(): 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 @@ -318,7 +315,7 @@ while True: user_input, full_message_history, memory, - cfg.fast_token_limit, cfg.debug) # TODO: This hardcodes the model to use GPT3.5. Make this an argument + cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument # Print Assistant thoughts print_assistant_thoughts(assistant_reply) From 88a802a675eaa0385e91a73d435fdd4c1e1c13d7 Mon Sep 17 00:00:00 2001 From: Dylan N <65708398+bituq@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:44:01 +0200 Subject: [PATCH 05/13] Remove voice_settings parameters I removed the voice_settings parameters as it was an irrelevant change. --- scripts/speak.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/speak.py b/scripts/speak.py index d8dd191bc3..8e0fbd9c4d 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -22,7 +22,7 @@ queue_semaphore = Semaphore(1) # The amount of sounds to queue before blocking t def eleven_labs_speech(text, voice_index=0): tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format( voice_id=voices[voice_index]) - formatted_message = {"text": text, "voice_settings": {"stability": 0.05, "similarity_boost": 0.8}} + formatted_message = {"text": text} response = requests.post( tts_url, headers=tts_headers, json=formatted_message) @@ -59,4 +59,4 @@ def say_text(text, voice_index=0): queue_semaphore.acquire(True) thread = threading.Thread(target=speak) - thread.start() \ No newline at end of file + thread.start() From 8cf58d00cfb43ece4236a35e7b5ea1d2fe359685 Mon Sep 17 00:00:00 2001 From: Sma Das Date: Mon, 10 Apr 2023 10:57:47 -0400 Subject: [PATCH 06/13] Removed unneeded imports --- scripts/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index f96afeb163..b433eb0ea5 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -8,8 +8,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 From 353785d23d4f2ea75fb5c1f3cd3ed4a0993a0912 Mon Sep 17 00:00:00 2001 From: Bituq Date: Tue, 11 Apr 2023 00:50:57 +0200 Subject: [PATCH 07/13] Fix macos_tts_speech merge conflict --- scripts/speak.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/speak.py b/scripts/speak.py index 8e0fbd9c4d..08b0c1c98e 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -20,6 +20,7 @@ mutex_lock = Lock() # Ensure only one sound is played at a time queue_semaphore = Semaphore(1) # The amount of sounds to queue before blocking the main thread def eleven_labs_speech(text, voice_index=0): + """Speak text using elevenlabs.io's API""" tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format( voice_id=voices[voice_index]) formatted_message = {"text": text} @@ -45,11 +46,17 @@ def gtts_speech(text): playsound("speech.mp3", True) os.remove("speech.mp3") +def macos_tts_speech(text): + os.system(f'say "{text}"') + def say_text(text, voice_index=0): def speak(): if not cfg.elevenlabs_api_key: - gtts_speech(text) + if cfg.use_mac_os_tts == 'True': + macos_tts_speech(text) + else: + gtts_speech(text) else: success = eleven_labs_speech(text, voice_index) if not success: From 9ecfde013f28381d8f18bebb0acd03f6de503231 Mon Sep 17 00:00:00 2001 From: Artemonim Date: Tue, 11 Apr 2023 02:34:58 +0300 Subject: [PATCH 08/13] Add `log.txt` to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0edd3047d3..2d60380168 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ outputs/* ai_settings.yaml .vscode auto-gpt.json +log.txt From 1b128a1ef0437bf0ddfa3ce33555d5cfb0124a07 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Mon, 10 Apr 2023 18:50:54 -0500 Subject: [PATCH 09/13] Use UTF-8 encoding for Windows users. --- scripts/file_operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/file_operations.py b/scripts/file_operations.py index 1b87cc2896..c6066ef930 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: From efcc6a3f767c1c71e8c83fac960b456d8d645ec3 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Mon, 10 Apr 2023 19:50:40 -0500 Subject: [PATCH 10/13] Update json_utils.py This was used differently in a local branch and an error. --- scripts/json_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/json_utils.py b/scripts/json_utils.py index b3ffe4b9ab..9508a937e5 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: From d12da33e55ec026be8cc5efdcaab4172e8d5631e Mon Sep 17 00:00:00 2001 From: Andy Melnikov Date: Mon, 10 Apr 2023 18:46:40 +0200 Subject: [PATCH 11/13] Fix flake8 W293 and W391 --- scripts/ai_config.py | 1 - scripts/browse.py | 2 +- scripts/chat.py | 4 ++-- scripts/json_parser.py | 6 +++--- scripts/main.py | 1 - 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 1d5832c182..2a4854cb97 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 09f376a70a..b0c745ef42 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 c00e4d4a60..23e5b50149 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/json_parser.py b/scripts/json_parser.py index 1fd6824408..8c17dfa252 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/main.py b/scripts/main.py index 8661bfad14..217461188d 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -415,4 +415,3 @@ while True: chat.create_chat_message( "system", "Unable to execute command")) print_to_console("SYSTEM: ", Fore.YELLOW, "Unable to execute command") - From b90f355e7d31cffd0969f9bdd292f862d16e5a9b Mon Sep 17 00:00:00 2001 From: onekum <55006697+onekum@users.noreply.github.com> Date: Tue, 11 Apr 2023 05:01:02 -0400 Subject: [PATCH 12/13] Change "an" to "a" Grammar error: In English, only words starting with (a, e, i, o, u) get "an". --- scripts/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.py b/scripts/main.py index 8661bfad14..7faf1d4293 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -170,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" From b06974904c5ce48da1681ef2d8a362cde59e90de Mon Sep 17 00:00:00 2001 From: kinance Date: Tue, 11 Apr 2023 19:26:23 +0900 Subject: [PATCH 13/13] Remove duplicates of set debug mode func --- scripts/config.py | 3 --- scripts/main.py | 4 ---- 2 files changed, 7 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 27cc946cf0..c9a285ac2c 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -89,9 +89,6 @@ class Config(metaclass=Singleton): """Set the speak mode value.""" self.speak_mode = value - def set_debug_mode(self, value: bool): - self.debug_mode = value - def set_fast_llm_model(self, value: str): """Set the fast LLM model value.""" self.fast_llm_model = value diff --git a/scripts/main.py b/scripts/main.py index 8661bfad14..6afcdf55b6 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -288,10 +288,6 @@ 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)