parent
c9f69d5fef
commit
02a6fbc694
@ -1,31 +1,55 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.11-slim
|
||||
# Use Python 3.11 slim-bullseye for smaller base image
|
||||
FROM python:3.11-slim-bullseye AS builder
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /usr/src/swarms
|
||||
|
||||
|
||||
# Install Python dependencies
|
||||
# COPY requirements.txt and pyproject.toml if you're using poetry for dependency management
|
||||
COPY requirements.txt .
|
||||
RUN pip install --upgrade pip
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Install the 'swarms' package, assuming it's available on PyPI
|
||||
RUN pip install -U swarms
|
||||
|
||||
# Copy the rest of the application
|
||||
COPY . .
|
||||
|
||||
# Expose port if your application has a web interface
|
||||
# EXPOSE 5000
|
||||
|
||||
# # Define environment variable for the swarm to work
|
||||
# ENV OPENAI_API_KEY=your_swarm_api_key_here
|
||||
|
||||
# If you're using `CMD` to execute a Python script, make sure it's executable
|
||||
# RUN chmod +x example.py
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PIP_NO_CACHE_DIR=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /build
|
||||
|
||||
# Install only essential build dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
gcc \
|
||||
g++ \
|
||||
gfortran \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install swarms packages
|
||||
RUN pip install --no-cache-dir swarm-models swarms
|
||||
|
||||
# Production stage
|
||||
FROM python:3.11-slim-bullseye
|
||||
|
||||
# Set secure environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
WORKSPACE_DIR="agent_workspace" \
|
||||
PATH="/app:${PATH}" \
|
||||
PYTHONPATH="/app:${PYTHONPATH}" \
|
||||
USER=swarms
|
||||
|
||||
# Create non-root user
|
||||
RUN useradd -m -s /bin/bash -U $USER && \
|
||||
mkdir -p /app && \
|
||||
chown -R $USER:$USER /app
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only necessary files from builder
|
||||
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# Copy application with correct permissions
|
||||
COPY --chown=$USER:$USER . .
|
||||
|
||||
# Switch to non-root user
|
||||
USER $USER
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
CMD python -c "import swarms; print('Health check passed')" || exit 1
|
@ -1,65 +0,0 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
# Import necessary classes from your swarm module
|
||||
from swarms.structs.agent import Agent
|
||||
from swarms.structs.base_swarm import BaseSwarm
|
||||
from swarms.telemetry.capture_sys_data import log_agent_data
|
||||
from swarms.utils.file_processing import create_file_in_folder
|
||||
from swarms import SpreadSheetSwarm
|
||||
# Ensure you have an environment variable or default workspace dir
|
||||
workspace_dir = os.getenv("WORKSPACE_DIR", "./workspace")
|
||||
def create_agents(num_agents: int):
|
||||
"""
|
||||
Create a list of agent instances.
|
||||
|
||||
Args:
|
||||
num_agents (int): The number of agents to create.
|
||||
|
||||
Returns:
|
||||
List[Agent]: List of created Agent objects.
|
||||
"""
|
||||
agents = []
|
||||
for i in range(num_agents):
|
||||
agent_name = f"Agent-{i + 1}"
|
||||
agents.append(Agent(agent_name=agent_name))
|
||||
return agents
|
||||
def main():
|
||||
# Number of agents to create
|
||||
num_agents = 5
|
||||
# Create the agents
|
||||
agents = create_agents(num_agents)
|
||||
# Initialize the swarm with agents and other configurations
|
||||
swarm = SpreadSheetSwarm(
|
||||
name="Test-Swarm",
|
||||
description="A swarm for testing purposes.",
|
||||
agents=agents,
|
||||
autosave_on=True,
|
||||
max_loops=2,
|
||||
workspace_dir=workspace_dir
|
||||
)
|
||||
# Run a sample task in the swarm (synchronously)
|
||||
task = "process_data"
|
||||
|
||||
# Ensure the run method is synchronous
|
||||
swarm_metadata = swarm.run(task) # Assuming this is made synchronous
|
||||
# Print swarm metadata after task completion
|
||||
print("Swarm Metadata:")
|
||||
print(swarm_metadata)
|
||||
# Check if CSV file has been created and saved
|
||||
if os.path.exists(swarm.save_file_path):
|
||||
print(f"Metadata saved to: {swarm.save_file_path}")
|
||||
else:
|
||||
print(f"Metadata not saved correctly. Check the save path.")
|
||||
# Test saving metadata to JSON file
|
||||
swarm.data_to_json_file()
|
||||
# Test exporting metadata to JSON
|
||||
swarm_json = swarm.export_to_json()
|
||||
print("Exported JSON metadata:")
|
||||
print(swarm_json)
|
||||
# Log agent data
|
||||
print("Logging agent data:")
|
||||
print(log_agent_data(swarm.metadata.model_dump()))
|
||||
# Run the synchronous main function
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in new issue