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,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"
|
||||||
|
)
|
@ -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
|
Loading…
Reference in new issue