log datatype change

This commit is contained in:
yzlin 2024-04-02 12:08:39 +08:00
parent 95dc1eebf2
commit 5e34038831
3 changed files with 29 additions and 11 deletions

View file

@ -13,10 +13,22 @@ from datetime import datetime
from functools import partial
from loguru import logger as _logger
from pydantic import BaseModel, Field
from metagpt.const import METAGPT_ROOT
class ToolLogItem(BaseModel):
type_: str = Field(alias="type", default="str", description="Data type of `value` field.")
name: str
value: str
TOOL_LOG_END_MARKER = ToolLogItem(
type="str", name="end_marker", value="#END#"
) # A special log item to suggest the end of a stream log
def define_log_level(print_level="INFO", logfile_level="DEBUG", name: str = None):
"""Adjust the log level to above level"""
current_date = datetime.now()
@ -36,9 +48,9 @@ def log_llm_stream(msg):
_llm_stream_log(msg)
def log_tool_output(output: dict, tool_name: str = ""):
def log_tool_output(output: ToolLogItem | list[ToolLogItem], tool_name: str = ""):
"""interface for logging tool output, can be set to log tool output in different ways to different places with set_tool_output_logfunc"""
_tool_output_log(output, tool_name)
_tool_output_log(output=output, tool_name=tool_name)
def set_llm_stream_logfunc(func):
@ -54,4 +66,4 @@ def set_tool_output_logfunc(func):
_llm_stream_log = partial(print, end="")
_tool_output_log = partial(print, end="")
_tool_output_log = lambda output, tool_name: print(output)