Skip to content

Commit

Permalink
[FEAT][Save to json]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Feb 13, 2024
1 parent 54f19e5 commit 43e19f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- [ ]
29 changes: 26 additions & 3 deletions autort/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Callable, List, Any

from swarms import (
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 43e19f6

Please sign in to comment.