asynchronous swarms

Former-commit-id: a0f3c74b057d3df8d3124b501aca3924151dde84
pull/160/head
Kye 2 years ago
parent 8a1b298bdb
commit b0820dd667

@ -1,9 +1,11 @@
import logging
import asyncio
from swarms.tools.agent_tools import * from swarms.tools.agent_tools import *
from swarms.agents.workers.WorkerNode import WorkerNode, worker_node from swarms.agents.workers.WorkerNode import WorkerNode, worker_node
from swarms.agents.boss.BossNode import BossNode from swarms.agents.boss.BossNode import BossNode
from swarms.agents.workers.WorkerUltraNode import WorkerUltra from swarms.agents.workers.WorkerUltraNode import WorkerUltra
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
class Swarms: class Swarms:
@ -135,7 +137,7 @@ class Swarms:
def run_swarms(self, objective): async def run_swarms(self, objective):
""" """
Run the swarm with the given objective Run the swarm with the given objective
@ -171,16 +173,15 @@ def swarm(api_key="", objective=""):
The result of the swarm. The result of the swarm.
""" """
if not api_key: if not api_key or not isinstance(api_key, str):
logging.error("OpenAIkey is not provided") logging.error("Invalid OpenAI key")
raise ValueError("OpenAI API key is not provided") raise ValueError("A valid OpenAI API key is required")
if not objective: if not objective or not isinstance(objective, str):
logging.error("Objective is not provided") logging.error("Invalid objective")
raise ValueError("Objective is required") raise ValueError("A valid objective is required")
try: try:
swarms = Swarms(api_key) swarms = Swarms(api_key)
result = swarms.run_swarms(objective) result = asyncio.run(swarms.run_swarms(objective))
if result is None: if result is None:
logging.error("Failed to run swarms") logging.error("Failed to run swarms")
else: else:

Loading…
Cancel
Save