Allow spinning to be disabled (#4329)
parent
e7c0d3330c
commit
064e95b46b
|
@ -21,6 +21,10 @@
|
||||||
## EXIT_KEY - Key to exit AUTO-GPT
|
## EXIT_KEY - Key to exit AUTO-GPT
|
||||||
# EXIT_KEY=n
|
# EXIT_KEY=n
|
||||||
|
|
||||||
|
## PLAIN_OUTPUT - Enabeling plain output will disable spinner (Default: False)
|
||||||
|
## Note: Spinner is used to indicate that Auto-GPT is working on something in the background
|
||||||
|
# PLAIN_OUTPUT=False
|
||||||
|
|
||||||
## DISABLED_COMMAND_CATEGORIES - The list of categories of commands that are disabled. Each of the below are an option:
|
## DISABLED_COMMAND_CATEGORIES - The list of categories of commands that are disabled. Each of the below are an option:
|
||||||
## autogpt.commands.analyze_code
|
## autogpt.commands.analyze_code
|
||||||
## autogpt.commands.audio_text
|
## autogpt.commands.audio_text
|
||||||
|
|
|
@ -126,7 +126,7 @@ class Agent:
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
# Send message to AI, get response
|
# Send message to AI, get response
|
||||||
with Spinner("Thinking... "):
|
with Spinner("Thinking... ", plain_output=cfg.plain_output):
|
||||||
assistant_reply = chat_with_ai(
|
assistant_reply = chat_with_ai(
|
||||||
self,
|
self,
|
||||||
self.system_prompt,
|
self.system_prompt,
|
||||||
|
|
|
@ -318,7 +318,7 @@ def download_file(url, filename, config: Config):
|
||||||
directory = os.path.dirname(filename)
|
directory = os.path.dirname(filename)
|
||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
message = f"{Fore.YELLOW}Downloading file from {Back.LIGHTBLUE_EX}{url}{Back.RESET}{Fore.RESET}"
|
message = f"{Fore.YELLOW}Downloading file from {Back.LIGHTBLUE_EX}{url}{Back.RESET}{Fore.RESET}"
|
||||||
with Spinner(message) as spinner:
|
with Spinner(message, plain_output=config.plain_output) as spinner:
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
retry = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])
|
retry = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])
|
||||||
adapter = HTTPAdapter(max_retries=retry)
|
adapter = HTTPAdapter(max_retries=retry)
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Config(metaclass=Singleton):
|
||||||
|
|
||||||
self.authorise_key = os.getenv("AUTHORISE_COMMAND_KEY", "y")
|
self.authorise_key = os.getenv("AUTHORISE_COMMAND_KEY", "y")
|
||||||
self.exit_key = os.getenv("EXIT_KEY", "n")
|
self.exit_key = os.getenv("EXIT_KEY", "n")
|
||||||
|
self.plain_output = os.getenv("PLAIN_OUTPUT", "False") == "True"
|
||||||
|
|
||||||
disabled_command_categories = os.getenv("DISABLED_COMMAND_CATEGORIES")
|
disabled_command_categories = os.getenv("DISABLED_COMMAND_CATEGORIES")
|
||||||
if disabled_command_categories:
|
if disabled_command_categories:
|
||||||
|
|
|
@ -8,13 +8,20 @@ import time
|
||||||
class Spinner:
|
class Spinner:
|
||||||
"""A simple spinner class"""
|
"""A simple spinner class"""
|
||||||
|
|
||||||
def __init__(self, message: str = "Loading...", delay: float = 0.1) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
message: str = "Loading...",
|
||||||
|
delay: float = 0.1,
|
||||||
|
plain_output: bool = False,
|
||||||
|
) -> None:
|
||||||
"""Initialize the spinner class
|
"""Initialize the spinner class
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message (str): The message to display.
|
message (str): The message to display.
|
||||||
delay (float): The delay between each spinner update.
|
delay (float): The delay between each spinner update.
|
||||||
|
plain_output (bool): Whether to display the spinner or not.
|
||||||
"""
|
"""
|
||||||
|
self.plain_output = plain_output
|
||||||
self.spinner = itertools.cycle(["-", "/", "|", "\\"])
|
self.spinner = itertools.cycle(["-", "/", "|", "\\"])
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
self.message = message
|
self.message = message
|
||||||
|
@ -23,11 +30,17 @@ class Spinner:
|
||||||
|
|
||||||
def spin(self) -> None:
|
def spin(self) -> None:
|
||||||
"""Spin the spinner"""
|
"""Spin the spinner"""
|
||||||
|
if self.plain_output:
|
||||||
|
self.print_message()
|
||||||
|
return
|
||||||
while self.running:
|
while self.running:
|
||||||
sys.stdout.write(f"{next(self.spinner)} {self.message}\r")
|
self.print_message()
|
||||||
sys.stdout.flush()
|
|
||||||
time.sleep(self.delay)
|
time.sleep(self.delay)
|
||||||
sys.stdout.write(f"\r{' ' * (len(self.message) + 2)}\r")
|
|
||||||
|
def print_message(self):
|
||||||
|
sys.stdout.write(f"\r{' ' * (len(self.message) + 2)}\r")
|
||||||
|
sys.stdout.write(f"{next(self.spinner)} {self.message}\r")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
"""Start the spinner"""
|
"""Start the spinner"""
|
||||||
|
@ -57,9 +70,7 @@ class Spinner:
|
||||||
new_message (str): New message to display.
|
new_message (str): New message to display.
|
||||||
delay (float): The delay in seconds between each spinner update.
|
delay (float): The delay in seconds between each spinner update.
|
||||||
"""
|
"""
|
||||||
time.sleep(delay)
|
self.delay = delay
|
||||||
sys.stdout.write(
|
|
||||||
f"\r{' ' * (len(self.message) + 2)}\r"
|
|
||||||
) # Clear the current message
|
|
||||||
sys.stdout.flush()
|
|
||||||
self.message = new_message
|
self.message = new_message
|
||||||
|
if self.plain_output:
|
||||||
|
self.print_message()
|
||||||
|
|
|
@ -12,11 +12,14 @@ from autogpt.workspace import Workspace
|
||||||
def agent_test_config(config: Config):
|
def agent_test_config(config: Config):
|
||||||
was_continuous_mode = config.continuous_mode
|
was_continuous_mode = config.continuous_mode
|
||||||
was_temperature = config.temperature
|
was_temperature = config.temperature
|
||||||
|
was_plain_output = config.plain_output
|
||||||
config.set_continuous_mode(False)
|
config.set_continuous_mode(False)
|
||||||
config.set_temperature(0)
|
config.set_temperature(0)
|
||||||
|
config.plain_output = True
|
||||||
yield config
|
yield config
|
||||||
config.set_continuous_mode(was_continuous_mode)
|
config.set_continuous_mode(was_continuous_mode)
|
||||||
config.set_temperature(was_temperature)
|
config.set_temperature(was_temperature)
|
||||||
|
config.plain_output = was_plain_output
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
Loading…
Reference in New Issue