From 31764add8a6065316b02df6fdbc0c55f6938d1a0 Mon Sep 17 00:00:00 2001 From: seehi <6580@pm.me> Date: Mon, 12 Aug 2024 14:56:15 +0800 Subject: [PATCH] add an example --- examples/serialize_model.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/serialize_model.py diff --git a/examples/serialize_model.py b/examples/serialize_model.py new file mode 100644 index 000000000..b81afc743 --- /dev/null +++ b/examples/serialize_model.py @@ -0,0 +1,24 @@ +from metagpt.logs import logger +from metagpt.roles.product_manager import ProductManager + + +def main(): + """Demonstrates serialization and deserialization using SerializationMixin. + + This example creates an instance of ProductManager, serializes it to a file, + and then deserializes it back to an instance. + + If executed correctly, the following log messages will be output: + ProductManager serialization successful. File saved at: /data/hjt/gitlab_metagpt/workspace/storage/ProductManager.json + ProductManager deserialization successful. Instance created from file: /data/hjt/gitlab_metagpt/workspace/storage/ProductManager.json + The role is Product Manager + """ + role = ProductManager() + role.serialize() + + role: ProductManager = ProductManager.deserialize() + logger.info(f"The role is {role.profile}") + + +if __name__ == "__main__": + main()