-
-
Notifications
You must be signed in to change notification settings - Fork 516
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
committed
Apr 24, 2024
1 parent
01bfc71
commit 8f91a7d
Showing
11 changed files
with
822 additions
and
40 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 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,134 @@ | ||
from swarms import Agent, Anthropic, tool, ChromaDB | ||
import subprocess | ||
from pydantic import BaseModel | ||
|
||
|
||
# Initilaize the chromadb client | ||
chromadb = ChromaDB( | ||
metric="cosine", | ||
output="results", | ||
docs_folder="docs", | ||
) | ||
|
||
|
||
# Create a schema for the code revision tool | ||
class CodeRevisionSchema(BaseModel): | ||
code: str = None | ||
revision: str = None | ||
|
||
|
||
# iNitialize the schema | ||
tool_schema = CodeRevisionSchema( | ||
code="print('Hello, World!')", | ||
revision="print('What is 2+2')", | ||
) | ||
|
||
|
||
# Model | ||
llm = Anthropic( | ||
temperature=0.1, | ||
) | ||
|
||
|
||
# Tools | ||
@tool | ||
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) | ||
|
||
|
||
@tool | ||
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." | ||
|
||
|
||
@tool | ||
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." | ||
|
||
|
||
@tool | ||
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." | ||
|
||
|
||
# Agent | ||
agent = Agent( | ||
agent_name="Devin", | ||
system_prompt=( | ||
"Autonomous agent that can interact with humans and other" | ||
" agents. Be Helpful and Kind. Use the tools provided to" | ||
" assist the user. Return all code in markdown format." | ||
), | ||
llm=llm, | ||
max_loops="auto", | ||
autosave=True, | ||
dashboard=False, | ||
streaming_on=True, | ||
verbose=True, | ||
stopping_token="<DONE>", | ||
interactive=True, | ||
tools=[terminal, browser, file_editor, create_file], | ||
long_term_memory=chromadb, | ||
output_type=tool_schema, # or dict, or str | ||
metadata_output_type="json", | ||
# List of schemas that the agent can handle | ||
list_tool_schemas=[tool_schema], | ||
function_calling_format_type="OpenAI", | ||
function_calling_type="json", # or soon yaml | ||
) | ||
|
||
# Run the agent | ||
out = agent.run("Create a new file for a plan to take over the world.") | ||
print(out) |
File renamed without changes.
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
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.