From f88f4fab13903d13ebb65fd13939fc76b646fb15 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Tue, 22 Jul 2025 21:15:58 -0700 Subject: [PATCH] [CLEANUP][Tests] [DOCS][Contributors Guide] [SCRIPTS][setup.sh] [cleanup un-used files --- .github/workflows/code-quality-and-tests.yml | 73 ++ docs/contributors/environment_setup.md | 692 ++++++++++++++++++ docs/swarms/structs/base_workflow.md | 287 -------- .../utils => examples/models}/vllm_wrapper.py | 13 +- .../council/council_judge_evaluation.py | 3 +- pyproject.toml | 6 + requirements.txt | 8 +- scripts/setup.sh | 155 ++++ scripts/test_rename_recursive.py | 120 +++ swarms/structs/__init__.py | 2 - swarms/structs/base_workflow.py | 343 --------- swarms/tools/func_calling_utils.py | 6 +- tests/Dockerfile | 33 - tests/README.md | 79 -- ...chmark.py => test_agent_exec_benchmark.py} | 0 ...to_test_eval.py => test_auto_test_eval.py} | 0 ...nchmark_init.py => test_benchmark_init.py} | 0 ...ent.py => test_github_summarizer_agent.py} | 0 ...iling_agent.py => test_profiling_agent.py} | 0 ...ive_test.py => test_comprehensive_test.py} | 0 .../{acompletions.py => test_acompletions.py} | 0 21 files changed, 1062 insertions(+), 758 deletions(-) create mode 100644 .github/workflows/code-quality-and-tests.yml create mode 100644 docs/contributors/environment_setup.md delete mode 100644 docs/swarms/structs/base_workflow.md rename {swarms/utils => examples/models}/vllm_wrapper.py (92%) create mode 100644 scripts/setup.sh create mode 100644 scripts/test_rename_recursive.py delete mode 100644 swarms/structs/base_workflow.py delete mode 100644 tests/Dockerfile delete mode 100644 tests/README.md rename tests/benchmark_agent/{agent_exec_benchmark.py => test_agent_exec_benchmark.py} (100%) rename tests/benchmark_agent/{agent_evals/auto_test_eval.py => test_auto_test_eval.py} (100%) rename tests/benchmark_agent/{benchmark_init.py => test_benchmark_init.py} (100%) rename tests/benchmark_agent/{agent_evals/github_summarizer_agent.py => test_github_summarizer_agent.py} (100%) rename tests/benchmark_agent/{profiling_agent.py => test_profiling_agent.py} (100%) rename tests/{comprehensive_test.py => test_comprehensive_test.py} (100%) rename tests/utils/{acompletions.py => test_acompletions.py} (100%) diff --git a/.github/workflows/code-quality-and-tests.yml b/.github/workflows/code-quality-and-tests.yml new file mode 100644 index 00000000..a6fec774 --- /dev/null +++ b/.github/workflows/code-quality-and-tests.yml @@ -0,0 +1,73 @@ +name: Code Quality and Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + code-quality-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + # Step 1: Check out the repository + - name: Checkout repository + uses: actions/checkout@v4 + + # Step 2: Set up Python + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + # Step 3: Install Poetry for dependency management + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + + # Step 4: Cache dependencies to speed up subsequent runs + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + # Step 5: Install dependencies including dev dependencies + - name: Install dependencies + run: poetry install --no-interaction --with dev --all-extras + + # Step 7: Run Black formatting check on swarms folder + - name: Check Black formatting on swarms folder + run: | + poetry run black swarms/ --check --diff + + # Step 8: Run Ruff linting on swarms folder + - name: Run Ruff linting on swarms folder + run: | + poetry run ruff check swarms/ + + # Step 10: Run tests with API keys + - name: Run tests + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + run: | + poetry run pytest tests/ -v --tb=short + + # Step 11: Upload test results as artifacts (optional) + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.python-version }} + path: | + tests/ + .coverage + retention-days: 7 \ No newline at end of file diff --git a/docs/contributors/environment_setup.md b/docs/contributors/environment_setup.md new file mode 100644 index 00000000..18d0d48f --- /dev/null +++ b/docs/contributors/environment_setup.md @@ -0,0 +1,692 @@ +# Environment Setup Guide for Swarms Contributors + +Welcome to the Swarms development environment setup guide! This comprehensive guide will walk you through setting up your development environment from scratch, whether you're a first-time contributor or an experienced developer. + +!!! success "🚀 One-Click Setup (Recommended)" + **New!** Use our automated setup script that handles everything: + ```bash + git clone https://github.com/kyegomez/swarms.git + cd swarms + chmod +x scripts/setup.sh + ./scripts/setup.sh + ``` + This script automatically installs Poetry, creates a virtual environment, installs all dependencies, sets up pre-commit hooks, and more! + +!!! info "Manual Setup" + **Alternative**: For manual control, install Python 3.10+, Git, and Poetry, then run: + ```bash + git clone https://github.com/kyegomez/swarms.git + cd swarms + poetry install --with dev + ``` + +--- + +## :material-list-status: Prerequisites + +Before setting up your development environment, ensure you have the following installed: + +### System Requirements + +| Tool | Version | Purpose | +|------|---------|---------| +| **Python** | 3.10+ | Core runtime | +| **Git** | 2.30+ | Version control | +| **Poetry** | 1.4+ | Dependency management (recommended) | +| **Node.js** | 16+ | Documentation tools (optional) | + +### Operating System Support + +=== "macOS" + + ```bash + # Install Homebrew if not already installed + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # Install prerequisites + brew install python@3.10 git poetry node + ``` + +=== "Ubuntu/Debian" + + ```bash + # Update package list + sudo apt update + + # Install Python 3.10 and pip + sudo apt install python3.10 python3.10-venv python3-pip git curl + + # Install Poetry + curl -sSL https://install.python-poetry.org | python3 - + + # Add Poetry to PATH + export PATH="$HOME/.local/bin:$PATH" + echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc + ``` + +=== "Windows" + + 1. **Install Python 3.10+** from [python.org](https://python.org/downloads/) + 2. **Install Git** from [git-scm.com](https://git-scm.com/download/win) + 3. **Install Poetry** using PowerShell: + ```powershell + (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - + ``` + +--- + +## :material-auto-fix: Automated Setup (Recommended) + +We provide a comprehensive setup script that automates the entire development environment setup process. This is the **recommended approach** for new contributors. + +### What the Setup Script Does + +The `scripts/setup.sh` script automatically handles: + +- ✅ **Python Version Check**: Verifies Python 3.10+ is installed +- ✅ **Poetry Installation**: Installs Poetry if not present +- ✅ **Virtual Environment**: Creates and configures a project-specific virtual environment +- ✅ **Dependencies**: Installs all main, development, lint, and test dependencies +- ✅ **Pre-commit Hooks**: Sets up and installs pre-commit hooks for code quality +- ✅ **Environment Template**: Creates a `.env` file template with common variables +- ✅ **Verification**: Runs initial setup verification checks +- ✅ **Helpful Output**: Provides colored output and next steps + +### Running the Automated Setup + +```bash +# Clone the repository +git clone https://github.com/kyegomez/swarms.git +cd swarms + +# Make the script executable and run it +chmod +x scripts/setup.sh +./scripts/setup.sh +``` + +### Script Features + +=== "🎯 Smart Detection" + The script intelligently detects your system state: + - Checks if Poetry is already installed + - Verifies Python version compatibility + - Detects existing virtual environments + - Checks for Git repository status + +=== "🔧 Comprehensive Setup" + Installs everything you need: + ```bash + # All dependency groups + poetry install --with dev,lint,test + + # Pre-commit hooks + pre-commit install + pre-commit install --hook-type commit-msg + + # Initial verification run + pre-commit run --all-files + ``` + +=== "📋 Environment Template" + Creates a starter `.env` file: + ```bash + # Generated .env template + OPENAI_API_KEY=your_openai_api_key_here + ANTHROPIC_API_KEY=your_anthropic_key_here + LOG_LEVEL=INFO + DEVELOPMENT=true + ``` + +=== "💡 Helpful Guidance" + Provides next steps and useful commands: + - How to activate the virtual environment + - Essential Poetry commands + - Testing and development workflow + - Troubleshooting tips + +### When to Use Manual Setup + +Use the manual setup approach if you: +- Want full control over each step +- Have specific system requirements +- Are troubleshooting installation issues +- Prefer to understand each component + +--- + +## :material-git: Repository Setup + +### Step 1: Fork and Clone + +1. **Fork the repository** on GitHub: [github.com/kyegomez/swarms](https://github.com/kyegomez/swarms) + +2. **Clone your fork**: +```bash +git clone https://github.com/YOUR_USERNAME/swarms.git +cd swarms +``` + +3. **Add upstream remote**: +```bash +git remote add upstream https://github.com/kyegomez/swarms.git +``` + +4. **Verify remotes**: +```bash +git remote -v +# origin https://github.com/YOUR_USERNAME/swarms.git (fetch) +# origin https://github.com/YOUR_USERNAME/swarms.git (push) +# upstream https://github.com/kyegomez/swarms.git (fetch) +# upstream https://github.com/kyegomez/swarms.git (push) +``` + +--- + +## :material-package-variant: Dependency Management + +Choose your preferred method for managing dependencies: + +=== "Poetry (Recommended)" + + Poetry provides superior dependency resolution and virtual environment management. + + ### Installation + + ```bash + # Navigate to project directory + cd swarms + + # Install all dependencies including development tools + poetry install --with dev,lint,test + + # Activate the virtual environment + poetry shell + ``` + + ### Useful Poetry Commands + + ```bash + # Add a new dependency + poetry add package_name + + # Add a development dependency + poetry add --group dev package_name + + # Update dependencies + poetry update + + # Show dependency tree + poetry show --tree + + # Run commands in the virtual environment + poetry run python your_script.py + ``` + +=== "pip + venv" + + Traditional pip-based setup with virtual environments. + + ### Installation + + ```bash + # Navigate to project directory + cd swarms + + # Create virtual environment + python -m venv venv + + # Activate virtual environment + # On macOS/Linux: + source venv/bin/activate + # On Windows: + venv\Scripts\activate + + # Upgrade pip + pip install --upgrade pip + + # Install core dependencies + pip install -r requirements.txt + + # Install documentation dependencies (optional) + pip install -r docs/requirements.txt + ``` + +--- + +## :material-tools: Development Tools Setup + +### Code Quality Tools + +Swarms uses several tools to maintain code quality: + +=== "Formatting" + + **Black** - Code formatter + ```bash + # Format code + poetry run black swarms/ + # or with pip: + black swarms/ + + # Check formatting without making changes + black swarms/ --check --diff + ``` + +=== "Linting" + + **Ruff** - Fast Python linter + ```bash + # Run linter + poetry run ruff check swarms/ + # or with pip: + ruff check swarms/ + + # Auto-fix issues + ruff check swarms/ --fix + ``` + +=== "Type Checking" + + **MyPy** - Static type checker + ```bash + # Run type checking + poetry run mypy swarms/ + # or with pip: + mypy swarms/ + ``` + +### Pre-commit Hooks (Optional but Recommended) + +Set up pre-commit hooks to automatically run quality checks: + +```bash +# Install pre-commit +poetry add --group dev pre-commit +# or with pip: +pip install pre-commit + +# Install git hooks +pre-commit install + +# Run on all files +pre-commit run --all-files +``` + +The project uses the latest ruff-pre-commit configuration with separate hooks for linting and formatting: + +- **ruff-check**: Runs the linter with automatic fixes (`--fix` flag) +- **ruff-format**: Runs the formatter for code styling +- **types_or: [python, pyi]**: Excludes Jupyter notebooks from processing + +This configuration ensures consistent code quality and style across the project while avoiding conflicts with Jupyter notebook files. + +--- + +## :material-test-tube: Testing Setup + +### Running Tests + +```bash +# Run all tests +poetry run pytest +# or with pip: +pytest + +# Run tests with coverage +poetry run pytest --cov=swarms tests/ + +# Run specific test file +poetry run pytest tests/test_specific_file.py + +# Run tests matching a pattern +poetry run pytest -k "test_agent" +``` + +### Test Structure + +The project uses pytest with the following structure: +``` +tests/ +├── agents/ # Agent-related tests +├── structs/ # Multi-agent structure tests +├── tools/ # Tool tests +├── utils/ # Utility tests +└── conftest.py # Test configuration +``` + +### Writing Tests + +```python +# Example test file: tests/test_example.py +import pytest +from swarms import Agent + +def test_agent_creation(): + """Test that an agent can be created successfully.""" + agent = Agent( + agent_name="test_agent", + system_prompt="You are a helpful assistant" + ) + assert agent.agent_name == "test_agent" + +@pytest.mark.parametrize("input_val,expected", [ + ("hello", "HELLO"), + ("world", "WORLD"), +]) +def test_uppercase(input_val, expected): + """Example parametrized test.""" + assert input_val.upper() == expected +``` + +--- + +## :material-book-open-page-variant: Documentation Setup + +### Building Documentation Locally + +```bash +# Install documentation dependencies +pip install -r docs/requirements.txt + +# Navigate to docs directory +cd docs + +# Serve documentation locally +mkdocs serve +# Documentation will be available at http://127.0.0.1:8000 +``` + +### Documentation Structure + +``` +docs/ +├── index.md # Homepage +├── mkdocs.yml # MkDocs configuration +├── swarms/ # Core documentation +├── examples/ # Examples and tutorials +├── contributors/ # Contributor guides +└── assets/ # Images and static files +``` + +### Writing Documentation + +Use Markdown with MkDocs extensions: + +```markdown +# Page Title + +!!! tip "Pro Tip" + Use admonitions to highlight important information. + +=== "Python" + ```python + from swarms import Agent + agent = Agent() + ``` + +=== "CLI" + ```bash + swarms create-agent --name myagent + ``` +``` + +--- + +## :material-application-variable: Environment Variables + +Create a `.env` file for local development: + +```bash +# Copy example environment file +cp .env.example .env # if it exists + +# Or create your own .env file +touch .env +``` + +Common environment variables: +```bash +# .env file +OPENAI_API_KEY=your_openai_api_key_here +ANTHROPIC_API_KEY=your_anthropic_api_key_here +GROQ_API_KEY=your_groq_api_key_here + +# Development settings +DEBUG=true +LOG_LEVEL=INFO + +# Optional: Database settings +DATABASE_URL=sqlite:///swarms.db +``` + +--- + +## :material-check-circle: Verification Steps + +!!! tip "Automated Verification" + If you used the automated setup script (`./scripts/setup.sh`), most verification steps are handled automatically. The script runs verification checks and reports any issues. + +For manual setups, verify your setup is working correctly: + +### 1. Basic Import Test +```bash +poetry run python -c "from swarms import Agent; print('✅ Import successful')" +``` + +### 2. Run a Simple Agent +```python +# test_setup.py +from swarms import Agent + +agent = Agent( + agent_name="setup_test", + system_prompt="You are a helpful assistant for testing setup.", + max_loops=1 +) + +response = agent.run("Say hello!") +print(f"✅ Agent response: {response}") +``` + +### 3. Code Quality Check +```bash +# Run all quality checks +poetry run black swarms/ --check +poetry run ruff check swarms/ +poetry run pytest tests/ -x +``` + +### 4. Documentation Build +```bash +cd docs +mkdocs build +echo "✅ Documentation built successfully" +``` + +--- + +## :material-rocket-launch: Development Workflow + +### Creating a Feature Branch + +```bash +# Sync with upstream +git fetch upstream +git checkout master +git rebase upstream/master + +# Create feature branch +git checkout -b feature/your-feature-name + +# Make your changes... +# Add and commit +git add . +git commit -m "feat: add your feature description" + +# Push to your fork +git push origin feature/your-feature-name +``` + +### Daily Development Commands + +```bash +# Start development session +cd swarms +poetry shell # or source venv/bin/activate + +# Pull latest changes +git fetch upstream +git rebase upstream/master + +# Run tests during development +poetry run pytest tests/ -v + +# Format and lint before committing +poetry run black swarms/ +poetry run ruff check swarms/ --fix + +# Run a quick smoke test +poetry run python -c "from swarms import Agent; print('✅ All good')" +``` + +--- + +## :material-bug: Troubleshooting + +!!! tip "First Step: Try the Automated Setup" + If you're experiencing setup issues, try running our automated setup script first: + ```bash + chmod +x scripts/setup.sh + ./scripts/setup.sh + ``` + This script handles most common setup problems automatically and provides helpful error messages. + +### Common Issues and Solutions + +=== "Poetry Issues" + + **Problem**: Poetry command not found + ```bash + # Solution: Add Poetry to PATH + export PATH="$HOME/.local/bin:$PATH" + # Add to your shell profile (.bashrc, .zshrc, etc.) + ``` + + **Problem**: Poetry install fails + ```bash + # Solution: Clear cache and reinstall + poetry cache clear --all pypi + poetry install --with dev + ``` + +=== "Python Version Issues" + + **Problem**: Wrong Python version + ```bash + # Check Python version + python --version + + # Use pyenv to manage Python versions + curl https://pyenv.run | bash + pyenv install 3.10.12 + pyenv local 3.10.12 + ``` + +=== "Import Errors" + + **Problem**: Cannot import swarms modules + ```bash + # Ensure you're in the virtual environment + poetry shell + # or + source venv/bin/activate + + # Install in development mode + poetry install --with dev + # or + pip install -e . + ``` + +=== "Test Failures" + + **Problem**: Tests fail due to missing dependencies + ```bash + # Install test dependencies + poetry install --with test + # or + pip install pytest pytest-cov pytest-mock + ``` + +### Getting Help + +If you encounter issues: + +1. **Check the FAQ** in the main documentation +2. **Search existing issues** on GitHub +3. **Ask in the Discord community**: [discord.gg/jM3Z6M9uMq](https://discord.gg/jM3Z6M9uMq) +4. **Create a GitHub issue** with: + - Your operating system + - Python version + - Error messages + - Steps to reproduce + +--- + +## :material-next-step: Next Steps + +Now that your environment is set up: + +1. **Read the Contributing Guide**: [contributors/main.md](main.md) +2. **Explore the Codebase**: Start with `swarms/structs/agent.py` +3. **Run Examples**: Check out `examples/` directory +4. **Pick an Issue**: Look for `good-first-issue` labels on GitHub +5. **Join the Community**: Discord, Twitter, and GitHub discussions + +!!! success "You're Ready!" + Your Swarms development environment is now set up! You're ready to contribute to the most important technology for multi-agent collaboration. + +--- + +## :material-bookmark-outline: Quick Reference + +### Essential Commands + +```bash +# Setup (choose one) +./scripts/setup.sh # Automated setup (recommended) +poetry install --with dev # Manual dependency install + +# Daily workflow +poetry shell # Activate environment +poetry run pytest # Run tests +poetry run black swarms/ # Format code +poetry run ruff check swarms/ # Lint code + +# Git workflow +git fetch upstream # Get latest changes +git rebase upstream/master # Update your branch +git checkout -b feature/name # Create feature branch +git push origin feature/name # Push your changes + +# Documentation +cd docs && mkdocs serve # Serve docs locally +mkdocs build # Build docs +``` + +### Project Structure + +``` +swarms/ +├── swarms/ # Core package +│ ├── agents/ # Agent implementations +│ ├── structs/ # Multi-agent structures +│ ├── tools/ # Agent tools +│ └── utils/ # Utilities +├── examples/ # Usage examples +├── tests/ # Test suite +├── docs/ # Documentation +├── pyproject.toml # Poetry configuration +└── requirements.txt # Pip dependencies +``` + +Happy coding! 🚀 \ No newline at end of file diff --git a/docs/swarms/structs/base_workflow.md b/docs/swarms/structs/base_workflow.md deleted file mode 100644 index 36d81062..00000000 --- a/docs/swarms/structs/base_workflow.md +++ /dev/null @@ -1,287 +0,0 @@ -# BaseWorkflow - -The `BaseWorkflow` class serves as a foundational structure for defining and managing workflows. It allows users to add, remove, update, and manage tasks and agents within a workflow, offering flexibility and extensibility for various applications. - -### Key Concepts - -- **Agents**: Entities participating in the workflow. -- **Tasks**: Units of work to be executed within the workflow. -- **Models**: Computational models used within the workflow. -- **Workflow State**: The state of the workflow, which can be saved and restored. - -## Attributes - -### Arguments - -| Argument | Type | Default | Description | -|----------|------|---------|-------------| -| `agents` | `List[Agent]` | `None` | A list of agents participating in the workflow. | -| `task_pool` | `List[Task]` | `None` | A list of tasks in the workflow. | -| `models` | `List[Any]` | `None` | A list of models used in the workflow. | -| `*args` | | | Variable length argument list. | -| `**kwargs` | | | Arbitrary keyword arguments. | - -### Attributes - -| Attribute | Type | Description | -|-----------|------|-------------| -| `agents` | `List[Agent]` | A list of agents participating in the workflow. | -| `task_pool` | `List[Task]` | A list of tasks in the workflow. | -| `models` | `List[Any]` | A list of models used in the workflow. | - -## Methods - -### add_task - -Adds a task or a list of tasks to the task pool. - -**Arguments:** - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `task` | `Task` | `None` | A single task to add. | -| `tasks` | `List[Task]` | `None` | A list of tasks to add. | - -**Raises:** - -- `ValueError`: If neither task nor tasks are provided. - -**Examples:** - -```python -workflow = BaseWorkflow() -task1 = Task(description="Task 1") -task2 = Task(description="Task 2") - -# Adding a single task -workflow.add_task(task=task1) - -# Adding multiple tasks -workflow.add_task(tasks=[task1, task2]) -``` - -### add_agent - -Adds an agent to the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `agent` | `Agent` | The agent to add to the workflow. | - -**Examples:** - -```python -workflow = BaseWorkflow() -agent = Agent(name="Agent 1") - -# Adding an agent to the workflow -workflow.add_agent(agent=agent) -``` - -### run - -Abstract method to run the workflow. - -### __sequential_loop - -Abstract method for the sequential loop. - -### __log - -Logs a message if verbose mode is enabled. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `message` | `str` | The message to log. | - -### __str__ - -Returns a string representation of the workflow. - -### __repr__ - -Returns a string representation of the workflow for debugging. - -### reset - -Resets the workflow by clearing the results of each task. - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.reset() -``` - -### get_task_results - -Returns the results of each task in the workflow. - -**Returns:** - -| Return Type | Description | -|-------------|-------------| -| `Dict[str, Any]` | The results of each task in the workflow. | - -**Examples:** - -```python -workflow = BaseWorkflow() -results = workflow.get_task_results() -``` - -### remove_task - -Removes a task from the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `task` | `str` | The description of the task to remove. | - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.remove_task(task="Task 1") -``` - -### update_task - -Updates the arguments of a task in the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `task` | `str` | The description of the task to update. | -| `**updates` | | The updates to apply to the task. | - -**Raises:** - -- `ValueError`: If the task is not found in the workflow. - -**Examples:** - -```python -workflow = BaseWorkflow() -task = Task(description="Task 1", kwargs={"param": 1}) - -# Adding a task to the workflow -workflow.add_task(task=task) - -# Updating the task -workflow.update_task("Task 1", param=2) -``` - -### delete_task - -Deletes a task from the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `task` | `str` | The description of the task to delete. | - -**Raises:** - -- `ValueError`: If the task is not found in the workflow. - -**Examples:** - -```python -workflow = BaseWorkflow() -task = Task(description="Task 1") - -# Adding a task to the workflow -workflow.add_task(task=task) - -# Deleting the task -workflow.delete_task("Task 1") -``` - -### save_workflow_state - -Saves the workflow state to a json file. - -**Arguments:** - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `filepath` | `Optional[str]` | `"sequential_workflow_state.json"` | The path to save the workflow state to. | - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.save_workflow_state(filepath="workflow_state.json") -``` - -### add_objective_to_workflow - -Adds an objective to the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `task` | `str` | The description of the task. | -| `**kwargs` | | Additional keyword arguments for the task. | - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.add_objective_to_workflow(task="New Objective", agent=agent, args=[], kwargs={}) -``` - -### load_workflow_state - -Loads the workflow state from a json file and restores the workflow state. - -**Arguments:** - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `filepath` | `str` | `None` | The path to load the workflow state from. | - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.load_workflow_state(filepath="workflow_state.json") -``` - -### workflow_dashboard - -Displays a dashboard for the workflow. - -**Arguments:** - -| Parameter | Type | Description | -|-----------|------|-------------| -| `**kwargs` | | Additional keyword arguments to pass to the dashboard. | - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.workflow_dashboard() -``` - -### workflow_bootup - -Initializes the workflow. - -**Examples:** - -```python -workflow = BaseWorkflow() -workflow.workflow_bootup() -``` \ No newline at end of file diff --git a/swarms/utils/vllm_wrapper.py b/examples/models/vllm_wrapper.py similarity index 92% rename from swarms/utils/vllm_wrapper.py rename to examples/models/vllm_wrapper.py index 8a114ad1..00dd95d8 100644 --- a/swarms/utils/vllm_wrapper.py +++ b/examples/models/vllm_wrapper.py @@ -1,6 +1,7 @@ -import os import concurrent.futures -from typing import List, Optional, Dict, Any +import os +from typing import Any + from loguru import logger try: @@ -26,12 +27,12 @@ class VLLMWrapper: def __init__( self, model_name: str = "meta-llama/Llama-2-7b-chat-hf", - system_prompt: Optional[str] = None, + system_prompt: str | None = None, stream: bool = False, temperature: float = 0.5, max_tokens: int = 4000, max_completion_tokens: int = 4000, - tools_list_dictionary: Optional[List[Dict[str, Any]]] = None, + tools_list_dictionary: list[dict[str, Any]] | None = None, tool_choice: str = "auto", parallel_tool_calls: bool = False, *args, @@ -121,8 +122,8 @@ class VLLMWrapper: return self.run(task, *args, **kwargs) def batched_run( - self, tasks: List[str], batch_size: int = 10 - ) -> List[str]: + self, tasks: list[str], batch_size: int = 10 + ) -> list[str]: """ Run the model for multiple tasks in batches. diff --git a/examples/multi_agent/council/council_judge_evaluation.py b/examples/multi_agent/council/council_judge_evaluation.py index d1ae0190..8e0694d5 100644 --- a/examples/multi_agent/council/council_judge_evaluation.py +++ b/examples/multi_agent/council/council_judge_evaluation.py @@ -329,7 +329,8 @@ class CouncilJudgeEvaluator: return ( final_answer.group(1) == correct_answer_lower ) - except: + except Exception as e: + logger.error(f"Error checking answer: {str(e)}") pass # For other datasets, check if the correct answer is contained in the evaluation diff --git a/pyproject.toml b/pyproject.toml index 8da6a778..6291af13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,12 @@ mypy-protobuf = "^3.0.0" [tool.poetry.group.test.dependencies] pytest = "^8.1.1" +[tool.poetry.group.dev.dependencies] +black = "*" +ruff = "*" +pytest = "*" +# pre-commit = "*" + [tool.ruff] line-length = 70 diff --git a/requirements.txt b/requirements.txt index 918aacd3..2f512d55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,17 +12,17 @@ psutil python-dotenv PyYAML docstring_parser==0.16 -black>=23.1,<26.0 -ruff>=0.0.249,<0.4.5 +black +ruff types-toml>=0.10.8.1 types-pytz>=2023.3,<2026.0 types-chardet>=5.0.4.6 mypy-protobuf>=3.0.0 -pytest>=8.1.1 +pytest networkx aiofiles httpx # vllm>=0.2.0 aiohttp mcp -numpy \ No newline at end of file +numpy diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 00000000..c9beb36b --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,155 @@ +#!/bin/bash + +# Swarms Setup Script +# This script sets up the complete development environment for the Swarms project + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +print_status "Starting Swarms development environment setup..." + +# Check Python version +print_status "Checking Python version..." +if command_exists python3; then + PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') + print_status "Found Python $PYTHON_VERSION" + + # Check if Python version meets requirements (>=3.10) + if python3 -c 'import sys; exit(0 if sys.version_info >= (3, 10) else 1)'; then + print_success "Python version is compatible (>=3.10)" + else + print_error "Python 3.10 or higher is required. Please install a compatible Python version." + exit 1 + fi +else + print_error "Python3 is not installed. Please install Python 3.10 or higher." + exit 1 +fi + +# Install Poetry if not present +if ! command_exists poetry; then + print_status "Poetry not found. Installing Poetry..." + curl -sSL https://install.python-poetry.org | python3 - + + # Add Poetry to PATH for current session + export PATH="$HOME/.local/bin:$PATH" + + # Check if installation was successful + if command_exists poetry; then + print_success "Poetry installed successfully" + else + print_error "Failed to install Poetry. Please install manually from https://python-poetry.org/" + exit 1 + fi +else + print_success "Poetry is already installed" + poetry --version +fi + +# Configure Poetry to create virtual environments in project directory +print_status "Configuring Poetry..." +poetry config virtualenvs.in-project true +poetry config virtualenvs.prefer-active-python true + +# Install dependencies +print_status "Installing project dependencies..." +poetry install --with dev,lint,test + +print_success "All dependencies installed successfully" + +# Activate virtual environment and run additional setup +print_status "Setting up development tools..." + +# Setup pre-commit hooks +print_status "Installing pre-commit hooks..." +poetry run pre-commit install +poetry run pre-commit install --hook-type commit-msg + +print_success "Pre-commit hooks installed" + +# Run pre-commit on all files to ensure everything is set up correctly +print_status "Running pre-commit on all files (this may take a while on first run)..." +poetry run pre-commit run --all-files || print_warning "Some pre-commit checks failed - this is normal on first setup" + +# Create .env file if it doesn't exist +if [ ! -f ".env" ]; then + print_status "Creating .env file template..." + cat > .env << 'EOF' +# Swarms Environment Variables +# Copy this file and fill in your actual values + +# OpenAI Configuration +OPENAI_API_KEY=your_openai_api_key_here + +# Other API Keys (add as needed) +# ANTHROPIC_API_KEY=your_anthropic_key_here +# COHERE_API_KEY=your_cohere_key_here + +# Logging Level +LOG_LEVEL=INFO + +# Development Settings +DEVELOPMENT=true +EOF + print_success ".env template created - please fill in your API keys" +else + print_status ".env file already exists" +fi + +# Check if Git is initialized +if [ ! -d ".git" ]; then + print_warning "Git repository not initialized. Run 'git init' if you want version control." +else + print_success "Git repository detected" +fi + +# Display virtual environment information +print_status "Virtual environment information:" +poetry env info + +# Display installed packages +print_status "Installed packages:" +poetry show --tree + +print_success "Setup completed successfully!" +print_status "Next steps:" +echo " 1. Activate the virtual environment: poetry shell" +echo " 2. Fill in your API keys in the .env file" +echo " 3. Run tests to verify installation: poetry run pytest" +echo " 4. Start developing!" + +print_status "Useful commands:" +echo " - poetry shell # Activate virtual environment" +echo " - poetry run python