AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(agent): Replace `PromptToolkit` with `click.prompt`
Reinier van der Leer632686cfa5f5
diff --git a/autogpts/autogpt/autogpt/app/main.py b/autogpts/autogpt/autogpt/app/main.pyindex 39524ee70a..976ecfabf9 100644--- a/autogpts/autogpt/autogpt/app/main.py+++ b/autogpts/autogpt/autogpt/app/main.py@@ -180,7 +180,7 @@ async def run_auto_gpt("Existing agents\n---------------\n"+ "\n".join(f"{i} - {id}" for i, id in enumerate(existing_agents, 1)))- load_existing_agent = await clean_input(+ load_existing_agent = clean_input(config,"Enter the number or name of the agent to run,"" or hit enter to create a new one:",@@ -205,7 +205,7 @@ async def run_auto_gpt(if load_existing_agent:agent_state = Nonewhile True:- answer = await clean_input(config, "Resume? [Y/n]")+ answer = clean_input(config, "Resume? [Y/n]")if answer == "" or answer.lower() == "y":agent_state = agent_manager.load_agent_state(load_existing_agent)break@@ -238,7 +238,7 @@ async def run_auto_gpt(# Agent was resumed after `finish` -> rewrite result of `finish` actionfinish_reason = agent.event_history.current_episode.action.args["reason"]print(f"Agent previously self-terminated; reason: '{finish_reason}'")- new_assignment = await clean_input(+ new_assignment = clean_input(config, "Please give a follow-up question or assignment:")agent.event_history.register_result(@@ -270,7 +270,7 @@ async def run_auto_gpt(if not agent:task = ""while task.strip() == "":- task = await clean_input(+ task = clean_input(config,"Enter the task that you want AutoGPT to execute,"" with as much detail as possible:",@@ -343,7 +343,7 @@ async def run_auto_gpt(# Allow user to Save As other IDsave_as_id = (- await clean_input(+ clean_input(config,f"Press enter to save as '{agent_id}',"" or enter a different ID to save to:",@@ -725,9 +725,9 @@ async def get_user_feedback(while user_feedback is None:# Get input from userif config.chat_messages_enabled:- console_input = await clean_input(config, "Waiting for your response...")+ console_input = clean_input(config, "Waiting for your response...")else:- console_input = await clean_input(+ console_input = clean_input(config, Fore.MAGENTA + "Input:" + Style.RESET_ALL)diff --git a/autogpts/autogpt/autogpt/app/setup.py b/autogpts/autogpt/autogpt/app/setup.pyindex df4e9436cd..94460e62f6 100644--- a/autogpts/autogpt/autogpt/app/setup.py+++ b/autogpts/autogpt/autogpt/app/setup.py@@ -69,20 +69,18 @@ async def interactively_revise_ai_settings()if (- await clean_input(app_config, "Continue with these settings? [Y/n]")+ clean_input(app_config, "Continue with these settings? [Y/n]").lower()or app_config.authorise_key) == app_config.authorise_key:break# Ask for revised ai_profileai_profile.ai_name = (- await clean_input(- app_config, "Enter AI name (or press enter to keep current):"- )+ clean_input(app_config, "Enter AI name (or press enter to keep current):")or ai_profile.ai_name)ai_profile.ai_role = (- await clean_input(+ clean_input(app_config, "Enter new AI role (or press enter to keep current):")or ai_profile.ai_role@@ -94,7 +92,7 @@ async def interactively_revise_ai_settings(constraint = directives.constraints[i]print_attribute(f"Constraint {i+1}:", f'"{constraint}"')new_constraint = (- await clean_input(+ clean_input(app_config,f"Enter new constraint {i+1}"" (press enter to keep current, or '-' to remove):",@@ -112,7 +110,7 @@ async def interactively_revise_ai_settings(# Add new constraintswhile True:- new_constraint = await clean_input(+ new_constraint = clean_input(app_config,"Press enter to finish, or enter a constraint to add:",)@@ -126,7 +124,7 @@ async def interactively_revise_ai_settings(resource = directives.resources[i]print_attribute(f"Resource {i+1}:", f'"{resource}"')new_resource = (- await clean_input(+ clean_input(app_config,f"Enter new resource {i+1}"" (press enter to keep current, or '-' to remove):",@@ -143,7 +141,7 @@ async def interactively_revise_ai_settings(# Add new resourceswhile True:- new_resource = await clean_input(+ new_resource = clean_input(app_config,"Press enter to finish, or enter a resource to add:",)@@ -157,7 +155,7 @@ async def interactively_revise_ai_settings(best_practice = directives.best_practices[i]print_attribute(f"Best Practice {i+1}:", f'"{best_practice}"')new_best_practice = (- await clean_input(+ clean_input(app_config,f"Enter new best practice {i+1}"" (press enter to keep current, or '-' to remove):",@@ -174,7 +172,7 @@ async def interactively_revise_ai_settings(# Add new best practiceswhile True:- new_best_practice = await clean_input(+ new_best_practice = clean_input(app_config,"Press enter to finish, or add a best practice to add:",)diff --git a/autogpts/autogpt/autogpt/app/utils.py b/autogpts/autogpt/autogpt/app/utils.pyindex 3e986852b4..49a1e2a44f 100644--- a/autogpts/autogpt/autogpt/app/utils.py+++ b/autogpts/autogpt/autogpt/app/utils.py@@ -7,20 +7,18 @@ import sysfrom pathlib import Pathfrom typing import TYPE_CHECKING+import clickimport requestsfrom colorama import Fore, Stylefrom git import InvalidGitRepositoryError, Repo-from prompt_toolkit import ANSI, PromptSession-from prompt_toolkit.history import InMemoryHistoryif TYPE_CHECKING:from autogpt.config import Configlogger = logging.getLogger(__name__)-session = PromptSession(history=InMemoryHistory())-async def clean_input(config: "Config", prompt: str = ""):+def clean_input(config: "Config", prompt: str = ""):try:if config.chat_messages_enabled:for plugin in config.plugins:@@ -53,11 +51,9 @@ async def clean_input(config: "Config", prompt: str = ""):# ask for input, default when just pressing Enter is ylogger.debug("Asking user via keyboard...")- # handle_sigint must be set to False, so the signal handler in the- # autogpt/main.py could be employed properly. This referes to- # https://github.com/Significant-Gravitas/AutoGPT/pull/4799/files/3966cdfd694c2a80c0333823c3bc3da090f85ed3#r1264278776- answer = await session.prompt_async(ANSI(prompt + " "), handle_sigint=False)- return answer+ return click.prompt(+ text=prompt, prompt_suffix=" ", default="", show_default=False+ )except KeyboardInterrupt:logger.info("You interrupted AutoGPT")logger.info("Quitting...")diff --git a/autogpts/autogpt/autogpt/commands/user_interaction.py b/autogpts/autogpt/autogpt/commands/user_interaction.pyindex c53213c7ff..bd4dd639ce 100644--- a/autogpts/autogpt/autogpt/commands/user_interaction.py+++ b/autogpts/autogpt/autogpt/commands/user_interaction.py@@ -28,5 +28,5 @@ COMMAND_CATEGORY_TITLE = "User Interaction")async def ask_user(question: str, agent: Agent) -> str:print(f"\nQ: {question}")- resp = await clean_input(agent.legacy_config, "A:")+ resp = clean_input(agent.legacy_config, "A:")return f"The user's answer: '{resp}'"diff --git a/autogpts/autogpt/poetry.lock b/autogpts/autogpt/poetry.lockindex 176be5e63c..6ee147a454 100644--- a/autogpts/autogpt/poetry.lock+++ b/autogpts/autogpt/poetry.lock@@ -4589,7 +4589,7 @@ files = [name = "prompt-toolkit"version = "3.0.43"description = "Library for building powerful interactive command lines in Python"-optional = false+optional = truepython-versions = ">=3.7.0"files = [{file = "prompt_toolkit-3.0.43-py3-none-any.whl", hash = "sha256:a11a29cb3bf0a28a387fe5122cdb649816a957cd9261dcedf8c9f1fef33eacf6"},@@ -7248,4 +7248,4 @@ benchmark = ["agbenchmark"][metadata]lock-version = "2.0"python-versions = "^3.10"-content-hash = "f693821e204aaf64d946ac45d7c0e447f02c2a3f173f939dac2fcc8e797a142f"+content-hash = "a09e20daaf94e05457ded6a9989585cd37edf96a036c5f9e505f0b2456403a25"diff --git a/autogpts/autogpt/pyproject.toml b/autogpts/autogpt/pyproject.tomlindex 919e110181..ad138ee242 100644--- a/autogpts/autogpt/pyproject.toml+++ b/autogpts/autogpt/pyproject.toml@@ -48,7 +48,6 @@ orjson = "^3.8.10"Pillow = "*"pinecone-client = "^2.2.1"playsound = "~1.2.2"-prompt_toolkit = "^3.0.38"pydantic = "*"pylatexenc = "*"pypdf = "^3.1.0"