Adds a standard logging / log-printing class to TeamOne (#194)

* Added initial code for TeamOne utils.

* Fixed hatch errors.

* Updated examples.

* Fixed more hatch errors.

* examples/example_coder.py

* Added standard logging for TeamOne

* Read time from log record.
This commit is contained in:
afourney
2024-07-09 13:51:05 -07:00
committed by GitHub
parent 05e72084e8
commit 699f024a6d
6 changed files with 75 additions and 66 deletions

View File

@@ -7,8 +7,8 @@ from agnext.application.logging import EVENT_LOGGER_NAME
from team_one.agents.coder import Coder
from team_one.agents.orchestrator import RoundRobinOrchestrator
from team_one.agents.user_proxy import UserProxy
from team_one.messages import OrchestrationEvent, RequestReplyMessage
from team_one.utils import create_completion_client_from_env
from team_one.messages import RequestReplyMessage
from team_one.utils import LogHandler, create_completion_client_from_env
async def main() -> None:
@@ -35,27 +35,9 @@ async def main() -> None:
await run_context.stop_when_idle()
class MyHandler(logging.Handler):
def __init__(self) -> None:
super().__init__()
def emit(self, record: logging.LogRecord) -> None:
try:
if isinstance(record.msg, OrchestrationEvent):
print(
f"""---------------------------------------------------------------------------
\033[91m{record.msg.source}:\033[0m
{record.msg.message}""",
flush=True,
)
except Exception:
self.handleError(record)
if __name__ == "__main__":
logger = logging.getLogger(EVENT_LOGGER_NAME)
logger.setLevel(logging.INFO)
my_handler = MyHandler()
logger.handlers = [my_handler]
log_handler = LogHandler()
logger.handlers = [log_handler]
asyncio.run(main())