Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions autogen/logger/file_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..doc_utils import export_module
from .base_logger import BaseLogger, LLMConfig
from .logger_utils import get_current_ts, to_dict
from .logger_utils import redact as _redact

if TYPE_CHECKING:
from openai import AzureOpenAI, OpenAI
Expand All @@ -39,8 +40,6 @@

__all__ = ("FileLogger",)

from .logger_utils import redact as _redact


def safe_serialize(obj: Any) -> str:
def default(o: Any) -> str:
Expand Down Expand Up @@ -109,7 +108,7 @@ def log_chat_completion(
"invocation_id": str(invocation_id),
"client_id": client_id,
"wrapper_id": wrapper_id,
"request": to_dict(request),
"request": _redact(to_dict(request)),
"response": str(response),
"is_cached": is_cached,
"cost": cost,
Expand Down Expand Up @@ -137,7 +136,7 @@ def log_new_agent(self, agent: ConversableAgent, init_args: dict[str, Any] = {})
"session_id": self.session_id,
"current_time": get_current_ts(),
"agent_type": type(agent).__name__,
"args": to_dict(init_args),
"args": _redact(to_dict(init_args)),
"thread_id": thread_id,
})
self.logger.info(log_data)
Expand Down
9 changes: 5 additions & 4 deletions autogen/logger/sqlite_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..doc_utils import export_module
from .base_logger import BaseLogger, LLMConfig
from .logger_utils import get_current_ts, get_sensitive_exclude_keys, to_dict
from .logger_utils import redact as _redact

if TYPE_CHECKING:
from openai import AzureOpenAI, OpenAI
Expand Down Expand Up @@ -294,7 +295,7 @@ def log_chat_completion(
client_id,
wrapper_id,
self.session_id,
json.dumps(to_dict(request)),
json.dumps(_redact(to_dict(request))),
response_messages,
is_cached,
cost,
Expand Down Expand Up @@ -357,7 +358,7 @@ def log_event(self, source: str | Agent, name: str, **kwargs: dict[str, Any]) ->
if self.con is None:
return

json_args = json.dumps(kwargs, default=lambda o: f"<<non-serializable: {type(o).__qualname__}>>")
json_args = json.dumps(_redact(kwargs), default=lambda o: f"<<non-serializable: {type(o).__qualname__}>>")

if isinstance(source, Agent):
query = """
Expand Down Expand Up @@ -432,8 +433,8 @@ def log_function_use(self, source: str | Agent, function: F, args: dict[str, Any
id(source),
source.name if hasattr(source, "name") else source,
function.__name__,
safe_serialize(args),
safe_serialize(returns),
safe_serialize(_redact(args) if isinstance(args, dict) else args),
safe_serialize(_redact(returns) if isinstance(returns, dict) else returns),
get_current_ts(),
)
self._run_query(query=query, args=query_args)
Expand Down
Loading
Loading