-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Kye Gomez
authored and
Kye Gomez
committed
Jun 18, 2024
1 parent
f229f91
commit 7d2520c
Showing
7 changed files
with
259 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import threading | ||
from swarms.agents.multion_wrapper import MultiOnAgent | ||
|
||
def run_model(api_key): | ||
model = MultiOnAgent(api_key=api_key, max_steps=500, url="https://x.com") | ||
out = model.run( | ||
""" | ||
click on the 'Tweet' button to start a new tweet and post it saying: $pip3 install swarms | ||
""" | ||
) | ||
print(out) | ||
|
||
# Create a list to store the threads | ||
threads = [] | ||
|
||
# Run 100 instances using multithreading | ||
for _ in range(10): | ||
api_key = os.getenv("MULTION_API_KEY") | ||
thread = threading.Thread(target=run_model, args=(api_key,)) | ||
thread.start() | ||
threads.append(thread) | ||
|
||
# Wait for all threads to finish | ||
for thread in threads: | ||
thread.join() |
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,72 @@ | ||
|
||
from swarms import Agent, AgentRearrange, OpenAIChat | ||
from swarms.agents.multion_wrapper import MultiOnAgent | ||
|
||
model = MultiOnAgent( | ||
url="https://tesla.com", | ||
) | ||
|
||
|
||
llm = OpenAIChat() | ||
|
||
|
||
def browser_automation(task: str): | ||
""" | ||
Run a task on the browser automation agent. | ||
Args: | ||
task (str): The task to be executed on the browser automation agent. | ||
""" | ||
out = model.run(task) | ||
return out | ||
|
||
|
||
# Purpose = To detect email spam using three different agents | ||
agent1 = Agent( | ||
agent_name="CyberTruckBuyer1", | ||
system_prompt="Find the best deal on a Cyber Truck and provide your reasoning", | ||
llm=llm, | ||
max_loops=1, | ||
# output_type=str, | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
tools=[browser_automation], | ||
) | ||
|
||
agent2 = Agent( | ||
agent_name="CyberTruckBuyer2", | ||
system_prompt="Find the best deal on a Cyber Truck and provide your reasoning", | ||
llm=llm, | ||
max_loops=1, | ||
# output_type=str, | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
tools=[browser_automation], | ||
) | ||
|
||
agent3 = Agent( | ||
agent_name="CyberTruckBuyer3", | ||
system_prompt="Find the best deal on a Cyber Truck and provide your reasoning", | ||
llm=llm, | ||
max_loops=1, | ||
# output_type=str, | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
tools=[browser_automation], | ||
) | ||
|
||
swarm = AgentRearrange( | ||
flow="CyberTruckBuyer1 -> CyberTruckBuyer2 -> CyberTruckBuyer3", | ||
agents=[agent1, agent2, agent3], | ||
logging_enabled=True, | ||
max_loops=1, | ||
) | ||
|
||
# Run all the agents | ||
swarm.run("Let's buy a cyber truck") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
|
||
from swarms import OpenAIChat, Agent, AgentRearrange | ||
|
||
# Purpose = To detect email spam using three different agents | ||
agent1 = Agent( | ||
agent_name="SpamDetector1", | ||
system_prompt="Detect if the email is spam or not, and provide your reasoning", | ||
llm=OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")), | ||
max_loops=1, | ||
output_type=str, | ||
# tools=[], | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
) | ||
|
||
agent2 = Agent( | ||
agent_name="SpamDetector2", | ||
system_prompt="Detect if the email is spam or not, and provide your reasoning", | ||
llm=OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")), | ||
max_loops=1, | ||
output_type=str, | ||
# tools=[], | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
) | ||
|
||
agent3 = Agent( | ||
agent_name="SpamDetector3", | ||
system_prompt="Detect if the email is spam or not, and provide your reasoning", | ||
llm=OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")), | ||
max_loops=1, | ||
output_type=str, | ||
# tools=[], | ||
metadata="json", | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", | ||
streaming_on=True, | ||
) | ||
|
||
swarm = AgentRearrange( | ||
flow="SpamDetector1 -> SpamDetector2 -> SpamDetector3", | ||
agents=[agent1, agent2, agent3], | ||
logging_enabled=True, | ||
max_loops=1, | ||
) | ||
|
||
# Run all the agents | ||
swarm.run("Find YSL bag with the biggest discount") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# pip3 install multion | ||
# pip3 install swarms | ||
from multion.client import MultiOn | ||
import os | ||
from swarms.models.base_llm import BaseLLM | ||
|
||
|
||
def check_multion_api_key(): | ||
""" | ||
Checks if the MultiOn API key is available in the environment variables. | ||
Returns: | ||
str: The MultiOn API key. | ||
""" | ||
api_key = os.getenv("MULTION_API_KEY") | ||
return api_key | ||
|
||
|
||
class MultiOnAgent(BaseLLM): | ||
""" | ||
Represents an agent that interacts with the MultiOn API to run tasks on a remote session. | ||
Args: | ||
api_key (str): The API key for accessing the MultiOn API. | ||
url (str): The URL of the remote session. | ||
*args: Variable length argument list. | ||
**kwargs: Arbitrary keyword arguments. | ||
Attributes: | ||
client (MultiOn): The MultiOn client instance. | ||
url (str): The URL of the remote session. | ||
session_id (str): The ID of the current session. | ||
Methods: | ||
run: Runs a task on the remote session. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
name: str = None, | ||
system_prompt: str = None, | ||
api_key: str = check_multion_api_key, | ||
url: str = "https://huggingface.co/papers", | ||
max_steps: int = 1, | ||
*args, | ||
**kwargs, | ||
): | ||
super().__init__(*args, **kwargs) | ||
self.name = name | ||
self.client = MultiOn(api_key=api_key) | ||
self.url = url | ||
self.system_prompt = system_prompt | ||
self.max_steps = max_steps | ||
|
||
def run(self, task: str, *args, **kwargs): | ||
""" | ||
Runs a task on the remote session. | ||
Args: | ||
task (str): The task to be executed on the remote session. | ||
*args: Variable length argument list. | ||
**kwargs: Arbitrary keyword arguments. | ||
""" | ||
response = self.client.browse( | ||
cmd=task, | ||
url=self.url, | ||
local=True, | ||
max_steps=self.max_steps, | ||
) | ||
|
||
# response = response.json() | ||
|
||
# print(response.message) | ||
return str(response.message) | ||
|