2023-04-13 11:02:42 +00:00
|
|
|
import yaml
|
|
|
|
from colorama import Fore
|
|
|
|
|
2023-04-13 22:23:23 +00:00
|
|
|
|
2023-04-14 19:42:28 +00:00
|
|
|
def clean_input(prompt: str = ""):
|
2023-04-10 00:53:32 +00:00
|
|
|
try:
|
|
|
|
return input(prompt)
|
|
|
|
except KeyboardInterrupt:
|
2023-04-10 15:31:43 +00:00
|
|
|
print("You interrupted Auto-GPT")
|
|
|
|
print("Quitting...")
|
2023-04-10 00:53:32 +00:00
|
|
|
exit(0)
|
|
|
|
|
2023-04-13 11:02:42 +00:00
|
|
|
|
|
|
|
def validate_yaml_file(file: str):
|
|
|
|
try:
|
2023-04-15 00:04:48 +00:00
|
|
|
with open(file, encoding="utf-8") as fp:
|
|
|
|
yaml.load(fp.read(), Loader=yaml.FullLoader)
|
2023-04-13 11:02:42 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
return (False, f"The file {Fore.CYAN}`{file}`{Fore.RESET} wasn't found")
|
|
|
|
except yaml.YAMLError as e:
|
2023-04-14 19:42:28 +00:00
|
|
|
return (
|
|
|
|
False,
|
|
|
|
f"There was an issue while trying to read with your AI Settings file: {e}",
|
|
|
|
)
|
2023-04-13 12:09:24 +00:00
|
|
|
|
|
|
|
return (True, f"Successfully validated {Fore.CYAN}`{file}`{Fore.RESET}!")
|
2023-04-17 02:34:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def readable_file_size(size, decimal_places=2):
|
|
|
|
"""Converts the given size in bytes to a readable format.
|
|
|
|
Args:
|
|
|
|
size: Size in bytes
|
|
|
|
decimal_places (int): Number of decimal places to display
|
|
|
|
"""
|
|
|
|
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
|
|
|
if size < 1024.0:
|
|
|
|
break
|
|
|
|
size /= 1024.0
|
|
|
|
return f"{size:.{decimal_places}f} {unit}"
|