Skip to content

Commit

Permalink
Update according to the comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavdGao committed Aug 22, 2024
1 parent 963ec48 commit 05a8c27
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/agentscope/agents/dialog_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def __init__(
use_memory=use_memory,
)

logger.warning(
f"Unused keyword arguments is provided: {kwargs}",
)
if kwargs:
logger.warning(
f"Unused keyword arguments are provided: {kwargs}",
)

def reply(self, x: Optional[Union[Msg, Sequence[Msg]]] = None) -> Msg:
"""Reply function of the agent. Processes the input data,
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/memory/temporary_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add(
# type error
if isinstance(memory_unit, PlaceholderMessage):
memory_unit.update_value()
memory_unit = Msg.from_dict(memory_unit.serialize())
memory_unit = Msg.from_dict(memory_unit.to_dict())

if not isinstance(memory_unit, Msg):
raise ValueError(
Expand Down
5 changes: 3 additions & 2 deletions src/agentscope/message/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ def formatted_str(self, colored: bool = False) -> str:
colored_strs.append(f"{name}: {self.url}")
return "\n".join(colored_strs)

def serialize(self) -> dict:
"""Return the serialized message.
def to_dict(self) -> dict:
"""Serialize the message into a dictionary, which can be
deserialized by calling the `from_dict` function.
Returns:
`dict`: The serialized dictionary.
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/message/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def __update_task_id(self) -> None:
self._task_id = task_id
self._stub = None

def serialize(self) -> dict:
def to_dict(self) -> dict:
"""Serialize the placeholder message."""
if self._is_placeholder:
self.__update_task_id()
Expand Down
4 changes: 2 additions & 2 deletions src/agentscope/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def _default_serialize(obj: Any) -> Any:
obj.__module__ == "agentscope.message.msg"
and obj.__class__.__name__ == "Msg"
):
return obj.serialize()
return obj.to_dict()

if (
obj.__module__ == "agentscope.message.placeholder"
and obj.__class__.__name__ == "PlaceholderMessage"
):
return obj.serialize()
return obj.to_dict()

return obj

Expand Down
2 changes: 1 addition & 1 deletion tests/message_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_formatted_msg(self) -> None:
def test_serialize(self) -> None:
"""Test the serialization and deserialization of Msg object."""
msg = Msg(name="A", content="B", role="assistant")
serialized_msg = msg.serialize()
serialized_msg = msg.to_dict()
deserialized_msg = Msg.from_dict(serialized_msg)
self.assertEqual(msg.id, deserialized_msg.id)
self.assertEqual(msg.name, deserialized_msg.name)
Expand Down

0 comments on commit 05a8c27

Please sign in to comment.