Skip to content

Commit

Permalink
Merge pull request #132 from ag2ai/patch/logging
Browse files Browse the repository at this point in the history
Patch/logging
  • Loading branch information
Hk669 authored Dec 3, 2024
2 parents 17e4b14 + ddffd6f commit 95431af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions autogen/logger/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
import datetime
import inspect
from datetime import datetime, timezone
from pathlib import Path, PurePath
from typing import Any, Dict, List, Tuple, Union

__all__ = ("get_current_ts", "to_dict")


def get_current_ts() -> str:
return datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S.%f")
return datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S.%f")


def to_dict(
Expand All @@ -22,6 +23,8 @@ def to_dict(
) -> Any:
if isinstance(obj, (int, float, str, bool)):
return obj
elif isinstance(obj, (Path, PurePath)):
return str(obj)
elif callable(obj):
return inspect.getsource(obj).strip()
elif isinstance(obj, dict):
Expand Down
9 changes: 9 additions & 0 deletions test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
import json
import os
import sqlite3
import uuid
from pathlib import Path
from typing import Any, Callable
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -232,12 +234,16 @@ def test_log_oai_client(db_connection):

def test_to_dict():
from autogen import Agent
from autogen.coding import LocalCommandLineCodeExecutor

agent_executor = LocalCommandLineCodeExecutor(work_dir=Path("."))

agent1 = autogen.ConversableAgent(
"alice",
human_input_mode="NEVER",
llm_config=False,
default_auto_reply="This is alice speaking.",
code_execution_config={"executor": agent_executor},
)

agent2 = autogen.ConversableAgent(
Expand All @@ -256,6 +262,7 @@ def __init__(self):
self.d = None
self.test_function = lambda x, y: x + y
self.extra_key = "remove this key"
self.path = Path("/to/something")

class Bar(object):
def init(self):
Expand All @@ -270,13 +277,15 @@ def build(self):
bar = Bar()
bar.build()

expected_path = "\\to\\something" if os.name == "nt" else "/to/something"
expected_foo_val_field = [
{
"a": 1.234,
"b": "some string",
"c": {"some_key": [7, 8, 9]},
"d": None,
"test_function": "self.test_function = lambda x, y: x + y",
"path": expected_path,
}
]

Expand Down

0 comments on commit 95431af

Please sign in to comment.