@ -1,49 +0,0 @@
|
||||
from swarms import OpenAI, Flow
|
||||
from swarms.swarms.groupchat import GroupChatManager, GroupChat
|
||||
|
||||
|
||||
api_key = ""
|
||||
|
||||
llm = OpenAI(
|
||||
openai_api_key=api_key,
|
||||
temperature=0.5,
|
||||
max_tokens=3000,
|
||||
)
|
||||
|
||||
# Initialize the flow
|
||||
flow1 = Flow(
|
||||
llm=llm,
|
||||
max_loops=1,
|
||||
system_prompt="YOU ARE SILLY, YOU OFFER NOTHING OF VALUE",
|
||||
name="silly",
|
||||
dashboard=True,
|
||||
)
|
||||
flow2 = Flow(
|
||||
llm=llm,
|
||||
max_loops=1,
|
||||
system_prompt="YOU ARE VERY SMART AND ANSWER RIDDLES",
|
||||
name="detective",
|
||||
dashboard=True,
|
||||
)
|
||||
flow3 = Flow(
|
||||
llm=llm,
|
||||
max_loops=1,
|
||||
system_prompt="YOU MAKE RIDDLES",
|
||||
name="riddler",
|
||||
dashboard=True,
|
||||
)
|
||||
manager = Flow(
|
||||
llm=llm,
|
||||
max_loops=1,
|
||||
system_prompt="YOU ARE A GROUP CHAT MANAGER",
|
||||
name="manager",
|
||||
dashboard=True,
|
||||
)
|
||||
|
||||
|
||||
# Example usage:
|
||||
agents = [flow1, flow2, flow3]
|
||||
|
||||
group_chat = GroupChat(agents=agents, messages=[], max_round=10)
|
||||
chat_manager = GroupChatManager(groupchat=group_chat, selector=manager)
|
||||
chat_history = chat_manager("Write me a riddle")
|
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 3.0 MiB |
@ -1,5 +0,0 @@
|
||||
from swarms.models.openai_chat import ChatOpenAI
|
||||
|
||||
model = ChatOpenAI()
|
||||
|
||||
print(model("Hello, my name is", 5))
|
@ -0,0 +1,7 @@
|
||||
from swarms.models.openai_chat import OpenAIChat
|
||||
|
||||
model = OpenAIChat()
|
||||
|
||||
out = model("Hello, how are you?")
|
||||
|
||||
print(out)
|
@ -0,0 +1,62 @@
|
||||
from swarms.models import Anthropic
|
||||
from swarms.structs import Flow
|
||||
from swarms.tools.tool import tool
|
||||
|
||||
import asyncio
|
||||
|
||||
|
||||
llm = Anthropic(
|
||||
anthropic_api_key="",
|
||||
)
|
||||
|
||||
|
||||
async def async_load_playwright(url: str) -> str:
|
||||
"""Load the specified URLs using Playwright and parse using BeautifulSoup."""
|
||||
from bs4 import BeautifulSoup
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
results = ""
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
try:
|
||||
page = await browser.new_page()
|
||||
await page.goto(url)
|
||||
|
||||
page_source = await page.content()
|
||||
soup = BeautifulSoup(page_source, "html.parser")
|
||||
|
||||
for script in soup(["script", "style"]):
|
||||
script.extract()
|
||||
|
||||
text = soup.get_text()
|
||||
lines = (line.strip() for line in text.splitlines())
|
||||
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
||||
results = "\n".join(chunk for chunk in chunks if chunk)
|
||||
except Exception as e:
|
||||
results = f"Error: {e}"
|
||||
await browser.close()
|
||||
return results
|
||||
|
||||
|
||||
def run_async(coro):
|
||||
event_loop = asyncio.get_event_loop()
|
||||
return event_loop.run_until_complete(coro)
|
||||
|
||||
|
||||
@tool
|
||||
def browse_web_page(url: str) -> str:
|
||||
"""Verbose way to scrape a whole webpage. Likely to cause issues parsing."""
|
||||
return run_async(async_load_playwright(url))
|
||||
|
||||
|
||||
## Initialize the workflow
|
||||
flow = Flow(
|
||||
llm=llm,
|
||||
max_loops=5,
|
||||
tools=[browse_web_page],
|
||||
dashboard=True,
|
||||
)
|
||||
|
||||
out = flow.run(
|
||||
"Generate a 10,000 word blog on mental clarity and the benefits of meditation."
|
||||
)
|