pull/475/head
Kye Gomez 8 months ago
parent b0b25439c5
commit 612beb4df3

@ -1,8 +0,0 @@
from swarms.models.speecht5 import SpeechT5Wrapper
speechT5 = SpeechT5Wrapper()
result = speechT5("Hello, how are you?")
speechT5.save_speech(result)
print("Speech saved successfully!")

@ -1,42 +0,0 @@
from swarms import DialogueSimulator, Worker
from swarms.models import OpenAIChat
llm = OpenAIChat(
model_name="gpt-4", openai_api_key="api-key", temperature=0.5
)
worker1 = Worker(
llm=llm,
ai_name="Bumble Bee",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)
worker2 = Worker(
llm=llm,
ai_name="Optimus Prime",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)
worker3 = Worker(
llm=llm,
ai_name="Megatron",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)
collab = DialogueSimulator(
[worker1, worker2],
# DialogueSimulator.select_next_speaker
)
collab.run(
max_iters=4,
name="plinus",
message="how can we enable multi agent collaboration",
)

@ -1,33 +0,0 @@
import os
from dotenv import load_dotenv
from swarms import ModelParallelizer
from swarms.models import Anthropic, Gemini, Mixtral, OpenAIChat
load_dotenv()
# API Keys
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
openai_api_key = os.getenv("OPENAI_API_KEY")
gemini_api_key = os.getenv("GEMINI_API_KEY")
# Initialize the models
llm = OpenAIChat(openai_api_key=openai_api_key)
anthropic = Anthropic(anthropic_api_key=anthropic_api_key)
mixtral = Mixtral()
gemini = Gemini(gemini_api_key=gemini_api_key)
# Initialize the parallelizer
llms = [llm, anthropic, mixtral, gemini]
parallelizer = ModelParallelizer(llms)
# Set the task
task = "Generate a 10,000 word blog on health and wellness."
# Run the task
out = parallelizer.run(task)
# Print the responses 1 by 1
for i in range(len(out)):
print(f"Response from LLM {i}: {out[i]}")

@ -1,4 +1,4 @@
from swarms import HierarchicalSwarm
from swarms.structs.hiearchical_swarm import HierarchicalSwarm
# Retrieve your API key from the environment or replace with your actual key
api_key = "sksdsds"

@ -1,5 +1,5 @@
from swarms.models import OpenAIChat
from swarms.swarms.multi_agent_debate import (
from swarms.structs.multi_agent_debate import (
MultiAgentDebate,
select_speaker,
)
@ -11,7 +11,6 @@ worker1 = Worker(
llm=llm,
ai_name="Bumble Bee",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)
@ -19,7 +18,6 @@ worker2 = Worker(
llm=llm,
ai_name="Optimus Prime",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)
@ -27,7 +25,6 @@ worker3 = Worker(
llm=llm,
ai_name="Megatron",
ai_role="Worker in a swarm",
external_tools=None,
human_in_the_loop=False,
temperature=0.5,
)

@ -1,7 +1,6 @@
# This might not work in the beginning but it's a starting point
from swarms.structs import GPT4V, Agent
from swarms import GPT4VisionAPI, Agent
llm = GPT4V()
llm = GPT4VisionAPI()
agent = Agent(
max_loops="auto",

@ -1,18 +0,0 @@
from swarms.agents.base import agent
from swarms.structs.nonlinear_worfklow import NonLinearWorkflow, Task
prompt = "develop a feedforward network in pytorch"
prompt2 = "Develop a self attention using pytorch"
task1 = Task("task1", prompt)
task2 = Task("task2", prompt2, parents=[task1])
# add tasks to workflow
workflow = NonLinearWorkflow(agent)
# add tasks to tree
workflow.add(task1)
workflow.add(task2)
# run
workflow.run()

@ -1,17 +0,0 @@
from swarms import Orchestrator, Worker
node = Worker(
openai_api_key="",
ai_name="Optimus Prime",
)
# Instantiate the Orchestrator with 10 agents
orchestrator = Orchestrator(node, agent_list=[node] * 10, task_queue=[])
# Agent 7 sends a message to Agent 9
orchestrator.chat(
sender_id=7,
receiver_id=9,
message="Can you help me with this task?",
)

@ -0,0 +1,66 @@
from swarms import Agent, Anthropic
from swarms.structs.society_of_agents import SocietyOfAgents
# Initialize the director agent
director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the workers",
llm=Anthropic(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="director.json",
)
# Initialize worker 1
worker1 = Agent(
agent_name="Worker1",
system_prompt="Generates a transcript for a youtube video on what swarms are",
llm=Anthropic(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="worker1.json",
)
# Initialize worker 2
worker2 = Agent(
agent_name="Worker2",
system_prompt="Summarizes the transcript generated by Worker1",
llm=Anthropic(),
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="worker2.json",
)
# Create a list of agents
agents = [director, worker1, worker2]
# Create the swarm
society = SocietyOfAgents(
name="Society of Agents",
description="A society of agents that work together to complete a task",
agents=agents,
max_loops=1,
rules="Don't stop until the task is done",
)
# Run the swarm
output = society.run(
"Create a format to express and communicate swarms of llms in a structured manner for youtube"
)

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "5.0.5"
version = "5.0.6"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]

@ -2,7 +2,8 @@ def DOCUMENTATION_WRITER_SOP(
task: str,
module: str,
):
documentation = f"""Create multi-page long and explicit professional pytorch-like documentation for the {module} code below follow the outline for the {module} library,
documentation = f"""
Create multi-page long and explicit professional pytorch-like documentation for the {module} code below follow the outline for the {module} library,
provide many examples and teach the user about the code, provide examples for every function, make the documentation 10,000 words,
provide many usage examples and note this is markdown docs, create the documentation for the code to document,
put the arguments and methods in a table in markdown to make it visually seamless

@ -6,6 +6,25 @@ from beartype import beartype
from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm
from swarms.utils.loguru_logger import logger
from pydantic import BaseModel, Field
class HiearchicalRequest(BaseModel):
task: str = Field(
None,
title="Task",
description="The task to send to the director agent.",
)
agents: Agent = Field(
None,
title="Agents",
description="The list of agents in the hierarchical swarm.",
)
rules: str = Field(
None,
title="Rules",
description="The rules for the hierarchical swarm.",
)
class HiearchicalSwarm(BaseSwarm):
@ -34,6 +53,8 @@ class HiearchicalSwarm(BaseSwarm):
for agent in agents:
agent.long_term_memory = long_term_memory_system
# Set the max loops of every agent to max loops
def parse_function_activate_agent(
self, json_data: str = None, *args, **kwargs
):
@ -52,14 +73,30 @@ class HiearchicalSwarm(BaseSwarm):
"""
try:
data = json.loads(json_data)
name = data.get("name")
task = data.get("task")
response = self.select_agent_and_send_task(
name, task, *args, **kwargs
)
# Check if the data is a list of agent task pairs
if isinstance(data, list):
responses = []
# Iterate over the list of agent task pairs
for agent_task in data:
name = agent_task.get("name")
task = agent_task.get("task")
return response
response = self.select_agent_and_send_task(
name, task, *args, **kwargs
)
responses.append(response)
return responses
else:
name = data.get("name")
task = data.get("task")
response = self.select_agent_and_send_task(
name, task, *args, **kwargs
)
return response
except json.JSONDecodeError:
logger.error("Invalid JSON data, try again.")
raise json.JSONDecodeError
@ -124,6 +161,8 @@ class HiearchicalSwarm(BaseSwarm):
loop += 1
task = response
return response
except Exception as e:
logger.error(f"Error: {e}")

@ -0,0 +1,50 @@
from typing import List
from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm
from swarms.structs.conversation import Conversation
from swarms.utils.loguru_logger import logger
class SocietyOfAgents(BaseSwarm):
def __init__(
self,
name: str = None,
description: str = None,
agents: List[Agent] = None,
max_loops: int = 1,
rules: str = None,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
self.name = name
self.description = description
self.agents = agents
self.max_loops = max_loops
self.conversation = Conversation(
time_enabled=True, rules=rules, *args, **kwargs
)
def run(self, task: str = None, *args, **kwargs):
loop = 0
try:
while loop < self.max_loops:
for agent in self.agents:
out = agent.run(task, *args, **kwargs)
# Save the conversation
self.conversation.add(agent.agent_name, out)
task = out
# Log the agent's output
logger.info(f"Agent {agent.agent_name} output: {out}")
loop += 1
except Exception as e:
logger.error(f"An error occurred: {e}")
return None
return out

@ -26,7 +26,11 @@ def parse_tasks(
def find_agent_by_id(
agent_id: str = None, agents: List[Agent] = None, *args, **kwargs
agent_id: str = None,
agents: List[Agent] = None,
task: str = None,
*args,
**kwargs,
) -> Agent:
"""Find agent by id
@ -39,7 +43,11 @@ def find_agent_by_id(
"""
for agent in agents:
if agent.id == agent_id:
return agent
if task:
return agent.run(task, *args, **kwargs)
else:
return agent
return None

Loading…
Cancel
Save