mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-27 14:25:20 +02:00
refactor: save -> dump
This commit is contained in:
parent
2688fe680a
commit
c4eb028a83
3 changed files with 11 additions and 11 deletions
|
|
@ -58,7 +58,7 @@ class Environment(BaseModel):
|
|||
route the message to the message recipient is a problem addressed by the transport framework designed
|
||||
in RFC 113.
|
||||
"""
|
||||
logger.info(f"publish_message: {message.save()}")
|
||||
logger.info(f"publish_message: {message.dump()}")
|
||||
found = False
|
||||
# According to the routing feature plan in Chapter 2.2.3.2 of RFC 113
|
||||
for obj, subscribed_tags in self.consumers.items():
|
||||
|
|
@ -66,7 +66,7 @@ class Environment(BaseModel):
|
|||
obj.put_message(message)
|
||||
found = True
|
||||
if not found:
|
||||
logger.warning(f"Message no recipients: {message.save()}")
|
||||
logger.warning(f"Message no recipients: {message.dump()}")
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ class Message(BaseModel):
|
|||
"""Return a dict containing `role` and `content` for the LLM call.l"""
|
||||
return {"role": self.role, "content": self.content}
|
||||
|
||||
def save(self) -> str:
|
||||
def dump(self) -> str:
|
||||
"""Convert the object to json string"""
|
||||
return self.json(exclude_none=True)
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ class MessageQueue:
|
|||
"""Return true if the queue is empty."""
|
||||
return self._queue.empty()
|
||||
|
||||
async def save(self) -> str:
|
||||
async def dump(self) -> str:
|
||||
"""Convert the `MessageQueue` object to a json string."""
|
||||
if self.empty():
|
||||
return "[]"
|
||||
|
|
@ -299,7 +299,7 @@ class MessageQueue:
|
|||
if __name__ == "__main__":
|
||||
m = Message("a", role="v1")
|
||||
m.set_role("v2")
|
||||
v = m.save()
|
||||
v = m.dump()
|
||||
m = Message.load(v)
|
||||
|
||||
test_content = "test_message"
|
||||
|
|
@ -312,9 +312,9 @@ if __name__ == "__main__":
|
|||
logger.info(msgs)
|
||||
|
||||
jsons = [
|
||||
UserMessage(test_content).save(),
|
||||
SystemMessage(test_content).save(),
|
||||
AIMessage(test_content).save(),
|
||||
Message(test_content, role="QA").save(),
|
||||
UserMessage(test_content).dump(),
|
||||
SystemMessage(test_content).dump(),
|
||||
AIMessage(test_content).dump(),
|
||||
Message(test_content, role="QA").dump(),
|
||||
]
|
||||
logger.info(jsons)
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ def test_messages():
|
|||
@pytest.mark.asyncio
|
||||
def test_message():
|
||||
m = Message("a", role="v1")
|
||||
v = m.save()
|
||||
v = m.dump()
|
||||
d = json.loads(v)
|
||||
assert d
|
||||
assert d.get("content") == "a"
|
||||
assert d.get("meta_info") == {"role": "v1"}
|
||||
m.set_role("v2")
|
||||
v = m.save()
|
||||
v = m.dump()
|
||||
assert v
|
||||
m = Message.load(v)
|
||||
assert m.content == "a"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue