Skip to content

Commit

Permalink
[WRAP UP]
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegomez committed Jan 5, 2025
1 parent f1f1133 commit 48140c5
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 1,011 deletions.
48 changes: 48 additions & 0 deletions csvagent_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Example usage
from pathlib import Path
from swarms.structs.csv_to_agent import AgentLoader, AgentValidationError


if __name__ == "__main__":
# Example agent configurations
agent_configs = [
{
"agent_name": "Financial-Analysis-Agent",
"system_prompt": "You are a financial expert...",
"model_name": "gpt-4o-mini", # Updated to correct model name
"max_loops": 1,
"autosave": True,
"dashboard": False,
"verbose": True,
"dynamic_temperature": True,
"saved_state_path": "finance_agent.json",
"user_name": "swarms_corp",
"retry_attempts": 3,
"context_length": 200000,
"return_step_meta": False,
"output_type": "string",
"streaming": False,
}
]

try:
# Initialize CSV manager
csv_manager = AgentLoader(Path("agents.csv"))

# Create CSV with initial agents
csv_manager.create_agent_csv(agent_configs)

# Load agents from CSV
agents = csv_manager.load_agents()

# Use an agent
if agents:
financial_agent = agents[0]
financial_agent.run(
"How can I establish a ROTH IRA to buy stocks and get a tax break?"
)

except AgentValidationError as e:
print(f"Validation error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
108 changes: 108 additions & 0 deletions run_all_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import os
import subprocess
import logging
import time
import psutil

# Configure logging
logging.basicConfig(
filename="test_runner.log",
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)


def run_tests_in_subfolders(
base_folders: list,
file_extension=".py",
python_interpreter="python",
):
report_file = "test_report.txt"

with open(report_file, "w") as report:
for base_folder in base_folders:
if not os.path.exists(base_folder):
logging.warning(
f"Base folder does not exist: {base_folder}"
)
continue

for root, dirs, files in os.walk(base_folder):
for file in files:
if file.endswith(file_extension):
file_path = os.path.join(root, file)
try:
logging.info(f"Running {file_path}...")

# Start time measurement
start_time = time.time()

# Get initial memory usage
process = psutil.Process(os.getpid())
initial_memory = (
process.memory_info().rss
) # Resident Set Size

result = subprocess.run(
[python_interpreter, file_path],
capture_output=True,
text=True,
)

# End time measurement
end_time = time.time()

# Get final memory usage
final_memory = process.memory_info().rss

# Calculate metrics
execution_time = end_time - start_time
memory_used = (
final_memory - initial_memory
)

report.write(f"Running {file_path}:\n")
report.write(result.stdout)
report.write(result.stderr)
report.write(
f"\nExecution Time: {execution_time:.2f} seconds\n"
)
report.write(
f"Memory Used: {memory_used / (1024 ** 2):.2f} MB\n"
) # Convert to MB
report.write("\n" + "-" * 40 + "\n")

logging.info(
f"Completed {file_path} with return code {result.returncode}"
)
logging.info(
f"Execution Time: {execution_time:.2f} seconds, Memory Used: {memory_used / (1024 ** 2):.2f} MB"
)

except FileNotFoundError:
logging.error(
f"File not found: {file_path}"
)
report.write(
f"File not found: {file_path}\n"
)
except Exception as e:
logging.error(
f"Error running {file_path}: {e}"
)
report.write(
f"Error running {file_path}: {e}\n"
)


# Example usage
base_folders = [
"folder1",
"folder2",
] # Replace with your actual folder names
file_extension = ".py" # Specify the file extension to run
python_interpreter = "python" # Specify the Python interpreter to use

run_tests_in_subfolders(
base_folders, file_extension, python_interpreter
)
226 changes: 0 additions & 226 deletions swarm_cloud_api/api.py

This file was deleted.

10 changes: 0 additions & 10 deletions swarm_cloud_api/requirements.txt

This file was deleted.

Loading

0 comments on commit 48140c5

Please sign in to comment.