-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in
logger.chat
; Add speak interface within agent;
- Loading branch information
Showing
5 changed files
with
109 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
""" Unit test for logger chat""" | ||
import shutil | ||
import time | ||
import unittest | ||
|
||
from loguru import logger | ||
|
||
from agentscope.utils import setup_logger | ||
|
||
|
||
class LoggerTest(unittest.TestCase): | ||
""" | ||
Unit test for logger. | ||
""" | ||
|
||
def test_logger_chat(self) -> None: | ||
"""Logger chat.""" | ||
|
||
setup_logger("./runs/", level="INFO") | ||
|
||
# str with "\n" | ||
logger.chat("Test\nChat\n\nMessage\n\n") | ||
|
||
# dict with "\n" | ||
logger.chat({"name": "Alice", "content": "Hi!\n", "url": | ||
"https://xxx.png"}) | ||
|
||
# dict without content | ||
logger.chat({"name": "Alice", "url": "https://xxx.png"}) | ||
|
||
# dict | ||
logger.chat({"abc": 1}) | ||
|
||
# To avoid that logging is not finished before the file is read | ||
time.sleep(3) | ||
|
||
with open("./runs/logging.chat", "r", encoding="utf-8") as file: | ||
lines = file.readlines() | ||
|
||
ground_truth = [ | ||
'"Test\\nChat\\n\\nMessage\\n\\n"\n', | ||
'{"name": "Alice", "content": "Hi!\\n", "url": "https://xxx.png"}\n', | ||
'{"name": "Alice", "url": "https://xxx.png"}\n', | ||
'{"abc": 1}\n' | ||
] | ||
|
||
self.assertListEqual(lines, ground_truth) | ||
|
||
def tearDown(self): | ||
"""Tear down for LoggerTest.""" | ||
shutil.rmtree("./runs/") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |