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.
84 lines
2.2 KiB
84 lines
2.2 KiB
import os
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
import json
|
|
|
|
load_dotenv()
|
|
|
|
API_KEY = os.getenv("SWARMS_API_KEY")
|
|
BASE_URL = "https://swarms-api-285321057562.us-east1.run.app"
|
|
|
|
headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
|
|
|
|
|
|
def run_health_check():
|
|
response = requests.get(f"{BASE_URL}/health", headers=headers)
|
|
return response.json()
|
|
|
|
|
|
def run_single_swarm():
|
|
payload = {
|
|
"name": "Financial Analysis Swarm",
|
|
"description": "Market analysis swarm",
|
|
"agents": [
|
|
{
|
|
"agent_name": "Market Analyst",
|
|
"description": "Analyzes market trends",
|
|
"system_prompt": "You are a financial analyst expert.",
|
|
"model_name": "gpt-4o",
|
|
"role": "worker",
|
|
"max_loops": 1,
|
|
},
|
|
{
|
|
"agent_name": "Economic Forecaster",
|
|
"description": "Predicts economic trends",
|
|
"system_prompt": "You are an expert in economic forecasting.",
|
|
"model_name": "gpt-4o",
|
|
"role": "worker",
|
|
"max_loops": 1,
|
|
},
|
|
{
|
|
"agent_name": "Data Scientist",
|
|
"description": "Performs data analysis",
|
|
"system_prompt": "You are a data science expert.",
|
|
"model_name": "gpt-4o",
|
|
"role": "worker",
|
|
"max_loops": 1,
|
|
},
|
|
],
|
|
"max_loops": 1,
|
|
"swarm_type": "ConcurrentWorkflow",
|
|
"task": "Analyze current market trends in tech sector",
|
|
"output_type": "str",
|
|
"return_history": True,
|
|
}
|
|
|
|
response = requests.post(
|
|
f"{BASE_URL}/v1/swarm/completions",
|
|
headers=headers,
|
|
json=payload,
|
|
)
|
|
|
|
# return response.json()
|
|
output = response.json()
|
|
|
|
return json.dumps(output, indent=4)
|
|
|
|
|
|
def get_logs():
|
|
response = requests.get(
|
|
f"{BASE_URL}/v1/swarm/logs", headers=headers
|
|
)
|
|
output = response.json()
|
|
return json.dumps(output, indent=4)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
result = run_single_swarm()
|
|
print("Swarm Result:")
|
|
print(result)
|
|
|
|
# print("Swarm Logs:")
|
|
# logs = get_logs()
|
|
# print(logs)
|