visual diff

This commit is contained in:
மனோஜ்குமார் பழனிச்சாமி
2024-06-20 19:35:01 +05:30
parent dbf0e5b068
commit a2d91ee3a8
3 changed files with 11 additions and 2 deletions

View File

@@ -33,7 +33,9 @@ ColorType = Literal[
LOG_COLORS: Mapping[str, ColorType] = {
'BACKGROUND LOG': 'blue',
'ACTION': 'green',
'USER_ACTION': 'light_red',
'OBSERVATION': 'yellow',
'USER_OBSERVATION': 'light_green',
'DETAIL': 'cyan',
'ERROR': 'red',
'PLAN': 'light_magenta',
@@ -43,6 +45,11 @@ LOG_COLORS: Mapping[str, ColorType] = {
class ColoredFormatter(logging.Formatter):
def format(self, record):
msg_type = record.__dict__.get('msg_type')
event_source = record.__dict__.get('event_source')
if event_source:
new_msg_type = f'{event_source.upper()}_{msg_type}'
if new_msg_type in LOG_COLORS:
msg_type = new_msg_type
if msg_type in LOG_COLORS and not DISABLE_COLOR_PRINTING:
msg_type_color = colored(msg_type, LOG_COLORS[msg_type])
msg = colored(record.msg, LOG_COLORS[msg_type])

View File

@@ -25,7 +25,7 @@ class CmdOutputObservation(Observation):
return f'Command `{self.command}` executed with exit code {self.exit_code}.'
def __str__(self) -> str:
return f'**CmdOutputObservation (exit code={self.exit_code})**\n{self.content}'
return f'**CmdOutputObservation (source={self.source}, exit code={self.exit_code})**\n{self.content}'
@dataclass

View File

@@ -98,7 +98,9 @@ class Session:
event = event_from_dict(data.copy())
event._source = EventSource.USER # type: ignore[attr-defined]
if isinstance(event, Action):
logger.info(event, extra={'msg_type': 'ACTION'})
logger.info(
event, extra={'msg_type': 'ACTION', 'event_source': EventSource.USER}
)
await self.agent_session.event_stream.add_event(event, EventSource.USER)
async def send(self, data: dict[str, object]) -> bool: