@ -155,7 +155,10 @@ class Swarms:
boss_node = self . initialize_boss_node ( vectorstore , worker_node )
boss_node = self . initialize_boss_node ( vectorstore , worker_node )
task = boss_node . create_task ( objective )
task = boss_node . create_task ( objective )
return boss_node . execute_task ( task )
logging . info ( f " Running task: { task } " )
result = await boss_node . execute_task ( task )
logging . info ( f " Completed tasks: { task } " )
return result
except Exception as e :
except Exception as e :
logging . error ( f " An error occurred in run_swarms: { e } " )
logging . error ( f " An error occurred in run_swarms: { e } " )
return None
return None
@ -181,12 +184,15 @@ def swarm(api_key="", objective=""):
raise ValueError ( " A valid objective is required " )
raise ValueError ( " A valid objective is required " )
try :
try :
swarms = Swarms ( api_key )
swarms = Swarms ( api_key )
result = asyncio . run ( swarms . run_swarms ( objective ) )
loop = asyncio . get_event_loop ( )
if result is None :
tasks = [ loop . create_task ( swarms . run_swarms ( objective ) ) ]
completed , pending = loop . run_until_complete ( asyncio . wait ( tasks ) )
results = [ t . result ( ) for t in completed ]
if not results or any ( result is None for result in results ) :
logging . error ( " Failed to run swarms " )
logging . error ( " Failed to run swarms " )
else :
else :
logging . info ( f " Successfully ran swarms with result: { result } " )
logging . info ( f " Successfully ran swarms with result s : { result s } " )
return result
return result s
except Exception as e :
except Exception as e :
logging . error ( f " An error occured in swarm: { e } " )
logging . error ( f " An error occured in swarm: { e } " )
return None
return None