From 0cf790b633b417c092f84b52715f5ec057c045aa Mon Sep 17 00:00:00 2001 From: meta-fx Date: Mon, 10 Apr 2023 20:00:43 -0500 Subject: [PATCH 01/18] Added new env variable and speech function for alternative TTS voice --- .env.template | 1 + scripts/config.py | 11 ++++++++--- scripts/speak.py | 28 ++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index 01735615ca..98d2ca91e5 100644 --- a/.env.template +++ b/.env.template @@ -13,3 +13,4 @@ OPENAI_AZURE_DEPLOYMENT_ID=deployment-id-for-azure IMAGE_PROVIDER=dalle HUGGINGFACE_API_TOKEN= USE_MAC_OS_TTS=False +USE_BRIAN_TTS=False \ No newline at end of file diff --git a/scripts/config.py b/scripts/config.py index 27cc946cf0..3bf5cd9a81 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -57,7 +57,10 @@ class Config(metaclass=Singleton): self.use_mac_os_tts = False self.use_mac_os_tts = os.getenv("USE_MAC_OS_TTS") - + + self.use_brian_tts = False + self.use_brian_tts = os.getenv("USE_BRIAN_TTS") + self.google_api_key = os.getenv("GOOGLE_API_KEY") self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID") @@ -69,11 +72,13 @@ class Config(metaclass=Singleton): # User agent headers to use when browsing web # Some websites might just completely deny request with an error code if no user agent was found. - self.user_agent_header = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} + self.user_agent_header = { + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} self.redis_host = os.getenv("REDIS_HOST", "localhost") self.redis_port = os.getenv("REDIS_PORT", "6379") self.redis_password = os.getenv("REDIS_PASSWORD", "") - self.wipe_redis_on_start = os.getenv("WIPE_REDIS_ON_START", "True") == 'True' + self.wipe_redis_on_start = os.getenv( + "WIPE_REDIS_ON_START", "True") == 'True' self.memory_index = os.getenv("MEMORY_INDEX", 'auto-gpt') # Note that indexes must be created on db 0 in redis, this is not configureable. diff --git a/scripts/speak.py b/scripts/speak.py index 5d1e153c26..ebaae8d182 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -1,9 +1,9 @@ +import gtts import os from playsound import playsound import requests from config import Config cfg = Config() -import gtts # TODO: Nicer names for these ids @@ -14,6 +14,7 @@ tts_headers = { "xi-api-key": cfg.elevenlabs_api_key } + 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( @@ -33,23 +34,46 @@ def eleven_labs_speech(text, voice_index=0): print("Response content:", response.content) return False + +def brian_speech(text): + """Speak text using Brian with the streamelements API""" + tts_url = f"https://api.streamelements.com/kappa/v2/speech?voice=Brian&text={text}" + response = requests.get(tts_url) + + if response.status_code == 200: + with open("speech.mp3", "wb") as f: + f.write(response.content) + playsound("speech.mp3") + os.remove("speech.mp3") + return True + else: + print("Request failed with status code:", response.status_code) + print("Response content:", response.content) + return False + + def gtts_speech(text): tts = gtts.gTTS(text) tts.save("speech.mp3") playsound("speech.mp3") os.remove("speech.mp3") + def macos_tts_speech(text): os.system(f'say "{text}"') + def say_text(text, voice_index=0): if not cfg.elevenlabs_api_key: if cfg.use_mac_os_tts == 'True': macos_tts_speech(text) + elif cfg.use_brian_tts == 'True': + success = brian_speech(text) + if not success: + gtts_speech(text) else: gtts_speech(text) else: success = eleven_labs_speech(text, voice_index) if not success: gtts_speech(text) - From 3ee62211db3003312e09ff02517b0f250d7717a6 Mon Sep 17 00:00:00 2001 From: meta-fx Date: Mon, 10 Apr 2023 20:56:27 -0500 Subject: [PATCH 02/18] Fixed formatting issues --- scripts/config.py | 8 +++----- scripts/speak.py | 9 ++------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 3bf5cd9a81..f636da7dfd 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -72,13 +72,11 @@ class Config(metaclass=Singleton): # User agent headers to use when browsing web # Some websites might just completely deny request with an error code if no user agent was found. - self.user_agent_header = { - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} + self.user_agent_header = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} self.redis_host = os.getenv("REDIS_HOST", "localhost") self.redis_port = os.getenv("REDIS_PORT", "6379") self.redis_password = os.getenv("REDIS_PASSWORD", "") - self.wipe_redis_on_start = os.getenv( - "WIPE_REDIS_ON_START", "True") == 'True' + self.wipe_redis_on_start = os.getenv("WIPE_REDIS_ON_START", "True") == 'True' self.memory_index = os.getenv("MEMORY_INDEX", 'auto-gpt') # Note that indexes must be created on db 0 in redis, this is not configureable. @@ -139,4 +137,4 @@ class Config(metaclass=Singleton): def set_debug_mode(self, value: bool): """Set the debug mode value.""" - self.debug = value + self.debug = value \ No newline at end of file diff --git a/scripts/speak.py b/scripts/speak.py index ebaae8d182..2464c62596 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -1,9 +1,9 @@ -import gtts import os from playsound import playsound import requests from config import Config cfg = Config() +import gtts # TODO: Nicer names for these ids @@ -14,7 +14,6 @@ tts_headers = { "xi-api-key": cfg.elevenlabs_api_key } - 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( @@ -34,7 +33,6 @@ def eleven_labs_speech(text, voice_index=0): print("Response content:", response.content) return False - def brian_speech(text): """Speak text using Brian with the streamelements API""" tts_url = f"https://api.streamelements.com/kappa/v2/speech?voice=Brian&text={text}" @@ -51,18 +49,15 @@ def brian_speech(text): print("Response content:", response.content) return False - def gtts_speech(text): tts = gtts.gTTS(text) tts.save("speech.mp3") playsound("speech.mp3") os.remove("speech.mp3") - def macos_tts_speech(text): os.system(f'say "{text}"') - def say_text(text, voice_index=0): if not cfg.elevenlabs_api_key: if cfg.use_mac_os_tts == 'True': @@ -76,4 +71,4 @@ def say_text(text, voice_index=0): else: success = eleven_labs_speech(text, voice_index) if not success: - gtts_speech(text) + gtts_speech(text) \ No newline at end of file From 3cdde2d49cba4b43045ebef7f16236fed3a4acc9 Mon Sep 17 00:00:00 2001 From: meta-fx Date: Tue, 11 Apr 2023 08:15:58 -0500 Subject: [PATCH 03/18] Resolved conflicts in config.py and speak.py --- scripts/config.py | 7 ++---- scripts/speak.py | 60 ++++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index f636da7dfd..cdf0287c4b 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 @@ -92,9 +92,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 @@ -137,4 +134,4 @@ class Config(metaclass=Singleton): def set_debug_mode(self, value: bool): """Set the debug mode value.""" - self.debug = value \ No newline at end of file + self.debug_mode = value \ No newline at end of file diff --git a/scripts/speak.py b/scripts/speak.py index 2464c62596..bf5c6034fa 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, Semaphore # TODO: Nicer names for these ids @@ -14,6 +16,9 @@ tts_headers = { "xi-api-key": cfg.elevenlabs_api_key } +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( @@ -23,10 +28,11 @@ def eleven_labs_speech(text, voice_index=0): 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) @@ -39,10 +45,11 @@ def brian_speech(text): response = requests.get(tts_url) if response.status_code == 200: - with open("speech.mp3", "wb") as f: - f.write(response.content) - playsound("speech.mp3") - os.remove("speech.mp3") + with mutex_lock: + with open("speech.mp3", "wb") as f: + f.write(response.content) + playsound("speech.mp3") + os.remove("speech.mp3") return True else: print("Request failed with status code:", response.status_code) @@ -51,24 +58,33 @@ def brian_speech(text): 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 macos_tts_speech(text): os.system(f'say "{text}"') def say_text(text, voice_index=0): - if not cfg.elevenlabs_api_key: - if cfg.use_mac_os_tts == 'True': - macos_tts_speech(text) - elif cfg.use_brian_tts == 'True': - success = brian_speech(text) - if not success: + + def speak(): + if not cfg.elevenlabs_api_key: + if cfg.use_mac_os_tts == 'True': + macos_tts_speech(text) + elif cfg.use_brian_tts == 'True': + success = brian_speech(text) + if not success: + gtts_speech(text) + else: gtts_speech(text) else: - gtts_speech(text) - else: - success = eleven_labs_speech(text, voice_index) - if not success: - gtts_speech(text) \ No newline at end of file + 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 570f76bd51a2f01c78788938eadc17348bb92fe3 Mon Sep 17 00:00:00 2001 From: meta-fx Date: Tue, 11 Apr 2023 14:40:05 -0500 Subject: [PATCH 04/18] Removed trailing spaces and fixed CRLF being removed --- scripts/config.py | 4 ++-- scripts/speak.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index cdf0287c4b..c4ad3bf4eb 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -72,7 +72,7 @@ class Config(metaclass=Singleton): # User agent headers to use when browsing web # Some websites might just completely deny request with an error code if no user agent was found. - self.user_agent_header = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} + self.user_agent_header = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} self.redis_host = os.getenv("REDIS_HOST", "localhost") self.redis_port = os.getenv("REDIS_PORT", "6379") self.redis_password = os.getenv("REDIS_PASSWORD", "") @@ -134,4 +134,4 @@ class Config(metaclass=Singleton): def set_debug_mode(self, value: bool): """Set the debug mode value.""" - self.debug_mode = value \ No newline at end of file + self.debug_mode = value diff --git a/scripts/speak.py b/scripts/speak.py index bf5c6034fa..4934ecef1d 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -67,7 +67,7 @@ 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: if cfg.use_mac_os_tts == 'True': @@ -87,4 +87,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 41f17f89043b19e7a5990894996c6dc407d734c0 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Thu, 13 Apr 2023 16:02:15 +0200 Subject: [PATCH 05/18] Small README.md clarity update and usage fixup --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d12ae23a2..90706cbff1 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,11 @@ Your support is greatly appreciated - [Python 3.8 or later](https://www.tutorialspoint.com/how-to-install-python-in-windows) - [OpenAI API key](https://platform.openai.com/account/api-keys) -- [PINECONE API key](https://www.pinecone.io/) + Optional: +- [PINECONE API key](https://www.pinecone.io/) (If you want Pinecone backed memory) - ElevenLabs Key (If you want the AI to speak) ## 💾 Installation @@ -114,8 +115,8 @@ pip install -r requirements.txt python scripts/main.py ``` -2. After each of AUTO-GPT's actions, type "NEXT COMMAND" to authorise them to continue. -3. To exit the program, type "exit" and press Enter. +2. After each of action, enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter additional feedback for the AI. + ### Logs @@ -217,7 +218,10 @@ Pinecone enables the storage of vast amounts of vector-based memory, allowing fo ### Setting up environment variables -Simply set them in the `.env` file. +In the `.env` file set: +- `PINECONE_API_KEY` +- `PINECONE_ENV` (something like: us-east4-gcp) +- `MEMORY_BACKEND=pinecone` Alternatively, you can set them from the command line (advanced): @@ -226,7 +230,7 @@ For Windows Users: ``` setx PINECONE_API_KEY "YOUR_PINECONE_API_KEY" setx PINECONE_ENV "Your pinecone region" # something like: us-east4-gcp - +setx MEMORY_BACKEND "pinecone" ``` For macOS and Linux users: @@ -234,7 +238,7 @@ For macOS and Linux users: ``` export PINECONE_API_KEY="YOUR_PINECONE_API_KEY" export PINECONE_ENV="Your pinecone region" # something like: us-east4-gcp - +export MEMORY_BACKEND="pinecone" ``` From f9cbddc9f06baed21bc5bc0f3bd6848310240737 Mon Sep 17 00:00:00 2001 From: Ron Balter <44070810+Ronbalt@users.noreply.github.com> Date: Fri, 14 Apr 2023 00:58:51 +0300 Subject: [PATCH 06/18] Enable Custom Search API in gcp project While following this guide to enable google search, this step was missing for me and the API calls to https://customsearch.googleapis.com/customsearch/v1?q= failed with: """ Custom Search API has not been used in project before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/customsearch.googleapis.com/overview?project= then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. """ Also, checked that merely https://console.developers.google.com/apis/api/customsearch.googleapis.com redirects to the active project used in the last session in GCP, so no need to provide the projectId parameter. --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d11219769c..3d8fd003b6 100644 --- a/README.md +++ b/README.md @@ -154,9 +154,10 @@ To use the `google_official_search` command, you need to set up your Google API 4. Go to the [APIs & Services Dashboard](https://console.cloud.google.com/apis/dashboard) and click "Enable APIs and Services". Search for "Custom Search API" and click on it, then click "Enable". 5. Go to the [Credentials](https://console.cloud.google.com/apis/credentials) page and click "Create Credentials". Choose "API Key". 6. Copy the API key and set it as an environment variable named `GOOGLE_API_KEY` on your machine. See setting up environment variables below. -7. Go to the [Custom Search Engine](https://cse.google.com/cse/all) page and click "Add". -8. Set up your search engine by following the prompts. You can choose to search the entire web or specific sites. -9. Once you've created your search engine, click on "Control Panel" and then "Basics". Copy the "Search engine ID" and set it as an environment variable named `CUSTOM_SEARCH_ENGINE_ID` on your machine. See setting up environment variables below. +7. [Enable](https://console.developers.google.com/apis/api/customsearch.googleapis.com) the Custom Search API on your project. (Might need to wait few minutes to propagate) +8. Go to the [Custom Search Engine](https://cse.google.com/cse/all) page and click "Add". +9. Set up your search engine by following the prompts. You can choose to search the entire web or specific sites. +10. Once you've created your search engine, click on "Control Panel" and then "Basics". Copy the "Search engine ID" and set it as an environment variable named `CUSTOM_SEARCH_ENGINE_ID` on your machine. See setting up environment variables below. _Remember that your free daily custom search quota allows only up to 100 searches. To increase this limit, you need to assign a billing account to the project to profit from up to 10K daily searches._ @@ -357,4 +358,4 @@ flake8 scripts/ tests/ # Or, if you want to run flake8 with the same configuration as the CI: flake8 scripts/ tests/ --select E303,W293,W291,W292,E305,E231,E302 -``` \ No newline at end of file +``` From c59b6b5543793a01d1231552f6c81f4f72ddc740 Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Thu, 13 Apr 2023 15:19:41 -0700 Subject: [PATCH 07/18] wrap infinite loop in class agent --- scripts/main.py | 226 ++++++++++++++++++++++++++++-------------------- 1 file changed, 132 insertions(+), 94 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index 466f50dd1c..9c823ab110 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -351,110 +351,148 @@ def main(): # this is particularly important for indexing and referencing pinecone memory memory = get_memory(cfg, init=True) print('Using memory of type: ' + memory.__class__.__name__) - # Interaction Loop - loop_count = 0 - while True: - # Discontinue if continuous limit is reached - loop_count += 1 - if cfg.continuous_mode and cfg.continuous_limit > 0 and loop_count > cfg.continuous_limit: - logger.typewriter_log("Continuous Limit Reached: ", Fore.YELLOW, f"{cfg.continuous_limit}") - break + agent = Agent( + ai_name=ai_name, + memory=memory, + full_message_history=full_message_history, + next_action_count=next_action_count, + prompt=prompt, + user_input=user_input + ) + agent.start_interaction_loop() - # Send message to AI, get response - with Spinner("Thinking... "): - assistant_reply = chat.chat_with_ai( - prompt, - user_input, - full_message_history, - memory, - 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) +class Agent: + """Agent class for interacting with Auto-GPT. - # Get command name and arguments - try: - command_name, arguments = cmd.get_command( - attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply)) - if cfg.speak_mode: - speak.say_text(f"I want to execute {command_name}") - except Exception as e: - logger.error("Error: \n", str(e)) + Attributes: + ai_name: The name of the agent. + memory: The memory object to use. + full_message_history: The full message history. + next_action_count: The number of actions to execute. + prompt: The prompt to use. + user_input: The user input. - if not cfg.continuous_mode and next_action_count == 0: - ### GET USER AUTHORIZATION TO EXECUTE COMMAND ### - # Get key press: Prompt the user to press enter to continue or escape - # to exit - user_input = "" - logger.typewriter_log( - "NEXT ACTION: ", - Fore.CYAN, - f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") - print( - f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", - flush=True) - while True: - console_input = utils.clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) - if console_input.lower().rstrip() == "y": - user_input = "GENERATE NEXT COMMAND JSON" - break - elif console_input.lower().startswith("y -"): - try: - next_action_count = abs(int(console_input.split(" ")[1])) - user_input = "GENERATE NEXT COMMAND JSON" - except ValueError: - print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.") - continue - break - elif console_input.lower() == "n": - user_input = "EXIT" - break - else: - user_input = console_input - command_name = "human_feedback" - break + """ + def __init__(self, + ai_name, + memory, + full_message_history, + next_action_count, + prompt, + user_input): + self.ai_name = ai_name + self.memory = memory + self.full_message_history = full_message_history + self.next_action_count = next_action_count + self.prompt = prompt + self.user_input = user_input - if user_input == "GENERATE NEXT COMMAND JSON": - logger.typewriter_log( - "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", - Fore.MAGENTA, - "") - elif user_input == "EXIT": - print("Exiting...", flush=True) + def start_interaction_loop(self): + # Interaction Loop + loop_count = 0 + while True: + # Discontinue if continuous limit is reached + loop_count += 1 + if cfg.continuous_mode and cfg.continuous_limit > 0 and loop_count > cfg.continuous_limit: + logger.typewriter_log("Continuous Limit Reached: ", Fore.YELLOW, f"{cfg.continuous_limit}") break - else: - # Print command - logger.typewriter_log( - "NEXT ACTION: ", - Fore.CYAN, - f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") - # Execute command - if command_name is not None and command_name.lower().startswith("error"): - result = f"Command {command_name} threw the following error: " + arguments - elif command_name == "human_feedback": - result = f"Human feedback: {user_input}" - else: - result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}" - if next_action_count > 0: - next_action_count -= 1 + # Send message to AI, get response + with Spinner("Thinking... "): + assistant_reply = chat.chat_with_ai( + self.prompt, + self.user_input, + self.full_message_history, + self.memory, + cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument - memory_to_add = f"Assistant Reply: {assistant_reply} " \ - f"\nResult: {result} " \ - f"\nHuman Feedback: {user_input} " + # Print Assistant thoughts + print_assistant_thoughts(assistant_reply) - memory.add(memory_to_add) + # Get command name and arguments + try: + command_name, arguments = cmd.get_command( + attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply)) + if cfg.speak_mode: + speak.say_text(f"I want to execute {command_name}") + except Exception as e: + logger.error("Error: \n", str(e)) - # Check if there's a result from the command append it to the message - # history - if result is not None: - full_message_history.append(chat.create_chat_message("system", result)) - logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result) - else: - full_message_history.append( - chat.create_chat_message( - "system", "Unable to execute command")) - logger.typewriter_log("SYSTEM: ", Fore.YELLOW, "Unable to execute command") + if not cfg.continuous_mode and self.next_action_count == 0: + ### GET USER AUTHORIZATION TO EXECUTE COMMAND ### + # Get key press: Prompt the user to press enter to continue or escape + # to exit + self.user_input = "" + logger.typewriter_log( + "NEXT ACTION: ", + Fore.CYAN, + f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") + print( + f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {self.ai_name}...", + flush=True) + while True: + console_input = utils.clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) + if console_input.lower().rstrip() == "y": + self.user_input = "GENERATE NEXT COMMAND JSON" + break + elif console_input.lower().startswith("y -"): + try: + self.next_action_count = abs(int(console_input.split(" ")[1])) + self.user_input = "GENERATE NEXT COMMAND JSON" + except ValueError: + print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.") + continue + break + elif console_input.lower() == "n": + self.user_input = "EXIT" + break + else: + self.user_input = console_input + command_name = "human_feedback" + break + + if self.user_input == "GENERATE NEXT COMMAND JSON": + logger.typewriter_log( + "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", + Fore.MAGENTA, + "") + elif self.user_input == "EXIT": + print("Exiting...", flush=True) + break + else: + # Print command + logger.typewriter_log( + "NEXT ACTION: ", + Fore.CYAN, + f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") + + # Execute command + if command_name is not None and command_name.lower().startswith("error"): + result = f"Command {command_name} threw the following error: " + arguments + elif command_name == "human_feedback": + result = f"Human feedback: {self.user_input}" + else: + result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}" + if self.next_action_count > 0: + self.next_action_count -= 1 + + memory_to_add = f"Assistant Reply: {assistant_reply} " \ + f"\nResult: {result} " \ + f"\nHuman Feedback: {self.user_input} " + + self.memory.add(memory_to_add) + + # Check if there's a result from the command append it to the message + # history + if result is not None: + self.full_message_history.append(chat.create_chat_message("system", result)) + logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result) + else: + self.full_message_history.append( + chat.create_chat_message( + "system", "Unable to execute command")) + logger.typewriter_log("SYSTEM: ", Fore.YELLOW, "Unable to execute command") if __name__ == "__main__": From 43efbff4b80edbad2fc35010773372e76c3eb34b Mon Sep 17 00:00:00 2001 From: Merwane Hamadi Date: Thu, 13 Apr 2023 15:22:43 -0700 Subject: [PATCH 08/18] remove useless load_variables_method --- scripts/main.py | 54 ------------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index 466f50dd1c..1425e4200a 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -129,60 +129,6 @@ def print_assistant_thoughts(assistant_reply): logger.error("Error: \n", call_stack) -def load_variables(config_file="config.yaml"): - """Load variables from yaml file if it exists, otherwise prompt the user for input""" - try: - with open(config_file) as file: - config = yaml.load(file, Loader=yaml.FullLoader) - ai_name = config.get("ai_name") - ai_role = config.get("ai_role") - ai_goals = config.get("ai_goals") - except FileNotFoundError: - ai_name = "" - ai_role = "" - ai_goals = [] - - # Prompt the user for input if config file is missing or empty values - if not ai_name: - ai_name = utils.clean_input("Name your AI: ") - if ai_name == "": - ai_name = "Entrepreneur-GPT" - - if not ai_role: - ai_role = utils.clean_input(f"{ai_name} is: ") - if ai_role == "": - ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth." - - if not ai_goals: - print("Enter up to 5 goals for your AI: ") - print("For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'") - print("Enter nothing to load defaults, enter nothing when finished.") - ai_goals = [] - for i in range(5): - ai_goal = utils.clean_input(f"Goal {i+1}: ") - if ai_goal == "": - break - ai_goals.append(ai_goal) - if len(ai_goals) == 0: - ai_goals = ["Increase net worth", "Grow Twitter Account", "Develop and manage multiple businesses autonomously"] - - # Save variables to yaml file - config = {"ai_name": ai_name, "ai_role": ai_role, "ai_goals": ai_goals} - with open(config_file, "w") as file: - documents = yaml.dump(config, file) - - prompt = get_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.""" - - # Construct full prompt - full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n" - for i, goal in enumerate(ai_goals): - full_prompt += f"{i+1}. {goal}\n" - - full_prompt += f"\n\n{prompt}" - return full_prompt - - def construct_prompt(): """Construct the prompt for the AI to respond to""" config = AIConfig.load() From 4666ea015074506196762cc8008489d06a3d02bb Mon Sep 17 00:00:00 2001 From: Jesse R Weigel Date: Thu, 13 Apr 2023 21:57:31 -0400 Subject: [PATCH 09/18] fix misspelling --- scripts/call_ai_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/call_ai_function.py b/scripts/call_ai_function.py index 6f1d6ceee8..940eacfe0f 100644 --- a/scripts/call_ai_function.py +++ b/scripts/call_ai_function.py @@ -13,7 +13,7 @@ def call_ai_function(function, args, description, model=None): model = cfg.smart_llm_model # For each arg, if any are None, convert to "None": args = [str(arg) if arg is not None else "None" for arg in args] - # parse args to comma seperated string + # parse args to comma separated string args = ", ".join(args) messages = [ { From 1f21998f0c2115a76b1c53ae2b89ea581d2fd106 Mon Sep 17 00:00:00 2001 From: sunnypranay Date: Thu, 13 Apr 2023 21:47:28 -0500 Subject: [PATCH 10/18] Improve Dockerfile with best practices and optimizations --- Dockerfile | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4d264c88c8..e776664e84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,23 @@ +# Use an official Python base image from the Docker Hub FROM python:3.11-slim -ENV PIP_NO_CACHE_DIR=yes -WORKDIR /app -COPY requirements.txt . -RUN pip install -r requirements.txt -COPY scripts/ . -ENTRYPOINT ["python", "main.py"] + +# Set environment variables +ENV PIP_NO_CACHE_DIR=yes \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 + +# Create a non-root user and set permissions +RUN useradd --create-home appuser +WORKDIR /home/appuser +RUN chown appuser:appuser /home/appuser +USER appuser + +# Copy the requirements.txt file and install the requirements +COPY --chown=appuser:appuser requirements.txt . +RUN pip install --no-cache-dir --user -r requirements.txt + +# Copy the application files +COPY --chown=appuser:appuser scripts/ . + +# Set the entrypoint +ENTRYPOINT ["python", "main.py"] \ No newline at end of file From aeb81aa597a1eedcddcc42b060b98580a1870324 Mon Sep 17 00:00:00 2001 From: eng-cc <66scc66@gmail.com> Date: Fri, 14 Apr 2023 10:54:59 +0800 Subject: [PATCH 11/18] [environments] add devcontainer environment --- .devcontainer/Dockerfile | 23 +++++++++++++++++++ .devcontainer/devcontainer.json | 39 +++++++++++++++++++++++++++++++++ README.md | 4 +++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..f3b2e2dbb5 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,23 @@ +# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster +ARG VARIANT=3-bullseye +FROM python:3.8 + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131 + && apt-get purge -y imagemagick imagemagick-6-common + +# Temporary: Upgrade python packages due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-40897 +# They are installed by the base image (python) which does not have the patch. +RUN python3 -m pip install --upgrade setuptools + +# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. +# COPY requirements.txt /tmp/pip-tmp/ +# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ +# && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..5fefd9c13d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +{ + "build": { + "dockerfile": "./Dockerfile", + "context": "." + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "true", + "username": "vscode", + "userUid": "1000", + "userGid": "1000", + "upgradePackages": "true" + }, + "ghcr.io/devcontainers/features/python:1": "none", + "ghcr.io/devcontainers/features/node:1": "none", + "ghcr.io/devcontainers/features/git:1": { + "version": "latest", + "ppa": "false" + } + }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python" + } + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/README.md b/README.md index d11219769c..849679977c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,9 @@ Your support is greatly appreciated ## 📋 Requirements -- [Python 3.8 or later](https://www.tutorialspoint.com/how-to-install-python-in-windows) +- environments(just choose one) + - [vscode + devcontainer](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers): It has been configured in the .devcontainer folder and can be used directly + - [Python 3.8 or later](https://www.tutorialspoint.com/how-to-install-python-in-windows) - [OpenAI API key](https://platform.openai.com/account/api-keys) - [PINECONE API key](https://www.pinecone.io/) From 3128397988de6dc5280eb45cca814e98cd8c0a2d Mon Sep 17 00:00:00 2001 From: GyDi Date: Fri, 14 Apr 2023 11:17:46 +0800 Subject: [PATCH 12/18] fix: remove duplicate debug mode logger --- scripts/main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index 466f50dd1c..0221af4c72 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -318,10 +318,6 @@ def parse_arguments(): logger.typewriter_log("GPT4 Only Mode: ", Fore.GREEN, "ENABLED") cfg.set_fast_llm_model(cfg.smart_llm_model) - if args.debug: - logger.typewriter_log("Debug Mode: ", Fore.GREEN, "ENABLED") - cfg.set_debug_mode(True) - if args.memory_type: supported_memory = get_supported_memory_backends() chosen = args.memory_type From 5e6d0b620a582f2f143d91df1921d44c22e648df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E5=B0=94=E7=B4=A2?= Date: Fri, 14 Apr 2023 11:38:29 +0800 Subject: [PATCH 13/18] Resolving Unicode encoding issues Solve the problem that Chinese, Japanese, Korean and other non-English languages are all encoded in Unicode when writing ai_settings.yaml configuration. --- scripts/ai_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 4eb076ef2d..89a4e07eaa 100644 --- a/scripts/ai_config.py +++ b/scripts/ai_config.py @@ -70,8 +70,8 @@ class AIConfig: """ config = {"ai_name": self.ai_name, "ai_role": self.ai_role, "ai_goals": self.ai_goals} - with open(config_file, "w") as file: - yaml.dump(config, file) + with open(config_file, "w", encoding='utf-8') as file: + yaml.dump(config, file, allow_unicode=True) def construct_full_prompt(self) -> str: """ From 2fd96b68bdc9e7ab48b34eeff8d96e32b9eafdcf Mon Sep 17 00:00:00 2001 From: meta-fx Date: Fri, 14 Apr 2023 01:28:47 -0500 Subject: [PATCH 14/18] Added new line and elevenlabs elements back to the env --- .env.template | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index aa7b04e977..e22ce4f522 100644 --- a/.env.template +++ b/.env.template @@ -104,4 +104,12 @@ USE_MAC_OS_TTS=False ### STREAMELEMENTS # USE_BRIAN_TTS - Use Brian TTS or not (Default: False) -USE_BRIAN_TTS=False \ No newline at end of file +USE_BRIAN_TTS=False + +### ELEVENLABS +# ELEVENLABS_API_KEY - Eleven Labs API key (Example: my-elevenlabs-api-key) +# ELEVENLABS_VOICE_1_ID - Eleven Labs voice 1 ID (Example: my-voice-id-1) +# ELEVENLABS_VOICE_2_ID - Eleven Labs voice 2 ID (Example: my-voice-id-2) +ELEVENLABS_API_KEY=your-elevenlabs-api-key +ELEVENLABS_VOICE_1_ID=your-voice-id-1 +ELEVENLABS_VOICE_2_ID=your-voice-id-2 From 1612069594402540da4116f9f599b47091b8f041 Mon Sep 17 00:00:00 2001 From: meta-fx Date: Fri, 14 Apr 2023 02:18:17 -0500 Subject: [PATCH 15/18] Fixed E302 expected 2 blank lines, found 1 --- scripts/speak.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/speak.py b/scripts/speak.py index d71b5bcac6..3afa591dd5 100644 --- a/scripts/speak.py +++ b/scripts/speak.py @@ -52,6 +52,7 @@ def eleven_labs_speech(text, voice_index=0): print("Response content:", response.content) return False + def brian_speech(text): """Speak text using Brian with the streamelements API""" tts_url = f"https://api.streamelements.com/kappa/v2/speech?voice=Brian&text={text}" @@ -69,6 +70,7 @@ def brian_speech(text): print("Response content:", response.content) return False + def gtts_speech(text): tts = gtts.gTTS(text) with mutex_lock: From 475edd3b40c8769b22519083af2106bcbd08e559 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Fri, 14 Apr 2023 12:32:33 +0100 Subject: [PATCH 16/18] make the path reference in logger more robust --- scripts/logger.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/logger.py b/scripts/logger.py index 91bdb6f605..4c7e588f20 100644 --- a/scripts/logger.py +++ b/scripts/logger.py @@ -24,7 +24,8 @@ For console handler: simulates typing class Logger(metaclass=Singleton): def __init__(self): # create log directory if it doesn't exist - log_dir = os.path.join('..', 'logs') + this_files_dir_path = os.path.dirname(__file__) + log_dir = os.path.join(this_files_dir_path, '../logs') if not os.path.exists(log_dir): os.makedirs(log_dir) From 9e27e0165d15d441e58e5771e22957ae4fbd0063 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Fri, 14 Apr 2023 12:36:18 +0100 Subject: [PATCH 17/18] gitignore the logs file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cf6e75df15..0a98328ca6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ last_run_ai_settings.yaml .idea/* auto-gpt.json log.txt +logs # Coverage reports .coverage From b18530a9854f7b3e0cd5fb8333221bb0000cc4cb Mon Sep 17 00:00:00 2001 From: sagarishere <5121817+sagarishere@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:31:45 +0300 Subject: [PATCH 18/18] update to modern python format syntax update to modern python format syntax no logic change --- scripts/spinner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/spinner.py b/scripts/spinner.py index df1f4ddf93..d232152926 100644 --- a/scripts/spinner.py +++ b/scripts/spinner.py @@ -17,10 +17,10 @@ class Spinner: def spin(self): """Spin the spinner""" while self.running: - sys.stdout.write(next(self.spinner) + " " + self.message + "\r") + sys.stdout.write(f"{next(self.spinner)} {self.message}\r") sys.stdout.flush() time.sleep(self.delay) - sys.stdout.write('\r' + ' ' * (len(self.message) + 2) + '\r') + sys.stdout.write(f"\r{' ' * (len(self.message) + 2)}\r") def __enter__(self): """Start the spinner""" @@ -32,5 +32,5 @@ class Spinner: """Stop the spinner""" self.running = False self.spinner_thread.join() - sys.stdout.write('\r' + ' ' * (len(self.message) + 2) + '\r') + sys.stdout.write(f"\r{' ' * (len(self.message) + 2)}\r") sys.stdout.flush()