parent
2ca7191c77
commit
151217b496
@ -1,7 +1,6 @@
|
|||||||
from swarms.models.anthropic import Anthropic
|
from swarms.models.anthropic import Anthropic
|
||||||
# from swarms.models.palm import GooglePalm
|
from swarms.models.palm import GooglePalm
|
||||||
from swarms.models.petals import Petals
|
from swarms.models.petals import Petals
|
||||||
#from swarms.models.openai import OpenAIChat
|
from swarms.models.openai import OpenAIChat
|
||||||
|
|
||||||
#prompts
|
#prompts
|
||||||
from swarms.models.prompts.debate import *
|
from swarms.models.prompts.debate import *
|
@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
# swarms
|
# 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.god_mode import GodMode
|
||||||
from swarms.swarms.simple_swarm import SimpleSwarm
|
from swarms.swarms.simple_swarm import SimpleSwarm
|
||||||
from swarms.swarms.multi_agent_debate import MultiAgentDebate
|
from swarms.swarms.multi_agent_debate import MultiAgentDebate, select_speaker
|
||||||
from swarms.swarms.groupchat import GroupChat
|
from swarms.swarms.groupchat import GroupChat
|
||||||
|
|
@ -1,34 +1,45 @@
|
|||||||
from typing import List
|
from typing import List, Callable
|
||||||
from swarms import Worker
|
from swarms import Worker
|
||||||
|
|
||||||
|
|
||||||
|
# Define a selection function
|
||||||
|
def select_speaker(step: int, agents: List[Worker]) -> int:
|
||||||
|
# This function selects the speaker in a round-robin fashion
|
||||||
|
return step % len(agents)
|
||||||
|
|
||||||
|
|
||||||
class MultiAgentDebate:
|
class MultiAgentDebate:
|
||||||
def __init__(self, agents: List[Worker]):
|
def __init__(
|
||||||
|
self,
|
||||||
|
agents: List[Worker],
|
||||||
|
selection_func: Callable[[int, List[Worker]], int]
|
||||||
|
):
|
||||||
self.agents = agents
|
self.agents = agents
|
||||||
|
self.selection_func = selection_func
|
||||||
|
|
||||||
def run(self, task: str):
|
def reset_agents(self):
|
||||||
results = []
|
|
||||||
for agent in self.agents:
|
for agent in self.agents:
|
||||||
response = agent.run(task)
|
agent.reset()
|
||||||
|
|
||||||
|
def inject_agent(self, agent: Worker):
|
||||||
|
self.agents.append(agent)
|
||||||
|
|
||||||
|
def run(self, task: str, max_iters: int = None):
|
||||||
|
self.reset_agents()
|
||||||
|
results = []
|
||||||
|
for i in range(max_iters or len(self.agents)):
|
||||||
|
speaker_idx = self.selection_func(i, self.agents)
|
||||||
|
speaker = self.agents[speaker_idx]
|
||||||
|
response = speaker.run(task)
|
||||||
results.append({
|
results.append({
|
||||||
'agent': agent.ai_name,
|
'agent': speaker.ai_name,
|
||||||
'response': response
|
'response': response
|
||||||
})
|
})
|
||||||
return results
|
return results
|
||||||
|
|
||||||
# Initialize agents
|
def update_task(self, task: str):
|
||||||
agents = [
|
self.task = task
|
||||||
Worker(openai_api_key="", ai_name="Optimus Prime"),
|
|
||||||
Worker(openai_api_key="", ai_name="Bumblebee"),
|
|
||||||
Worker(openai_api_key="", ai_name="Megatron")
|
|
||||||
]
|
|
||||||
|
|
||||||
# Initialize multi-agent debate
|
|
||||||
debate = MultiAgentDebate(agents)
|
|
||||||
|
|
||||||
# Run task
|
|
||||||
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."
|
|
||||||
results = debate.run(task)
|
|
||||||
|
|
||||||
# Print results
|
def format_results(self, results):
|
||||||
for result in results:
|
formatted_results = "\n".join([f"Agent {result['agent']} responded: {result['response']}" for result in results])
|
||||||
print(f"Agent {result['agent']} responded: {result['response']}")
|
return formatted_results
|
||||||
|
Loading…
Reference in new issue