coding-alt/AutoGPT
0
1import os2 3import requests4import yaml5from colorama import Fore6from git import Repo7 8 9def clean_input(prompt: str = ""):10 try:11 return input(prompt)12 except KeyboardInterrupt:13 print("You interrupted Auto-GPT")14 print("Quitting...")15 exit(0)16 17 18def validate_yaml_file(file: str):19 try:20 with open(file, encoding="utf-8") as fp:21 yaml.load(fp.read(), Loader=yaml.FullLoader)22 except FileNotFoundError:23 return (False, f"The file {Fore.CYAN}`{file}`{Fore.RESET} wasn't found")24 except yaml.YAMLError as e:25 return (26 False,27 f"There was an issue while trying to read with your AI Settings file: {e}",28 )29 30 return (True, f"Successfully validated {Fore.CYAN}`{file}`{Fore.RESET}!")31 32 33def readable_file_size(size, decimal_places=2):34 """Converts the given size in bytes to a readable format.35 Args:36 size: Size in bytes37 decimal_places (int): Number of decimal places to display38 """39 for unit in ["B", "KB", "MB", "GB", "TB"]:40 if size < 1024.0:41 break42 size /= 1024.043 return f"{size:.{decimal_places}f} {unit}"44 45 46def get_bulletin_from_web() -> str:47 try:48 response = requests.get(49 "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md"50 )51 if response.status_code == 200:52 return response.text53 except:54 return ""55 56 57def get_current_git_branch() -> str:58 try:59 repo = Repo(search_parent_directories=True)60 branch = repo.active_branch61 return branch.name62 except:63 return ""64 65 66def get_latest_bulletin() -> str:67 exists = os.path.exists("CURRENT_BULLETIN.md")68 current_bulletin = ""69 if exists:70 current_bulletin = open("CURRENT_BULLETIN.md", "r", encoding="utf-8").read()71 new_bulletin = get_bulletin_from_web()72 is_new_news = new_bulletin != current_bulletin73 74 if new_bulletin and is_new_news:75 open("CURRENT_BULLETIN.md", "w", encoding="utf-8").write(new_bulletin)76 return f" {Fore.RED}::UPDATED:: {Fore.CYAN}{new_bulletin}{Fore.RESET}"77 return current_bulletin78 