From 43e19f65190c956078d1b9a451642edb199e8c10 Mon Sep 17 00:00:00 2001 From: Kye Date: Tue, 13 Feb 2024 11:36:49 -0800 Subject: [PATCH] [FEAT][Save to json] --- README.md | 5 +++++ autort/main.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27033fd..6d1ad6e 100644 --- a/README.md +++ b/README.md @@ -88,3 +88,8 @@ MIT +# Todo +- [ ] Implement a run method into `AutoRTSwarm` that runs all the agents with APIs. +- [ ] Make it able to send commands to a certain agent using the swarm network. +- [ ] Send a task to all agents in the swarm network +- [ ] \ No newline at end of file diff --git a/autort/main.py b/autort/main.py index cb3b1fe..a28d555 100644 --- a/autort/main.py +++ b/autort/main.py @@ -1,3 +1,4 @@ +import json from typing import Callable, List, Any from swarms import ( @@ -168,13 +169,18 @@ def __init__( self, agents: List[AutoRTAgent], datastore: Any = None, + autosave: bool = True, *args, **kwargs, ): self.agents = agents self.datastore = datastore + self.autosave = autosave self.conversation = Conversation( time_enabled=True, + save_filepath="autort_conversation.json", + *args, + **kwargs, ) # Swarm Network @@ -195,6 +201,23 @@ def run(self, text: str, img: str = None, *args, **kwargs): Returns: List: A list of results from running each agent. """ - return self.network.run_many_agents( - text, img, *args, **kwargs - ) + out = self.network.run_many_agents(text, img, *args, **kwargs) + + if self.autosave: + self.conversation.save_to_json( + self.conversation.save_filepath, out + ) + + return out + + def save_to_json(self, filename: str, content: List): + # Save the conversation to a JSON file + with open(filename, "w") as f: + json.dump(content, f, indent=4) + + def load_from_json(self, filename: str): + # Load the conversation from a JSON file + with open(filename, "r") as f: + content = json.load(f) + + return content