mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-01 13:24:22 +01:00
Filtering out ANSI escape codes in printed assistant thoughts (#4810)
Co-authored-by: merwanehamadi <merwanehamadi@gmail.com> Co-authored-by: Luke K (pr-0f3t) <2609441+lc0rp@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ from autogpt.log_cycle.log_cycle import (
|
||||
USER_INPUT_FILE_NAME,
|
||||
LogCycleHandler,
|
||||
)
|
||||
from autogpt.logs import logger, print_assistant_thoughts
|
||||
from autogpt.logs import logger, print_assistant_thoughts, remove_ansi_escape
|
||||
from autogpt.memory.message_history import MessageHistory
|
||||
from autogpt.memory.vector import VectorMemory
|
||||
from autogpt.models.command_registry import CommandRegistry
|
||||
@@ -185,7 +185,7 @@ class Agent:
|
||||
logger.typewriter_log(
|
||||
"NEXT ACTION: ",
|
||||
Fore.CYAN,
|
||||
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} "
|
||||
f"COMMAND = {Fore.CYAN}{remove_ansi_escape(command_name)}{Style.RESET_ALL} "
|
||||
f"ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}",
|
||||
)
|
||||
|
||||
|
||||
@@ -249,6 +249,10 @@ def remove_color_codes(s: str) -> str:
|
||||
return ansi_escape.sub("", s)
|
||||
|
||||
|
||||
def remove_ansi_escape(s: str) -> str:
|
||||
return s.replace("\x1B", "")
|
||||
|
||||
|
||||
logger = Logger()
|
||||
|
||||
|
||||
@@ -263,12 +267,16 @@ def print_assistant_thoughts(
|
||||
assistant_thoughts_criticism = None
|
||||
|
||||
assistant_thoughts = assistant_reply_json_valid.get("thoughts", {})
|
||||
assistant_thoughts_text = assistant_thoughts.get("text")
|
||||
assistant_thoughts_text = remove_ansi_escape(assistant_thoughts.get("text"))
|
||||
if assistant_thoughts:
|
||||
assistant_thoughts_reasoning = assistant_thoughts.get("reasoning")
|
||||
assistant_thoughts_plan = assistant_thoughts.get("plan")
|
||||
assistant_thoughts_criticism = assistant_thoughts.get("criticism")
|
||||
assistant_thoughts_speak = assistant_thoughts.get("speak")
|
||||
assistant_thoughts_reasoning = remove_ansi_escape(
|
||||
assistant_thoughts.get("reasoning")
|
||||
)
|
||||
assistant_thoughts_plan = remove_ansi_escape(assistant_thoughts.get("plan"))
|
||||
assistant_thoughts_criticism = remove_ansi_escape(
|
||||
assistant_thoughts.get("criticism")
|
||||
)
|
||||
assistant_thoughts_speak = remove_ansi_escape(assistant_thoughts.get("speak"))
|
||||
logger.typewriter_log(
|
||||
f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, f"{assistant_thoughts_text}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user