Skip to content

Commit

Permalink
Fix bulletin
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed May 2, 2023
1 parent e4129e1 commit 725abbb
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 95 deletions.
27 changes: 21 additions & 6 deletions BULLETIN.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
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
# Website and Documentation Site 📰📖
Check out *https://agpt.co*, the official news & updates site for Auto-GPT!
The documentation also has a place here, at *https://docs.agpt.co*

# INCLUDED COMMAND 'send_tweet' IS DEPRICATED, AND WILL BE REMOVED IN THE NEXT STABLE RELEASE
Base Twitter functionality (and more) is now covered by plugins: https://github.com/Significant-Gravitas/Auto-GPT-Plugins
# 🚀 v0.3.0 Release 🚀
Over a week and 275 pull requests have passed since v0.2.2, and we are happy to announce
the release of v0.3.0! *From now on, we will be focusing on major improvements* rather
than bugfixes, as we feel stability has reached a reasonable level. Most remaining
issues relate to limitations in prompt generation and the memory system, which will be
the focus of our efforts for the next release.

## Changes to Docker configuration
The workdir has been changed from /home/appuser to /app. Be sure to update any volume mounts accordingly.
Highlights and notable changes in this release:

## Plugin support 🔌
Auto-GPT now has support for plugins! With plugins, you can extend Auto-GPT's abilities,
adding support for third-party services and more.
See https://github.com/Significant-Gravitas/Auto-GPT-Plugins for instructions and available plugins.

## Changes to Docker configuration 🐋
The workdir has been changed from */home/appuser* to */app*.
Be sure to update any volume mounts accordingly!

# ⚠️ Command `send_tweet` is DEPRECATED, and will be removed in v0.4.0 ⚠️
Twitter functionality (and more) is now covered by plugins, see [Plugin support 🔌]
22 changes: 18 additions & 4 deletions autogpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from pathlib import Path

from colorama import Fore
from colorama import Fore, Style

from autogpt.agent.agent import Agent
from autogpt.commands.command import CommandRegistry
Expand All @@ -13,7 +13,11 @@
from autogpt.memory import get_memory
from autogpt.plugins import scan_plugins
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT, construct_main_ai_config
from autogpt.utils import get_current_git_branch, get_latest_bulletin
from autogpt.utils import (
get_current_git_branch,
get_latest_bulletin,
markdown_to_ansi_style,
)
from autogpt.workspace import Workspace
from scripts.install_plugin_deps import install_plugin_dependencies

Expand Down Expand Up @@ -57,9 +61,19 @@ def run_auto_gpt(
)

if not cfg.skip_news:
motd = get_latest_bulletin()
motd, is_new_motd = get_latest_bulletin()
if motd:
logger.typewriter_log("NEWS: ", Fore.GREEN, motd)
motd = markdown_to_ansi_style(motd)
for motd_line in motd.split("\n"):
logger.info(motd_line, "NEWS:", Fore.GREEN)
if is_new_motd and not cfg.chat_messages_enabled:
input(
Fore.MAGENTA
+ Style.BRIGHT
+ "NEWS: Bulletin was updated! Press Enter to continue..."
+ Style.RESET_ALL
)

git_branch = get_current_git_branch()
if git_branch and git_branch != "stable":
logger.typewriter_log(
Expand Down
42 changes: 37 additions & 5 deletions autogpt/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import re

import requests
import yaml
from colorama import Fore
from colorama import Fore, Style
from git.repo import Repo

from autogpt.logs import logger
Expand Down Expand Up @@ -107,15 +108,46 @@ def get_current_git_branch() -> str:
return ""


def get_latest_bulletin() -> str:
def get_latest_bulletin() -> tuple[str, bool]:
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
is_new_news = new_bulletin != "" and new_bulletin != current_bulletin

news_header = Fore.YELLOW + "Welcome to Auto-GPT!\n"
if new_bulletin or current_bulletin:
news_header += (
"Below you'll find the latest Auto-GPT News and updates regarding features!\n"
"If you don't wish to see this message, you "
"can run Auto-GPT with the *--skip-news* flag.\n"
)

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
current_bulletin = f"{Fore.RED}::NEW BULLETIN::{Fore.RESET}\n\n{new_bulletin}"

return f"{news_header}\n{current_bulletin}", is_new_news


def markdown_to_ansi_style(markdown: str):
ansi_lines: list[str] = []
for line in markdown.split("\n"):
line_style = ""

if line.startswith("# "):
line_style += Style.BRIGHT
else:
line = re.sub(
r"(?<!\*)\*(\*?[^*]+\*?)\*(?!\*)",
rf"{Style.BRIGHT}\1{Style.NORMAL}",
line,
)

if re.match(r"^#+ ", line) is not None:
line_style += Fore.CYAN
line = re.sub(r"^#+ ", "", line)

ansi_lines.append(f"{line_style}{line}{Style.RESET_ALL}")
return "\n".join(ansi_lines)
120 changes: 40 additions & 80 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,51 @@ def test_readable_file_size():

@patch("requests.get")
def test_get_bulletin_from_web_success(mock_get):
expected_content = "Test bulletin from web"

mock_get.return_value.status_code = 200
mock_get.return_value.text = "Test bulletin"
mock_get.return_value.text = expected_content
bulletin = get_bulletin_from_web()

assert bulletin == "Test bulletin"
assert expected_content in bulletin
mock_get.assert_called_with(
"https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md"
)


@patch("requests.get")
def test_get_bulletin_from_web_failure(mock_get):
mock_get.return_value.status_code = 404
bulletin = get_bulletin_from_web()
print(bulletin)

assert bulletin == ""


@skip_in_ci
def test_get_current_git_branch():
branch_name = get_current_git_branch()
@patch("requests.get")
def test_get_bulletin_from_web_exception(mock_get):
mock_get.side_effect = requests.exceptions.RequestException()
bulletin = get_bulletin_from_web()

# Assuming that the branch name will be non-empty if the function is working correctly.
assert branch_name != ""
assert bulletin == ""


def test_get_latest_bulletin_no_file():
if os.path.exists("CURRENT_BULLETIN.md"):
os.remove("CURRENT_BULLETIN.md")

with patch("autogpt.utils.get_bulletin_from_web", return_value=""):
bulletin = get_latest_bulletin()
assert bulletin == ""
bulletin, is_new = get_latest_bulletin()
assert is_new


def test_get_latest_bulletin_with_file():
expected_content = "Test bulletin"
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Test bulletin")
f.write(expected_content)

with patch("autogpt.utils.get_bulletin_from_web", return_value=""):
bulletin = get_latest_bulletin()
assert bulletin == "Test bulletin"
bulletin, is_new = get_latest_bulletin()
assert expected_content in bulletin
assert is_new == False

os.remove("CURRENT_BULLETIN.md")

Expand All @@ -103,39 +109,35 @@ def test_get_latest_bulletin_with_new_bulletin():
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Old bulletin")

with patch("autogpt.utils.get_bulletin_from_web", return_value="New bulletin"):
bulletin = get_latest_bulletin()
assert "New bulletin" in bulletin
expected_content = "New bulletin from web"
with patch("autogpt.utils.get_bulletin_from_web", return_value=expected_content):
bulletin, is_new = get_latest_bulletin()
assert "::NEW BULLETIN::" in bulletin
assert expected_content in bulletin
assert is_new

os.remove("CURRENT_BULLETIN.md")


@patch("requests.get")
def test_get_bulletin_from_web_success(mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = "Test bulletin"
bulletin = get_bulletin_from_web()

assert bulletin == "Test bulletin"
mock_get.assert_called_with(
"https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md"
)

def test_get_latest_bulletin_new_bulletin_same_as_old_bulletin():
expected_content = "Current bulletin"
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write(expected_content)

@patch("requests.get")
def test_get_bulletin_from_web_failure(mock_get):
mock_get.return_value.status_code = 404
bulletin = get_bulletin_from_web()
with patch("autogpt.utils.get_bulletin_from_web", return_value=expected_content):
bulletin, is_new = get_latest_bulletin()
assert expected_content in bulletin
assert is_new == False

assert bulletin == ""
os.remove("CURRENT_BULLETIN.md")


@patch("requests.get")
def test_get_bulletin_from_web_exception(mock_get):
mock_get.side_effect = requests.exceptions.RequestException()
bulletin = get_bulletin_from_web()
@skip_in_ci
def test_get_current_git_branch():
branch_name = get_current_git_branch()

assert bulletin == ""
# Assuming that the branch name will be non-empty if the function is working correctly.
assert branch_name != ""


@patch("autogpt.utils.Repo")
Expand All @@ -154,47 +156,5 @@ def test_get_current_git_branch_failure(mock_repo):
assert branch_name == ""


def test_get_latest_bulletin_no_file():
if os.path.exists("CURRENT_BULLETIN.md"):
os.remove("CURRENT_BULLETIN.md")

with patch("autogpt.utils.get_bulletin_from_web", return_value=""):
bulletin = get_latest_bulletin()
assert bulletin == ""


def test_get_latest_bulletin_with_file():
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Test bulletin")

with patch("autogpt.utils.get_bulletin_from_web", return_value=""):
bulletin = get_latest_bulletin()
assert bulletin == "Test bulletin"

os.remove("CURRENT_BULLETIN.md")


def test_get_latest_bulletin_with_new_bulletin():
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Old bulletin")

with patch("autogpt.utils.get_bulletin_from_web", return_value="New bulletin"):
bulletin = get_latest_bulletin()
assert f" {Fore.RED}::UPDATED:: {Fore.CYAN}New bulletin{Fore.RESET}" in bulletin

os.remove("CURRENT_BULLETIN.md")


def test_get_latest_bulletin_new_bulletin_same_as_old_bulletin():
with open("CURRENT_BULLETIN.md", "w", encoding="utf-8") as f:
f.write("Test bulletin")

with patch("autogpt.utils.get_bulletin_from_web", return_value="Test bulletin"):
bulletin = get_latest_bulletin()
assert bulletin == "Test bulletin"

os.remove("CURRENT_BULLETIN.md")


if __name__ == "__main__":
pytest.main()

0 comments on commit 725abbb

Please sign in to comment.