parent
869ee3ae87
commit
d01d24e9c0
@ -0,0 +1,43 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from swarms_memory import ChromaDB
|
||||||
|
|
||||||
|
from swarms import Agent, Anthropic
|
||||||
|
from swarms.prompts.finance_agent_sys_prompt import (
|
||||||
|
FINANCIAL_AGENT_SYS_PROMPT,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Initilaize the chromadb client
|
||||||
|
chromadb = ChromaDB(
|
||||||
|
metric="cosine",
|
||||||
|
output_dir="fiance_agent_rag",
|
||||||
|
# docs_folder="artifacts", # Folder of your documents
|
||||||
|
)
|
||||||
|
|
||||||
|
# Model
|
||||||
|
model = Anthropic(anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"))
|
||||||
|
|
||||||
|
|
||||||
|
# Initialize the agent
|
||||||
|
agent = Agent(
|
||||||
|
agent_name="Financial-Analysis-Agent",
|
||||||
|
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
|
||||||
|
agent_description="Agent creates ",
|
||||||
|
llm=model,
|
||||||
|
max_loops="auto",
|
||||||
|
autosave=True,
|
||||||
|
dashboard=False,
|
||||||
|
verbose=True,
|
||||||
|
streaming_on=True,
|
||||||
|
dynamic_temperature_enabled=True,
|
||||||
|
saved_state_path="finance_agent.json",
|
||||||
|
user_name="swarms_corp",
|
||||||
|
retry_attempts=3,
|
||||||
|
context_length=200000,
|
||||||
|
long_term_memory=chromadb,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
agent.run(
|
||||||
|
"What are the components of a startups stock incentive equity plan"
|
||||||
|
)
|
@ -0,0 +1,116 @@
|
|||||||
|
from swarms import Agent, OpenAIChat
|
||||||
|
from swarms_memory import ChromaDB
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Making an instance of the ChromaDB class
|
||||||
|
memory = ChromaDB(
|
||||||
|
metric="cosine",
|
||||||
|
n_results=3,
|
||||||
|
output_dir="results",
|
||||||
|
docs_folder="docs",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Model
|
||||||
|
model = OpenAIChat(
|
||||||
|
api_key=os.getenv("OPENAI_API_KEY"),
|
||||||
|
model_name="gpt-4o-mini",
|
||||||
|
temperature=0.1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Tools in swarms are simple python functions and docstrings
|
||||||
|
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."
|
||||||
|
|
||||||
|
|
||||||
|
# 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=model,
|
||||||
|
max_loops="auto",
|
||||||
|
autosave=True,
|
||||||
|
dashboard=False,
|
||||||
|
streaming_on=True,
|
||||||
|
verbose=True,
|
||||||
|
stopping_token="<DONE>",
|
||||||
|
interactive=True,
|
||||||
|
tools=[terminal, browser, file_editor, create_file],
|
||||||
|
streaming=True,
|
||||||
|
long_term_memory=memory,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the agent
|
||||||
|
out = agent(
|
||||||
|
"Create a CSV file with the latest tax rates for C corporations in the following ten states and the District of Columbia: Alabama, California, Florida, Georgia, Illinois, New York, North Carolina, Ohio, Texas, and Washington."
|
||||||
|
)
|
||||||
|
print(out)
|
Before Width: | Height: | Size: 532 KiB After Width: | Height: | Size: 532 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue