You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.9 KiB
83 lines
1.9 KiB
from swarms.prompts.prompt import Prompt
|
|
import subprocess
|
|
|
|
|
|
# Tools
|
|
def terminal(
|
|
code: str,
|
|
):
|
|
"""
|
|
Run code in the terminal.
|
|
|
|
Args:
|
|
code (str): The code to run in the terminal.
|
|
|
|
Returns:
|
|
str: The output of the code.
|
|
"""
|
|
out = subprocess.run(
|
|
code, shell=True, capture_output=True, text=True
|
|
).stdout
|
|
return str(out)
|
|
|
|
|
|
def browser(query: str):
|
|
"""
|
|
Search the query in the browser with the `browser` tool.
|
|
|
|
Args:
|
|
query (str): The query to search in the browser.
|
|
|
|
Returns:
|
|
str: The search results.
|
|
"""
|
|
import webbrowser
|
|
|
|
url = f"https://www.google.com/search?q={query}"
|
|
webbrowser.open(url)
|
|
return f"Searching for {query} in the browser."
|
|
|
|
|
|
def create_file(file_path: str, content: str):
|
|
"""
|
|
Create a file using the file editor tool.
|
|
|
|
Args:
|
|
file_path (str): The path to the file.
|
|
content (str): The content to write to the file.
|
|
|
|
Returns:
|
|
str: The result of the file creation operation.
|
|
"""
|
|
with open(file_path, "w") as file:
|
|
file.write(content)
|
|
return f"File {file_path} created successfully."
|
|
|
|
|
|
def file_editor(file_path: str, mode: str, content: str):
|
|
"""
|
|
Edit a file using the file editor tool.
|
|
|
|
Args:
|
|
file_path (str): The path to the file.
|
|
mode (str): The mode to open the file in.
|
|
content (str): The content to write to the file.
|
|
|
|
Returns:
|
|
str: The result of the file editing operation.
|
|
"""
|
|
with open(file_path, mode) as file:
|
|
file.write(content)
|
|
return f"File {file_path} edited successfully."
|
|
|
|
|
|
prompt = Prompt(
|
|
content="This is my first prompt!",
|
|
name="My First Prompt",
|
|
description="A simple example prompt.",
|
|
# tools=[file_editor, create_file, terminal]
|
|
)
|
|
|
|
prompt.add_tools(tools=[file_editor, create_file, terminal])
|
|
print(prompt.content)
|