From 4a077909108c7089e8eb688ea12ddeb087483ed9 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:09:07 +0100 Subject: [PATCH 1/4] Added ability to output news/announcements on startup --- BULLETIN.md | 2 ++ autogpt/cli.py | 12 ++++++++++++ autogpt/config/config.py | 1 + autogpt/configurator.py | 6 +++++- autogpt/utils.py | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 BULLETIN.md diff --git a/BULLETIN.md b/BULLETIN.md new file mode 100644 index 00000000..735048dd --- /dev/null +++ b/BULLETIN.md @@ -0,0 +1,2 @@ +Welcome to Auto-GPT! We'll keep you informed of the latest news and features by printing messages here. +If you don't wish to see this message, you can run Auto-GPT with the --skip-news flag \ No newline at end of file diff --git a/autogpt/cli.py b/autogpt/cli.py index 8ed9abb0..323c126b 100644 --- a/autogpt/cli.py +++ b/autogpt/cli.py @@ -42,6 +42,11 @@ import click is_flag=True, help="Dangerous: Allows Auto-GPT to download files natively.", ) +@click.option( + "--skip-news", + is_flag=True, + help="Specifies whether to suppress the output of latest news on startup.", +) @click.pass_context def main( ctx: click.Context, @@ -56,6 +61,7 @@ def main( memory_type: str, browser_name: str, allow_downloads: bool, + skip_news: bool ) -> None: """ Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI. @@ -73,6 +79,7 @@ def main( from autogpt.logs import logger from autogpt.memory import get_memory from autogpt.prompt import construct_prompt + from autogpt.utils import get_latest_bulletin if ctx.invoked_subcommand is None: cfg = Config() @@ -90,9 +97,14 @@ def main( memory_type, browser_name, allow_downloads, + skip_news ) logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO) ai_name = "" + if not cfg.skip_news: + motd = get_latest_bulletin() + if motd: + logger.typewriter_log("NEWS: ", Fore.GREEN, motd) system_prompt = construct_prompt() # print(prompt) # Initialize variables diff --git a/autogpt/config/config.py b/autogpt/config/config.py index bc75b031..763882ec 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -24,6 +24,7 @@ class Config(metaclass=Singleton): self.speak_mode = False self.skip_reprompt = False self.allow_downloads = False + self.skip_news = False self.selenium_web_browser = os.getenv("USE_WEB_BROWSER", "chrome") self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml") diff --git a/autogpt/configurator.py b/autogpt/configurator.py index 247cdac9..79b0bd0b 100644 --- a/autogpt/configurator.py +++ b/autogpt/configurator.py @@ -22,6 +22,7 @@ def create_config( memory_type: str, browser_name: str, allow_downloads: bool, + skip_news: bool ) -> None: """Updates the config object with the given arguments. @@ -37,7 +38,7 @@ def create_config( memory_type (str): The type of memory backend to use browser_name (str): The name of the browser to use when using selenium to scrape the web allow_downloads (bool): Whether to allow Auto-GPT to download files natively - + skips_news (bool): Whether to suppress the output of latest news on startup """ CFG.set_debug_mode(False) CFG.set_continuous_mode(False) @@ -126,5 +127,8 @@ def create_config( ) CFG.allow_downloads = True + if skip_news: + CFG.skip_news = True + if browser_name: CFG.selenium_web_browser = browser_name diff --git a/autogpt/utils.py b/autogpt/utils.py index db7d3321..c7b35b11 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,5 +1,6 @@ import yaml from colorama import Fore +import requests def clean_input(prompt: str = ""): @@ -37,3 +38,11 @@ def readable_file_size(size, decimal_places=2): break size /= 1024.0 return f"{size:.{decimal_places}f} {unit}" + +def get_latest_bulletin() -> str: + try: + response = requests.get('https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md') + if response.status_code == 200: + return response.text + except: + return "" From 90e6a55e378bc80352f01eb08122300b4d1a64ec Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:11:26 +0100 Subject: [PATCH 2/4] Black formatting --- autogpt/cli.py | 4 ++-- autogpt/configurator.py | 2 +- autogpt/utils.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/autogpt/cli.py b/autogpt/cli.py index 323c126b..a69a53ac 100644 --- a/autogpt/cli.py +++ b/autogpt/cli.py @@ -61,7 +61,7 @@ def main( memory_type: str, browser_name: str, allow_downloads: bool, - skip_news: bool + skip_news: bool, ) -> None: """ Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI. @@ -97,7 +97,7 @@ def main( memory_type, browser_name, allow_downloads, - skip_news + skip_news, ) logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO) ai_name = "" diff --git a/autogpt/configurator.py b/autogpt/configurator.py index 79b0bd0b..1dc3be12 100644 --- a/autogpt/configurator.py +++ b/autogpt/configurator.py @@ -22,7 +22,7 @@ def create_config( memory_type: str, browser_name: str, allow_downloads: bool, - skip_news: bool + skip_news: bool, ) -> None: """Updates the config object with the given arguments. diff --git a/autogpt/utils.py b/autogpt/utils.py index c7b35b11..3dc42871 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -39,9 +39,12 @@ def readable_file_size(size, decimal_places=2): size /= 1024.0 return f"{size:.{decimal_places}f} {unit}" + def get_latest_bulletin() -> str: try: - response = requests.get('https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md') + response = requests.get( + "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" + ) if response.status_code == 200: return response.text except: From 913c933e8cf43873d49c2a08d9ff9ed77e617d61 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:13:31 +0100 Subject: [PATCH 3/4] isort --- autogpt/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogpt/utils.py b/autogpt/utils.py index 3dc42871..ab7fe82a 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,6 +1,6 @@ +import requests import yaml from colorama import Fore -import requests def clean_input(prompt: str = ""): From 88ebebf74fecf43703a476fdce27ca66d4295ea3 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 21:45:09 +0100 Subject: [PATCH 4/4] Implement suggestions from pi - save current news to file --- .gitignore | 3 +++ autogpt/utils.py | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 26d7e5a3..85111ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,6 @@ vicuna-* # mac .DS_Store + +# news +CURRENT_BULLETIN.md \ No newline at end of file diff --git a/autogpt/utils.py b/autogpt/utils.py index ab7fe82a..0e4ce5e9 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,3 +1,5 @@ +import os + import requests import yaml from colorama import Fore @@ -40,12 +42,26 @@ def readable_file_size(size, decimal_places=2): return f"{size:.{decimal_places}f} {unit}" -def get_latest_bulletin() -> str: +def get_bulletin_from_web() -> str: try: response = requests.get( - "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" + "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/CONTRIBUTING.md" ) if response.status_code == 200: return response.text except: return "" + + +def get_latest_bulletin() -> str: + exists = os.path.exists("CURRENT_BULLETIN.md") + current_bulletin = "" + if exists: + current_bulletin = open("CURRENT_BULLETIN.md", "r", encoding="utf-8").read() + new_bulletin = get_bulletin_from_web() + is_new_news = new_bulletin != current_bulletin + + if new_bulletin and is_new_news: + open("CURRENT_BULLETIN.md", "w", encoding="utf-8").write(new_bulletin) + return f" {Fore.RED}::UPDATED:: {Fore.CYAN}{new_bulletin}{Fore.RESET}" + return current_bulletin