Skip to content

Commit

Permalink
support disable color printing via environment variable in config.toml (
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyaoww committed Apr 2, 2024
1 parent 4c1d278 commit 16fe830
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions opendevin/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
AgentErrorObservation,
NullObservation
)
from opendevin import config

from .command_manager import CommandManager


ColorType = Literal['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'light_grey', 'dark_grey', 'light_red', 'light_green', 'light_yellow', 'light_blue', 'light_magenta', 'light_cyan', 'white']

DISABLE_COLOR_PRINTING = config.get_or_default("DISABLE_COLOR", "false").lower() == "true"

def print_with_color(text: Any, print_type: str = "INFO"):
TYPE_TO_COLOR: Mapping[str, ColorType] = {
"BACKGROUND LOG": "blue",
Expand All @@ -35,11 +38,14 @@ def print_with_color(text: Any, print_type: str = "INFO"):
"PLAN": "light_magenta",
}
color = TYPE_TO_COLOR.get(print_type.upper(), TYPE_TO_COLOR["INFO"])
print(
colored(f"\n{print_type.upper()}:\n", color, attrs=["bold"])
+ colored(str(text), color),
flush=True,
)
if DISABLE_COLOR_PRINTING:
print(f"\n{print_type.upper()}:\n{str(text)}", flush=True)
else:
print(
colored(f"\n{print_type.upper()}:\n", color, attrs=["bold"])
+ colored(str(text), color),
flush=True,
)

class AgentController:
def __init__(
Expand Down

0 comments on commit 16fe830

Please sign in to comment.