-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from kyegomez/668
668
- Loading branch information
Showing
63 changed files
with
4,702 additions
and
1,362 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
|
||
# ================================== | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.11-slim | ||
|
||
|
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,112 @@ | ||
import requests | ||
import json | ||
from time import sleep | ||
|
||
BASE_URL = "http://api.swarms.ai:8000" | ||
|
||
|
||
def make_request(method, endpoint, data=None): | ||
"""Helper function to make requests with error handling""" | ||
url = f"{BASE_URL}{endpoint}" | ||
try: | ||
if method == "GET": | ||
response = requests.get(url) | ||
elif method == "POST": | ||
response = requests.post(url, json=data) | ||
elif method == "DELETE": | ||
response = requests.delete(url) | ||
|
||
response.raise_for_status() | ||
return response.json() | ||
except requests.exceptions.RequestException as e: | ||
print( | ||
f"Error making {method} request to {endpoint}: {str(e)}" | ||
) | ||
if hasattr(e.response, "text"): | ||
print(f"Response text: {e.response.text}") | ||
return None | ||
|
||
|
||
def create_agent(): | ||
"""Create a test agent""" | ||
data = { | ||
"agent_name": "test_agent", | ||
"model_name": "gpt-4", | ||
"system_prompt": "You are a helpful assistant", | ||
"description": "Test agent", | ||
"temperature": 0.7, | ||
"max_loops": 1, | ||
"tags": ["test"], | ||
} | ||
return make_request("POST", "/v1/agent", data) | ||
|
||
|
||
def list_agents(): | ||
"""List all agents""" | ||
return make_request("GET", "/v1/agents") | ||
|
||
|
||
def test_completion(agent_id): | ||
"""Test a completion with the agent""" | ||
data = { | ||
"prompt": "Say hello!", | ||
"agent_id": agent_id, | ||
"max_tokens": 100, | ||
} | ||
return make_request("POST", "/v1/agent/completions", data) | ||
|
||
|
||
def get_agent_metrics(agent_id): | ||
"""Get metrics for an agent""" | ||
return make_request("GET", f"/v1/agent/{agent_id}/metrics") | ||
|
||
|
||
def delete_agent(agent_id): | ||
"""Delete an agent""" | ||
return make_request("DELETE", f"/v1/agent/{agent_id}") | ||
|
||
|
||
def run_tests(): | ||
print("Starting API tests...") | ||
|
||
# Create an agent | ||
print("\n1. Creating agent...") | ||
agent_response = create_agent() | ||
if not agent_response: | ||
print("Failed to create agent") | ||
return | ||
|
||
agent_id = agent_response.get("agent_id") | ||
print(f"Created agent with ID: {agent_id}") | ||
|
||
# Give the server a moment to process | ||
sleep(2) | ||
|
||
# List agents | ||
print("\n2. Listing agents...") | ||
agents = list_agents() | ||
print(f"Found {len(agents)} agents") | ||
|
||
# Test completion | ||
if agent_id: | ||
print("\n3. Testing completion...") | ||
completion = test_completion(agent_id) | ||
if completion: | ||
print( | ||
f"Completion response: {completion.get('response')}" | ||
) | ||
|
||
print("\n4. Getting agent metrics...") | ||
metrics = get_agent_metrics(agent_id) | ||
if metrics: | ||
print(f"Agent metrics: {json.dumps(metrics, indent=2)}") | ||
|
||
# Clean up | ||
# print("\n5. Cleaning up - deleting agent...") | ||
# delete_result = delete_agent(agent_id) | ||
# if delete_result: | ||
# print("Successfully deleted agent") | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
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 |
---|---|---|
@@ -1,50 +1,31 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from swarm_models import OpenAIChat | ||
|
||
from swarms import Agent | ||
from swarms.prompts.finance_agent_sys_prompt import ( | ||
FINANCIAL_AGENT_SYS_PROMPT, | ||
) | ||
|
||
load_dotenv() | ||
|
||
# Get the OpenAI API key from the environment variable | ||
api_key = os.getenv("OPENAI_API_KEY") | ||
|
||
# Create an instance of the OpenAIChat class | ||
model = OpenAIChat( | ||
openai_api_key=api_key, model_name="gpt-4o-mini", temperature=0.1 | ||
) | ||
|
||
# Initialize the agent | ||
agent = Agent( | ||
agent_name="Financial-Analysis-Agent", | ||
system_prompt=FINANCIAL_AGENT_SYS_PROMPT, | ||
llm=model, | ||
max_loops=1, | ||
autosave=True, | ||
dashboard=False, | ||
verbose=True, | ||
agent_description="Personal finance advisor agent", | ||
system_prompt=FINANCIAL_AGENT_SYS_PROMPT | ||
+ "Output the <DONE> token when you're done creating a portfolio of etfs, index, funds, and more for AI", | ||
model_name="gpt-4o", # Use any model from litellm | ||
max_loops="auto", | ||
dynamic_temperature_enabled=True, | ||
saved_state_path="finance_agent.json", | ||
user_name="swarms_corp", | ||
retry_attempts=1, | ||
user_name="Kye", | ||
retry_attempts=3, | ||
streaming_on=True, | ||
context_length=200000, | ||
return_step_meta=True, | ||
output_type="json", # "json", "dict", "csv" OR "string" soon "yaml" and | ||
context_length=16000, | ||
return_step_meta=False, | ||
output_type="str", # "json", "dict", "csv" OR "string" "yaml" and | ||
auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task | ||
artifacts_on=True, | ||
artifacts_output_path="roth_ira_report", | ||
artifacts_file_extension=".txt", | ||
max_tokens=8000, | ||
return_history=True, | ||
max_tokens=16000, # max output tokens | ||
interactive=True, | ||
stopping_token="<DONE>", | ||
execute_tool=True, | ||
) | ||
|
||
|
||
agent.run( | ||
"How can I establish a ROTH IRA to buy stocks and get a tax break? What are the criteria. Create a report on this question.", | ||
"Create a table of super high growth opportunities for AI. I have $40k to invest in ETFs, index funds, and more. Please create a table in markdown.", | ||
all_cores=True, | ||
) |
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.