[BUFG][[BUG] FileNotFoundError: [Errno 2] No such file or directory: 'runs/conversation.json' #350]

pull/352/head
Kye 1 year ago
parent b48b405f28
commit 4abf987929

@ -43,7 +43,7 @@ class ConcurrentWorkflow(BaseStructure):
return_results: bool = False return_results: bool = False
use_processes: bool = False use_processes: bool = False
def add(self, task: Task, tasks: List[Task] = None): def add(self, task: Task = None):
"""Adds a task to the workflow. """Adds a task to the workflow.
Args: Args:
@ -51,11 +51,7 @@ class ConcurrentWorkflow(BaseStructure):
tasks (List[Task]): _description_ tasks (List[Task]): _description_
""" """
try: try:
if tasks: self.tasks.append(task)
for task in tasks:
self.tasks.append(task)
else:
self.tasks.append(task)
except Exception as error: except Exception as error:
print(f"[ERROR][ConcurrentWorkflow] {error}") print(f"[ERROR][ConcurrentWorkflow] {error}")
raise error raise error

@ -1,3 +1,4 @@
import os
import datetime import datetime
import json import json
@ -70,8 +71,8 @@ class Conversation(BaseStructure):
self, self,
time_enabled: bool = False, time_enabled: bool = False,
database: AbstractDatabase = None, database: AbstractDatabase = None,
autosave: bool = True, autosave: bool = None,
save_filepath: str = "runs/conversation.json", save_filepath: str = None,
*args, *args,
**kwargs, **kwargs,
): ):
@ -228,6 +229,9 @@ class Conversation(BaseStructure):
Args: Args:
filename (str): Save the conversation history as a JSON file filename (str): Save the conversation history as a JSON file
""" """
# Create the directory if it does not exist
os.makedirs(os.path.dirname(filename), exist_ok=True)
# Save the conversation history as a JSON file # Save the conversation history as a JSON file
with open(filename, "w") as f: with open(filename, "w") as f:
json.dump(self.conversation_history, f) json.dump(self.conversation_history, f)

@ -112,25 +112,23 @@ def power_swarm(agents: List[str], tasks: List[str]):
def log_swarm(agents: List[Agent], tasks: List[str]): def log_swarm(agents: List[Agent], tasks: List[str]):
for i in range(len(agents)): for i in range(len(agents)):
if 2 ** i < len(agents) and tasks: if 2**i < len(agents) and tasks:
task = tasks.pop(0) task = tasks.pop(0)
agents[2 ** i].run(task) agents[2**i].run(task)
def exponential_swarm(agents: List[Agent], tasks: List[str]): def exponential_swarm(agents: List[Agent], tasks: List[str]):
for i in range(len(agents)): for i in range(len(agents)):
index = min( index = min(int(2**i), len(agents) - 1)
int(2 ** i),
len(agents)-1
)
if tasks: if tasks:
task = tasks.pop(0) task = tasks.pop(0)
agents[index].run(task) agents[index].run(task)
def geometric_swarm(agents, tasks): def geometric_swarm(agents, tasks):
ratio = 2 ratio = 2
for i in range(range(len(agents))): for i in range(range(len(agents))):
index = min(int(ratio ** 2), len(agents)-1) index = min(int(ratio**2), len(agents) - 1)
if tasks: if tasks:
task = tasks.pop(0) task = tasks.pop(0)
agents[index].run(task) agents[index].run(task)
@ -138,11 +136,12 @@ def geometric_swarm(agents, tasks):
def harmonic_swarm(agents: List[Agent], tasks: List[str]): def harmonic_swarm(agents: List[Agent], tasks: List[str]):
for i in range(1, len(agents) + 1): for i in range(1, len(agents) + 1):
index = min(int(len(agents)/i), len(agents) -1) index = min(int(len(agents) / i), len(agents) - 1)
if tasks: if tasks:
task = tasks.pop(0) task = tasks.pop(0)
agents[index].run(task) agents[index].run(task)
def staircase_swarm(agents: List[Agent], task: str): def staircase_swarm(agents: List[Agent], task: str):
step = len(agents) // 5 step = len(agents) // 5
for i in range(len(agents)): for i in range(len(agents)):
@ -155,6 +154,7 @@ def sigmoid_swarm(agents: List[Agent], task: str):
index = int(len(agents) / (1 + math.exp(-i))) index = int(len(agents) / (1 + math.exp(-i)))
agents[index].run(task) agents[index].run(task)
def sinusoidal_swarm(agents: List[Agent], task: str): def sinusoidal_swarm(agents: List[Agent], task: str):
for i in range(len(agents)): for i in range(len(agents)):
index = int((math.sin(i) + 1) / 2 * len(agents)) index = int((math.sin(i) + 1) / 2 * len(agents))

Loading…
Cancel
Save