parent
246a66640b
commit
55f86cd29e
@ -1,3 +1,8 @@
|
|||||||
|
|
||||||
|
# swarms
|
||||||
from swarms.swarms.dialogue_simulator import DialogueSimulator
|
from swarms.swarms.dialogue_simulator import DialogueSimulator
|
||||||
from swarms.swarms.autoscaler import AutoScaler
|
from swarms.swarms.autoscaler import AutoScaler
|
||||||
from swarms.swarms.orchestrate import Orchestrator
|
from swarms.swarms.orchestrate import Orchestrator
|
||||||
|
from swarms.swarms.god_mode import GodMode
|
||||||
|
from swarms.swarms.simple_swarm import SimpleSwarm
|
||||||
|
from swarms.swarms.multi_agent_debate import MultiAgentDebate
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
|
from tabulate import tabulate
|
||||||
|
from termcolor import colored
|
||||||
|
|
||||||
|
from swarms.workers.worker import Worker
|
||||||
|
|
||||||
|
class GodMode:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
num_workers,
|
||||||
|
num_llms,
|
||||||
|
openai_api_key,
|
||||||
|
ai_name
|
||||||
|
):
|
||||||
|
self.workers = [
|
||||||
|
Worker(
|
||||||
|
openai_api_key=openai_api_key,
|
||||||
|
ai_name=ai_name
|
||||||
|
) for _ in range(num_workers)
|
||||||
|
]
|
||||||
|
# self.llms = [LLM() for _ in range(num_llms)]
|
||||||
|
self.all_agents = self.workers # + self.llms
|
||||||
|
|
||||||
|
def run_all(self, task):
|
||||||
|
with ThreadPoolExecutor() as executor:
|
||||||
|
responses = executor.map(
|
||||||
|
lambda agent: agent.run(task) if hasattr(
|
||||||
|
agent, 'run'
|
||||||
|
) else agent(task), self.all_agents)
|
||||||
|
|
||||||
|
return list(responses)
|
||||||
|
|
||||||
|
def print_responses(self, task):
|
||||||
|
responses = self.run_all(task)
|
||||||
|
|
||||||
|
table = []
|
||||||
|
|
||||||
|
for i, response in enumerate(responses):
|
||||||
|
agent_type = "Worker" if i < len(self.workers) else "LLM"
|
||||||
|
table.append([agent_type, response])
|
||||||
|
print(
|
||||||
|
colored(
|
||||||
|
tabulate(
|
||||||
|
table,
|
||||||
|
headers=["Agent Type", "Response"],
|
||||||
|
tablefmt="pretty"
|
||||||
|
), "cyan")
|
||||||
|
)
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
god_mode = GodMode(num_workers=3, openai_api_key="", ai_name="Optimus Prime")
|
||||||
|
task = "What were the winning Boston Marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."
|
||||||
|
god_mode.print_responses(task)
|
@ -0,0 +1,34 @@
|
|||||||
|
from swarms.worker.worker import Worker
|
||||||
|
|
||||||
|
class SimpleSwarm:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
num_workers,
|
||||||
|
openai_api_key,
|
||||||
|
ai_name
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
swarm = Swarm(num_workers=5, openai_api_key="", ai_name="Optimus Prime")
|
||||||
|
task = "What were the winning Boston Marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."
|
||||||
|
responses = swarm.distribute_task(task)
|
||||||
|
|
||||||
|
for response in responses:
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.workers = [
|
||||||
|
Worker(openai_api_key, ai_name) for _ in range(num_workers)
|
||||||
|
]
|
||||||
|
|
||||||
|
def run(self, task):
|
||||||
|
responses = []
|
||||||
|
for worker in self.workers:
|
||||||
|
response = worker.run(task)
|
||||||
|
responses.append(response)
|
||||||
|
return responses
|
||||||
|
|
||||||
|
def __call__(self, task):
|
||||||
|
return self.run(task)
|
||||||
|
|
Loading…
Reference in new issue