From a5de07505c5a9215794721ce13e4640fa48b7d45 Mon Sep 17 00:00:00 2001 From: Kye Date: Tue, 26 Sep 2023 18:40:33 -0400 Subject: [PATCH] inits --- example_godmode.py | 4 +-- multi_agent_debate.py | 44 +---------------------- swarms/__init__.py | 13 ++----- swarms/models/__init__.py | 7 ++-- swarms/swarms/__init__.py | 6 ++-- swarms/swarms/multi_agent_debate.py | 55 +++++++++++++++++------------ 6 files changed, 43 insertions(+), 86 deletions(-) diff --git a/example_godmode.py b/example_godmode.py index e33e304f..e9f3bca5 100644 --- a/example_godmode.py +++ b/example_godmode.py @@ -1,6 +1,6 @@ -from langchain.llms import GooglePalm, OpenAIChat -from swarms.swarms.god_mode import Anthropic, GodMode +from swarms.models import Anthropic, GooglePalm, OpenAIChat +from swarms.swarms.god_mode import GodMode claude = Anthropic(anthropic_api_key="") palm = GooglePalm(google_api_key="") diff --git a/multi_agent_debate.py b/multi_agent_debate.py index e7a05055..dba0d1d3 100644 --- a/multi_agent_debate.py +++ b/multi_agent_debate.py @@ -1,47 +1,5 @@ from typing import List, Callable -from swarms import Worker - - -class MultiAgentDebate: - def __init__( - self, - agents: List[Worker], - selection_func: Callable[[int, List[Worker]], int] - ): - self.agents = agents - self.selection_func = selection_func - - def reset_agents(self): - for agent in self.agents: - 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({ - 'agent': speaker.ai_name, - 'response': response - }) - return results - - def update_task(self, task: str): - self.task = task - - def format_results(self, results): - formatted_results = "\n".join([f"Agent {result['agent']} responded: {result['response']}" for result in results]) - return formatted_results - -# 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) +from swarms import Worker, MultiAgentDebate, select_speaker # Initialize agents worker1 = Worker(openai_api_key="", ai_name="Optimus Prime") diff --git a/swarms/__init__.py b/swarms/__init__.py index d4992455..e118f67d 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -12,23 +12,14 @@ from swarms.workers.worker import Worker # from swarms.boss.boss_node import Boss #models -from swarms.models.anthropic import Anthropic -from swarms.models.palm import GooglePalm -from swarms.models.petals import Petals -from swarms.models.openai import OpenAIChat +import swarms.models #structs from swarms.structs.workflow import Workflow from swarms.structs.task import Task # swarms -from swarms.swarms.dialogue_simulator import DialogueSimulator -from swarms.swarms.autoscaler import AutoScaler -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 - +import swarms.swarms #agents from swarms.swarms.profitpilot import ProfitPilot diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 3c423801..195287e5 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -1,7 +1,6 @@ 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.openai import OpenAIChat - +from swarms.models.openai import OpenAIChat #prompts -from swarms.models.prompts.debate import * +from swarms.models.prompts.debate import * \ No newline at end of file diff --git a/swarms/swarms/__init__.py b/swarms/swarms/__init__.py index 6aa0714e..0d4f85e9 100644 --- a/swarms/swarms/__init__.py +++ b/swarms/swarms/__init__.py @@ -1,10 +1,8 @@ - # swarms from swarms.swarms.dialogue_simulator import DialogueSimulator from swarms.swarms.autoscaler import AutoScaler 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 -from swarms.swarms.groupchat import GroupChat - +from swarms.swarms.multi_agent_debate import MultiAgentDebate, select_speaker +from swarms.swarms.groupchat import GroupChat \ No newline at end of file diff --git a/swarms/swarms/multi_agent_debate.py b/swarms/swarms/multi_agent_debate.py index f27744e4..ba9682c7 100644 --- a/swarms/swarms/multi_agent_debate.py +++ b/swarms/swarms/multi_agent_debate.py @@ -1,34 +1,45 @@ -from typing import List +from typing import List, Callable 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: - def __init__(self, agents: List[Worker]): + def __init__( + self, + agents: List[Worker], + selection_func: Callable[[int, List[Worker]], int] + ): self.agents = agents + self.selection_func = selection_func - def run(self, task: str): - results = [] + def reset_agents(self): 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({ - 'agent': agent.ai_name, + 'agent': speaker.ai_name, 'response': response }) return results -# Initialize agents -agents = [ - 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) + def update_task(self, task: str): + self.task = task -# Print results -for result in results: - print(f"Agent {result['agent']} responded: {result['response']}") \ No newline at end of file + def format_results(self, results): + formatted_results = "\n".join([f"Agent {result['agent']} responded: {result['response']}" for result in results]) + return formatted_results