apply black formatting to rearrange example

pull/577/head
tad dy 8 months ago
parent ef3be69c1b
commit 23cfe542e8

@ -1,13 +1,18 @@
import os
import asyncio import asyncio
import os
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
from swarms.structs import Agent
from swarms.models import Anthropic from swarms.models import Anthropic
from swarms.structs import Agent
from swarms.structs.rearrange import AgentRearrange from swarms.structs.rearrange import AgentRearrange
llm = Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True) llm = Anthropic(
anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), streaming=True
)
async def sequential(): async def sequential():
@ -16,7 +21,7 @@ async def sequential():
system_prompt="Generate a blog post like Stephen King", system_prompt="Generate a blog post like Stephen King",
llm=llm, llm=llm,
dashboard=False, dashboard=False,
streaming_on=True streaming_on=True,
) )
agent2 = Agent( agent2 = Agent(
@ -24,7 +29,7 @@ async def sequential():
system_prompt="Summarize the blog post", system_prompt="Summarize the blog post",
llm=llm, llm=llm,
dashboard=False, dashboard=False,
streaming_on=True streaming_on=True,
) )
flow = f"{agent1.name} -> {agent2.name}" flow = f"{agent1.name} -> {agent2.name}"
@ -42,6 +47,7 @@ async def sequential():
# "Generate a short blog post about Muhammad Ali." # "Generate a short blog post about Muhammad Ali."
# ) # )
async def parallel(): async def parallel():
writer1 = Agent( writer1 = Agent(
@ -55,14 +61,14 @@ async def parallel():
agent_name="Writer 2", agent_name="Writer 2",
system_prompt="Generate a blog post in the style of Stephen King", system_prompt="Generate a blog post in the style of Stephen King",
llm=llm, llm=llm,
dashboard=False dashboard=False,
) )
reviewer = Agent( reviewer = Agent(
agent_name="Reviewer", agent_name="Reviewer",
system_prompt="Select the writer that wrote the best story. There can only be one best story.", system_prompt="Select the writer that wrote the best story. There can only be one best story.",
llm=llm, llm=llm,
dashboard=False dashboard=False,
) )
flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}" flow = f"{writer1.name}, {writer2.name} -> {reviewer.name}"
@ -71,13 +77,15 @@ async def parallel():
[writer1, writer2, reviewer], flow, verbose=False, logging=False [writer1, writer2, reviewer], flow, verbose=False, logging=False
) )
result = await agent_rearrange.astream("Generate a 1 sentence story about Michael Jordan.") result = await agent_rearrange.astream(
"Generate a 1 sentence story about Michael Jordan."
)
# LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;) # LEAVING THIS CALL BELOW FOR COMPARISON with "completion-style" .run() approach ;)
# result = agent_rearrange.run( # result = agent_rearrange.run(
# "Generate a short blog post about Michael Jordan." # "Generate a short blog post about Michael Jordan."
# ) # )
# asyncio.run(sequential()) # asyncio.run(sequential())
asyncio.run(parallel()) asyncio.run(parallel())

Loading…
Cancel
Save