-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
185 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from swarms.models.openai_chat import OpenAIChat | ||
|
||
model = OpenAIChat() | ||
|
||
out = model("Hello, how are you?") | ||
|
||
print(out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.