diff --git a/docs/cli.md b/docs/cli.md new file mode 100644 index 00000000..56e1be35 --- /dev/null +++ b/docs/cli.md @@ -0,0 +1,225 @@ +# CLI Reference + +The Prime CLI provides commands for managing GPU pods, sandboxes, environments, and more. + +## Global Options + +```bash +prime --help # Show all commands +prime --version # Show version +``` + +## Authentication + +```bash +# Interactive login (opens browser) +prime login + +# Check current user +prime whoami +``` + +## GPU Availability + +Query available GPU resources across providers: + +```bash +# List all available GPUs +prime availability list + +# Filter by GPU type +prime availability list --gpu-type H100_80GB +prime availability list --gpu-type A100_80GB + +# Show available GPU types +prime availability gpu-types + +# Filter by region +prime availability list --region us-east + +# Show detailed pricing +prime availability list --show-pricing +``` + +## Pod Management + +Deploy and manage GPU compute instances: + +```bash +# List your pods +prime pods list + +# Create a pod (interactive) +prime pods create + +# Create with specific configuration +prime pods create --id +prime pods create --name my-training-pod +prime pods create --gpu H100 --count 8 + +# Monitor pod status +prime pods status + +# SSH into a pod +prime pods ssh + +# Terminate a pod +prime pods terminate +``` + +## Sandboxes + +Manage isolated code execution environments: + +```bash +# Create a sandbox +prime sandbox create python:3.11 +prime sandbox create ubuntu:22.04 --name my-sandbox + +# List sandboxes +prime sandbox list +prime sandbox list --status RUNNING + +# Execute commands +prime sandbox exec "python script.py" +prime sandbox exec "pip install numpy && python -c 'import numpy; print(numpy.__version__)'" + +# File operations +prime sandbox upload local_file.py /remote/path/ +prime sandbox download /remote/file.txt ./local/ + +# Delete sandbox +prime sandbox delete +``` + +## Environments Hub + +Access hundreds of verified environments: + +```bash +# Browse available environments +prime env list + +# Search environments +prime env list --search "math" + +# View environment details +prime env info + +# Install an environment locally +prime env install + +# Create your own environment +prime env init my-environment + +# Push environment to hub +prime env push my-environment +``` + +## Evaluations + +Push and manage evaluation results: + +```bash +# Auto-discover and push evaluations from current directory +prime eval push + +# Push specific directory +prime eval push examples/verifiers_example + +# List all evaluations +prime eval list + +# Get evaluation details +prime eval get + +# View evaluation samples +prime eval samples + +# Delete an evaluation +prime eval delete +``` + +## Teams + +Manage team resources: + +```bash +# List teams +prime teams list + +# Set team context +prime config set-team-id +prime config set-team-id +``` + +## Configuration + +```bash +# View current configuration +prime config view + +# Set API key +prime config set-api-key + +# Set SSH key path +prime config set-ssh-key-path + +# Set team ID +prime config set-team-id +``` + +## Inference + +Run inference requests: + +```bash +# Chat completion +prime inference chat "What is 2+2?" + +# With specific model +prime inference chat "Explain quantum computing" --model gpt-4 + +# Streaming response +prime inference chat "Write a poem" --stream +``` + +## Images + +Manage container images: + +```bash +# List available images +prime images list + +# Get image details +prime images info +``` + +## Registry + +Manage private registries: + +```bash +# List registry credentials +prime registry list + +# Add registry credentials +prime registry add --name my-registry --server ghcr.io +``` + +## Disks + +Manage persistent storage: + +```bash +# List disks +prime disks list + +# Create disk +prime disks create --name my-data --size 100 + +# Delete disk +prime disks delete +``` + diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 00000000..b6b4050b --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,124 @@ +# Configuration + +## API Key + +Get your API key from the [Prime Intellect Dashboard](https://app.primeintellect.ai). + +### Interactive Login (Recommended) + +```bash +prime login +``` + +This opens a browser for authentication and stores your credentials securely. + +### Set API Key Directly + +```bash +# Interactive mode (hides input) +prime config set-api-key + +# Non-interactive mode (for automation) +prime config set-api-key YOUR_API_KEY +``` + +### Environment Variable + +```bash +export PRIME_API_KEY="your-api-key-here" +``` + +**Security Note**: When using non-interactive mode, the API key may be visible in your shell history. For enhanced security, use interactive mode or environment variables. + +### Configuration Priority + +The SDK looks for credentials in this order: + +1. **Direct parameter**: `APIClient(api_key="sk-...")` +2. **Environment variable**: `PRIME_API_KEY` +3. **Config file**: `~/.prime/config.json` (created by `prime login`) + +## SSH Key + +Configure SSH key for pod access: + +```bash +# Interactive selection +prime config set-ssh-key-path + +# Or specify directly +prime config set-ssh-key-path ~/.ssh/id_rsa.pub +``` + +## Team Context + +Set team context for managing shared resources: + +```bash +# List your teams +prime teams list + +# Set team context (interactive) +prime config set-team-id + +# Set team context directly +prime config set-team-id +``` + +All subsequent commands will use the team context: + +```bash +prime pods list # Shows team's pods +prime sandbox list # Shows team's sandboxes +``` + +## View Configuration + +```bash +prime config view +``` + +## Configuration File + +Configuration is stored in `~/.prime/config.json`: + +```json +{ + "api_key": "your-api-key", + "base_url": "https://api.primeintellect.ai", + "ssh_key_path": "/Users/you/.ssh/id_rsa.pub", + "team_id": "team-123" +} +``` + +## SDK Configuration + +### Python SDK + +```python +from prime_sandboxes import APIClient, SandboxClient + +# Option 1: Direct API key +client = APIClient(api_key="your-api-key") + +# Option 2: From environment variable +import os +client = APIClient(api_key=os.environ["PRIME_API_KEY"]) + +# Option 3: Auto-detect (uses env var or config file) +client = APIClient() + +sandbox_client = SandboxClient(client) +``` + +### Async Client + +```python +from prime_sandboxes import AsyncSandboxClient + +# Context manager handles cleanup +async with AsyncSandboxClient(api_key="your-api-key") as client: + # Use client + pass +``` + diff --git a/docs/environments.md b/docs/environments.md new file mode 100644 index 00000000..cd308e99 --- /dev/null +++ b/docs/environments.md @@ -0,0 +1,180 @@ +# Environments Hub + +Access hundreds of RL environments on our community hub with deep integrations with sandboxes, training, and evaluation stack. + +## Overview + +Environments provide pre-configured setups for machine learning, data science, and development workflows, tested and verified by the Prime Intellect community. They integrate seamlessly with: + +- **Sandboxes** - Run environments in isolated execution environments +- **Training** - Use environments for RL training with PRIME-RL +- **Evaluation** - Evaluate models against environment benchmarks + +## Browsing Environments + +```bash +# List all available environments +prime env list + +# Search for specific environments +prime env list --search "math" +prime env list --search "code" + +# Filter by category +prime env list --category reasoning +``` + +## Environment Details + +```bash +# View environment information +prime env info gsm8k +prime env info hendrycks-math + +# Shows: +# - Description +# - Author +# - Version +# - Dependencies +# - Usage examples +``` + +## Installing Environments + +```bash +# Install an environment locally +prime env install gsm8k + +# Install specific version +prime env install gsm8k@1.0.0 + +# Install to custom path +prime env install gsm8k --path ./my-envs/ +``` + +After installation, environments are available for use with verifiers: + +```python +from verifiers import load_environment + +env = load_environment("gsm8k") +``` + +## Creating Environments + +### Initialize a New Environment + +```bash +prime env init my-environment +``` + +This creates a new environment scaffold: + +``` +my-environment/ +├── pyproject.toml +├── README.md +├── metadata.json +└── src/ + └── my_environment/ + └── __init__.py +``` + +### Environment Structure + +**pyproject.toml** - Package configuration: + +```toml +[project] +name = "my-environment" +version = "0.1.0" +description = "My custom environment" + +[project.optional-dependencies] +all = [] + +[tool.verifiers] +environment = "my_environment" +``` + +**metadata.json** - Hub metadata: + +```json +{ + "name": "my-environment", + "description": "A custom RL environment", + "category": "reasoning", + "tags": ["math", "custom"], + "author": "your-username" +} +``` + +**src/my_environment/__init__.py** - Environment implementation: + +```python +from verifiers import SingleTurnEnv + +def load_environment(**kwargs): + """Entry point for loading the environment.""" + return MyEnvironment(**kwargs) + +class MyEnvironment(SingleTurnEnv): + def __init__(self, **kwargs): + super().__init__(**kwargs) + # Initialize environment + + def get_dataset(self): + # Return evaluation dataset + pass + + def get_reward_functions(self): + # Return reward functions + pass +``` + +### Publishing Environments + +```bash +# Validate environment +prime env validate my-environment + +# Push to hub +prime env push my-environment + +# Push with version tag +prime env push my-environment --version 1.0.0 +``` + +## Using with Training + +Environments integrate with PRIME-RL for training: + +```bash +# Install environment for training +prime env install gsm8k + +# Use in training config +uv run rl @ config.toml --env gsm8k +``` + +## Using with Evaluation + +Push evaluation results for environments: + +```bash +# Run evaluation and push results +prime eval push ./outputs/evals/gsm8k--gpt-4o/ +``` + +Results appear on the environment's leaderboard on the hub. + +## Environment Categories + +| Category | Description | Examples | +|----------|-------------|----------| +| `reasoning` | Math and logical reasoning | gsm8k, hendrycks-math | +| `code` | Code generation and completion | humaneval, mbpp | +| `qa` | Question answering | triviaqa, naturalquestions | +| `games` | Interactive games | wordle, chess | +| `agents` | Multi-turn agent tasks | webshop, alfworld | + diff --git a/docs/evals.md b/docs/evals.md new file mode 100644 index 00000000..d91312d1 --- /dev/null +++ b/docs/evals.md @@ -0,0 +1,290 @@ +# Evals SDK + +Lightweight Python SDK for managing Prime Intellect evaluations - push, track, and analyze your model evaluation results. + +## Features + +- **Simple evaluation management** - Create, push samples, and finalize evaluations +- **Type-safe** - Full type hints and Pydantic models +- **Authentication caching** - Automatic token management +- **Environment checking** - Validate environments before pushing +- **No CLI dependencies** - Pure SDK, lightweight installation +- **Context manager support** - Automatic resource cleanup + +## Installation + +```bash +uv pip install prime-evals +``` + +Or with pip: + +```bash +pip install prime-evals +``` + +## Quick Start + +```python +from prime_evals import APIClient, EvalsClient + +# Initialize client +api_client = APIClient(api_key="your-api-key") +client = EvalsClient(api_client) + +# Create an evaluation +eval_response = client.create_evaluation( + name="gsm8k-gpt4o-baseline", + model_name="gpt-4o-mini", + dataset="gsm8k", + framework="verifiers", + metadata={ + "version": "1.0", + "num_examples": 10, + "temperature": 0.7, + } +) + +eval_id = eval_response["evaluation_id"] +print(f"Created evaluation: {eval_id}") + +# Push samples +samples = [ + { + "example_id": 0, + "reward": 1.0, + "correct": True, + "answer": "18", + "prompt": [{"role": "user", "content": "What is 9+9?"}], + "completion": [{"role": "assistant", "content": "The answer is 18."}], + } +] + +client.push_samples(eval_id, samples) + +# Finalize with metrics +metrics = { + "avg_reward": 0.87, + "avg_correctness": 0.82, + "success_rate": 0.87, +} + +client.finalize_evaluation(eval_id, metrics=metrics) +print("Evaluation finalized!") +``` + +## Async Usage + +```python +import asyncio +from prime_evals import AsyncEvalsClient + +async def main(): + async with AsyncEvalsClient(api_key="your-api-key") as client: + # Create evaluation + eval_response = client.create_evaluation( + name="my-evaluation", + model_name="gpt-4o-mini", + dataset="gsm8k", + ) + + eval_id = eval_response["evaluation_id"] + + # Push samples + await client.push_samples(eval_id, samples) + + # Finalize + await client.finalize_evaluation(eval_id) + +# Client automatically closed + +asyncio.run(main()) +``` + +## Authentication + +The SDK looks for credentials in this order: + +1. **Direct parameter**: `APIClient(api_key="sk-...")` +2. **Environment variable**: `export PRIME_API_KEY="sk-..."` +3. **Config file**: `~/.prime/config.json` (created by `prime login` CLI command) + +## Complete Example + +```python +from prime_evals import APIClient, EvalsClient + +# Initialize +api_client = APIClient(api_key="your-api-key") +client = EvalsClient(api_client) + +# Create evaluation with full metadata +eval_response = client.create_evaluation( + name="gsm8k-experiment-1", + model_name="gpt-4o-mini", + dataset="gsm8k", + framework="verifiers", + task_type="math", + description="Baseline evaluation on GSM8K dataset", + tags=["baseline", "math", "gsm8k"], + metadata={ + "version": "1.0", + "timestamp": "2025-10-09T12:00:00Z", + "num_examples": 100, + "temperature": 0.7, + "max_tokens": 2048, + } +) + +eval_id = eval_response["evaluation_id"] + +# Push samples in batches +samples_batch = [ + { + "example_id": i, + "task": "gsm8k", + "reward": 1.0 if i % 2 == 0 else 0.5, + "correct": i % 2 == 0, + "format_reward": 1.0, + "correctness": 1.0 if i % 2 == 0 else 0.0, + "answer": str(i * 2), + "prompt": [ + {"role": "system", "content": "Solve the math problem."}, + {"role": "user", "content": f"What is {i} + {i}?"} + ], + "completion": [ + {"role": "assistant", "content": f"The answer is {i * 2}."} + ], + "info": {"batch": 1} + } + for i in range(10) +] + +client.push_samples(eval_id, samples_batch) + +# Finalize with computed metrics +final_metrics = { + "avg_reward": 0.75, + "avg_format_reward": 1.0, + "avg_correctness": 0.50, + "success_rate": 0.75, + "total_samples": len(samples_batch), +} + +client.finalize_evaluation(eval_id, metrics=final_metrics) + +# Retrieve evaluation details +eval_details = client.get_evaluation(eval_id) +print(f"Evaluation Status: {eval_details.get('status')}") + +# List all evaluations +evaluations = client.list_evaluations(limit=10) +for eval in evaluations.get("evaluations", []): + print(f"{eval['name']}: {eval.get('total_samples', 0)} samples") + +# Get samples +samples_response = client.get_samples(eval_id, page=1, limit=100) +print(f"Retrieved {len(samples_response.get('samples', []))} samples") +``` + +## Push from JSON File + +You can also push evaluations from a JSON file: + +```python +import json +from prime_evals import APIClient, EvalsClient + +with open("eval_results.json") as f: + eval_data = json.load(f) + +api_client = APIClient() +client = EvalsClient(api_client) + +# Create +eval_response = client.create_evaluation( + name=eval_data["eval_name"], + model_name=eval_data["model_name"], + dataset=eval_data["dataset"], + metadata=eval_data.get("metadata"), + metrics=eval_data.get("metrics"), +) + +eval_id = eval_response["evaluation_id"] + +# Push samples +if "results" in eval_data: + client.push_samples(eval_id, eval_data["results"]) + +# Finalize +client.finalize_evaluation(eval_id, metrics=eval_data.get("metrics")) + +print(f"Successfully pushed evaluation: {eval_id}") +``` + +## CLI Usage + +The Prime CLI provides commands for pushing evaluations: + +```bash +# Auto-discover and push evaluations from current directory +prime eval push + +# Push specific directory +prime eval push examples/verifiers_example + +# List all evaluations +prime eval list + +# Get evaluation details +prime eval get + +# View evaluation samples +prime eval samples +``` + +## API Reference + +### EvalsClient + +Main client for interacting with the Prime Evals API. + +**Methods:** + +| Method | Description | +|--------|-------------| +| `create_evaluation(...)` | Create a new evaluation | +| `push_samples(eval_id, samples)` | Push evaluation samples | +| `finalize_evaluation(eval_id, metrics)` | Finalize with final metrics | +| `get_evaluation(eval_id)` | Get evaluation details by ID | +| `list_evaluations(limit, offset)` | List evaluations with pagination | +| `get_samples(eval_id, page, limit)` | Get samples for an evaluation | + +### AsyncEvalsClient + +Async version of EvalsClient with the same methods (all async). + +### Models + +| Model | Description | +|-------|-------------| +| `Evaluation` | Full evaluation object with metadata | +| `Sample` | Individual evaluation sample with prompt/completion/scores | +| `CreateEvaluationRequest` | Request model for creating evaluations | +| `EvaluationStatus` | Enum: PENDING, RUNNING, COMPLETED, FAILED, CANCELLED | + +## Error Handling + +```python +from prime_evals import APIClient, EvalsClient, EvalsAPIError, EvaluationNotFoundError + +try: + api_client = APIClient() + client = EvalsClient(api_client) + client.get_evaluation("non-existent-id") +except EvaluationNotFoundError: + print("Evaluation not found") +except EvalsAPIError as e: + print(f"API error: {e}") +``` + diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..8a5da79b --- /dev/null +++ b/docs/index.md @@ -0,0 +1,53 @@ +# Docs + +This directory maintains the documentation for Prime CLI & SDKs. It is organized into the following sections: + +- [**Installation**](installation.md) - Installation instructions for CLI and SDKs +- [**Configuration**](configuration.md) - API key setup, SSH keys, and team configuration +- [**CLI**](cli.md) - Command-line interface reference for pods, sandboxes, and more +- [**Environments**](environments.md) - Access and manage verified environments on the community hub +- [**Sandboxes**](sandboxes.md) - Python SDK for remote code execution environments +- [**Evals**](evals.md) - SDK for pushing and managing evaluation results +- [**MCP Server**](mcp.md) - Model Context Protocol server for AI assistants + +## Overview + +Prime is the official CLI and Python SDK for [Prime Intellect](https://primeintellect.ai), providing seamless access to GPU compute infrastructure, remote code execution environments (sandboxes), and AI inference capabilities. + +**What can you do with Prime?** + +- Deploy GPU pods with H100, A100, and other high-performance GPUs +- Create and manage isolated sandbox environments for running code +- Access hundreds of pre-configured development environments +- SSH directly into your compute instances +- Manage team resources and permissions +- Push and track model evaluation results + +## Packages + +| Package | Description | Install | +|---------|-------------|---------| +| `prime` | Full CLI + SDK with pods, sandboxes, inference, and more | `uv tool install prime` | +| `prime-sandboxes` | Lightweight SDK for sandboxes only (~50KB) | `uv pip install prime-sandboxes` | +| `prime-evals` | SDK for managing evaluation results | `uv pip install prime-evals` | +| `prime-mcp-server` | MCP server for AI assistants | `uv pip install prime-mcp-server` | + +## Quick Start + +```bash +# Install uv (if not already installed) +curl -LsSf https://astral.sh/uv/install.sh | sh + +# Install prime +uv tool install prime + +# Authenticate +prime login + +# Browse verified environments +prime env list + +# List available GPU resources +prime availability list +``` + diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 00000000..c99db691 --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,122 @@ +# Installation + +## CLI Installation + +### Using uv (recommended) + +First, install uv if you haven't already: + +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh +``` + +Then install prime as a global tool: + +```bash +uv tool install prime +``` + +This installs the `prime` command globally, making it available from any directory. + +### Using pip + +```bash +pip install prime +``` + +### Verify Installation + +```bash +prime --version +prime --help +``` + +## SDK Installation + +### Sandboxes SDK + +If you only need the sandboxes SDK (lightweight, ~50KB): + +```bash +uv pip install prime-sandboxes +``` + +Or with pip: + +```bash +pip install prime-sandboxes +``` + +### Evals SDK + +For managing evaluation results: + +```bash +uv pip install prime-evals +``` + +Or with pip: + +```bash +pip install prime-evals +``` + +### MCP Server + +For AI assistant integration: + +```bash +uv pip install prime-mcp-server +``` + +Or with pip: + +```bash +pip install prime-mcp-server +``` + +## Development Installation + +For contributing to Prime CLI: + +```bash +# Clone the repository +git clone https://github.com/PrimeIntellect-ai/prime-cli +cd prime-cli + +# Set up workspace (installs all packages in editable mode) +uv sync + +# Install CLI globally in editable mode +uv tool install -e packages/prime + +# Now you can use the CLI directly +prime --help + +# Run tests +uv run pytest packages/prime/tests +uv run pytest packages/prime-sandboxes/tests +``` + +All packages (prime, prime-sandboxes, prime-evals, prime-mcp-server) are installed in editable mode. Changes to code are immediately reflected. + +## Updating + +### Update CLI + +```bash +uv tool upgrade prime +``` + +Or with pip: + +```bash +pip install --upgrade prime +``` + +### Update SDKs + +```bash +uv pip install --upgrade prime-sandboxes prime-evals +``` + diff --git a/docs/mcp.md b/docs/mcp.md new file mode 100644 index 00000000..5b93b15b --- /dev/null +++ b/docs/mcp.md @@ -0,0 +1,218 @@ +# MCP Server + +Model Context Protocol (MCP) server for Prime Intellect - manage GPU pods, check availability, and control compute resources through MCP-compatible AI assistants. + +## Features + +- **GPU Availability Checking** - Search for available GPU instances across providers +- **Pod Management** - Create, list, monitor, and delete GPU pods +- **Cluster Support** - Check multi-node cluster availability +- **SSH Key Management** - Manage SSH keys for pod access +- **Sandbox Operations** - Create and manage remote code execution environments + +## Installation + +```bash +uv pip install prime-mcp-server +``` + +Or with pip: + +```bash +pip install prime-mcp-server +``` + +## Configuration + +Prime MCP uses `prime-core` for configuration, which supports multiple authentication methods. + +### Option 1: Environment Variable + +```bash +export PRIME_API_KEY="your-api-key" +``` + +### Option 2: Prime CLI Login (Recommended) + +```bash +prime login +``` + +This stores your API key in `~/.prime/config.json` and is shared across all Prime tools. + +### Option 3: Config File + +Manually edit `~/.prime/config.json`: + +```json +{ + "api_key": "your-api-key", + "base_url": "https://api.primeintellect.ai" +} +``` + +## Running the Server + +```bash +python -m prime_mcp.mcp +``` + +The server runs over stdio and can be integrated with MCP clients (like Claude Desktop, Cursor, or other MCP-compatible tools). + +## Integration with Claude Desktop + +Add to your Claude Desktop configuration (`~/Library/Application Support/Claude/claude_desktop_config.json`): + +```json +{ + "mcpServers": { + "prime": { + "command": "python", + "args": ["-m", "prime_mcp.mcp"], + "env": { + "PRIME_API_KEY": "your-api-key" + } + } + } +} +``` + +## Integration with Cursor + +Add to your Cursor MCP configuration: + +```json +{ + "mcpServers": { + "primeintellect": { + "command": "uvx", + "args": ["prime-mcp-server"] + } + } +} +``` + +## Available Tools + +### GPU Availability + +| Tool | Description | +|------|-------------| +| `check_gpu_availability` | Search for available GPU instances | +| `check_cluster_availability` | Check multi-node cluster options | + +### Pod Management + +| Tool | Description | +|------|-------------| +| `list_pods` | List all pods in your account | +| `get_pod_details` | Get detailed pod information | +| `get_pods_status` | Get status of specific pods | +| `get_pods_history` | Get historical pod data | +| `create_pod` | Create a new GPU pod | +| `delete_pod` | Terminate a pod | + +### SSH Keys + +| Tool | Description | +|------|-------------| +| `manage_ssh_keys` | List, add, delete, or set primary SSH keys | + +### Sandboxes + +| Tool | Description | +|------|-------------| +| `create_sandbox` | Create a new sandbox environment | +| `list_sandboxes` | List all sandboxes | +| `get_sandbox` | Get sandbox details | +| `delete_sandbox` | Delete a sandbox | +| `bulk_delete_sandboxes` | Delete multiple sandboxes | +| `execute_sandbox_command` | Run commands in a sandbox | +| `get_sandbox_logs` | Get sandbox container logs | +| `expose_sandbox_port` | Expose a port to the internet | +| `unexpose_sandbox_port` | Remove port exposure | +| `list_sandbox_exposed_ports` | List exposed ports | + +### Docker Registry + +| Tool | Description | +|------|-------------| +| `list_registry_credentials` | List private registry credentials | +| `check_docker_image` | Validate Docker image accessibility | + +## Example Usage + +Once configured with an MCP client, you can interact naturally: + +**User:** "Show me available H100 GPUs" + +**Assistant:** Uses `check_gpu_availability` with `gpu_type="H100_80GB"` + +**User:** "Create a pod with 4 A100 GPUs for training" + +**Assistant:** +1. Checks SSH keys with `manage_ssh_keys` +2. Finds availability with `check_gpu_availability` +3. Creates pod with `create_pod` + +**User:** "Create a sandbox and run my Python script" + +**Assistant:** +1. Creates sandbox with `create_sandbox` +2. Waits for ready state with `get_sandbox` +3. Executes code with `execute_sandbox_command` + +## Development + +```bash +# Clone the repo +git clone https://github.com/PrimeIntellect-ai/prime-cli +cd prime-cli/packages/prime-mcp-server + +# Install dependencies +uv sync + +# Run tests +uv run pytest + +# Run linter +uv run ruff check . +``` + +## Troubleshooting + +### Authentication Errors + +Ensure your API key is correctly configured: + +```bash +# Check if key is set +echo $PRIME_API_KEY + +# Or verify config file +cat ~/.prime/config.json +``` + +### Server Not Starting + +Check Python path and package installation: + +```bash +# Verify installation +python -c "import prime_mcp; print(prime_mcp.__file__)" + +# Run with verbose output +python -m prime_mcp.mcp --debug +``` + +### MCP Client Not Connecting + +Verify the MCP configuration path and command: + +```bash +# Test the server directly +python -m prime_mcp.mcp + +# Should output MCP protocol messages +``` + diff --git a/docs/mint.json b/docs/mint.json new file mode 100644 index 00000000..a2a10ce3 --- /dev/null +++ b/docs/mint.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://mintlify.com/docs.json", + "navigation": [ + { + "group": "CLI", + "pages": [ + "index", + "installation", + "configuration", + "cli", + "environments", + "sandboxes", + "evals", + "mcp" + ] + } + ] +} + diff --git a/docs/sandboxes.md b/docs/sandboxes.md new file mode 100644 index 00000000..10d01d85 --- /dev/null +++ b/docs/sandboxes.md @@ -0,0 +1,285 @@ +# Sandboxes SDK + +Lightweight Python SDK for managing Prime Intellect sandboxes - secure remote code execution environments. + +## Features + +- **Synchronous and async clients** - Use with sync or async/await code +- **Full sandbox lifecycle** - Create, list, execute commands, upload/download files, delete +- **Type-safe** - Full type hints and Pydantic models +- **Authentication caching** - Automatic token management +- **Bulk operations** - Create and manage multiple sandboxes efficiently +- **No CLI dependencies** - Pure SDK, ~50KB installed + +## Installation + +```bash +uv pip install prime-sandboxes +``` + +Or with pip: + +```bash +pip install prime-sandboxes +``` + +## Quick Start + +```python +from prime_sandboxes import APIClient, SandboxClient, CreateSandboxRequest + +# Initialize +client = APIClient(api_key="your-api-key") +sandbox_client = SandboxClient(client) + +# Create a sandbox +request = CreateSandboxRequest( + name="my-sandbox", + docker_image="python:3.11-slim", + cpu_cores=2, + memory_gb=4, +) + +sandbox = sandbox_client.create(request) +print(f"Created: {sandbox.id}") + +# Wait for it to be ready +sandbox_client.wait_for_creation(sandbox.id) + +# Execute commands +result = sandbox_client.execute_command(sandbox.id, "python --version") +print(result.stdout) + +# Clean up +sandbox_client.delete(sandbox.id) +``` + +## Async Usage + +```python +import asyncio +from prime_sandboxes import AsyncSandboxClient, CreateSandboxRequest + +async def main(): + async with AsyncSandboxClient(api_key="your-api-key") as client: + # Create sandbox + sandbox = await client.create(CreateSandboxRequest( + name="async-sandbox", + docker_image="python:3.11-slim", + )) + + # Wait and execute + await client.wait_for_creation(sandbox.id) + result = await client.execute_command(sandbox.id, "echo 'Hello from async!'") + print(result.stdout) + + # Clean up + await client.delete(sandbox.id) + +asyncio.run(main()) +``` + +## Authentication + +The SDK looks for credentials in this order: + +1. **Direct parameter**: `APIClient(api_key="sk-...")` +2. **Environment variable**: `export PRIME_API_KEY="sk-..."` +3. **Config file**: `~/.prime/config.json` (created by `prime login` CLI command) + +## Environment Variables and Secrets + +```python +# Create sandbox with environment variables and secrets +request = CreateSandboxRequest( + name="my-sandbox", + docker_image="python:3.11-slim", + environment_vars={ + "DEBUG": "true", + "LOG_LEVEL": "info" + }, + secrets={ + "API_KEY": "sk-secret-key-here", + "DATABASE_PASSWORD": "super-secret-password" + } +) + +sandbox = sandbox_client.create(request) +``` + +**Note:** Secrets are never displayed in logs or outputs. When retrieving sandbox details, only the secret keys are shown with values masked as `***`. + +## File Operations + +```python +# Upload a file +sandbox_client.upload_file( + sandbox_id=sandbox.id, + file_path="/app/script.py", + local_file_path="./local_script.py" +) + +# Download a file +sandbox_client.download_file( + sandbox_id=sandbox.id, + file_path="/app/output.txt", + local_file_path="./output.txt" +) +``` + +## Bulk Operations + +```python +# Create multiple sandboxes +sandbox_ids = [] +for i in range(5): + sandbox = sandbox_client.create(CreateSandboxRequest( + name=f"sandbox-{i}", + docker_image="python:3.11-slim", + )) + sandbox_ids.append(sandbox.id) + +# Wait for all to be ready +statuses = sandbox_client.bulk_wait_for_creation(sandbox_ids) + +# Delete by IDs or labels +sandbox_client.bulk_delete(sandbox_ids=sandbox_ids) +# OR by labels +sandbox_client.bulk_delete(labels=["experiment-1"]) +``` + +## Labels & Filtering + +```python +# Create with labels +sandbox = sandbox_client.create(CreateSandboxRequest( + name="labeled-sandbox", + docker_image="python:3.11-slim", + labels=["experiment", "ml-training"], +)) + +# List with filters +sandboxes = sandbox_client.list( + status="RUNNING", + labels=["experiment"], + page=1, + per_page=50, +) + +for s in sandboxes.sandboxes: + print(f"{s.name}: {s.status}") +``` + +## Long-Running Tasks + +Use `start_background_job` to run long-running tasks that continue after the API call returns. Poll for completion with `get_background_job`. + +```python +from prime_sandboxes import SandboxClient, CreateSandboxRequest + +sandbox_client = SandboxClient() + +# Create sandbox with extended timeout +sandbox = sandbox_client.create(CreateSandboxRequest( + name="training-job", + docker_image="python:3.11-slim", + timeout_minutes=1440, # 24 hours + cpu_cores=4, + memory_gb=16, +)) +sandbox_client.wait_for_creation(sandbox.id) + +# Start a long-running job in the background +job = sandbox_client.start_background_job( + sandbox.id, + "python train.py --epochs 100" +) +print(f"Job started: {job.job_id}") + +# Poll for completion +import time +while True: + status = sandbox_client.get_background_job(sandbox.id, job) + if status.completed: + print(f"Job finished with exit code: {status.exit_code}") + print(status.stdout) + break + print("Still running...") + time.sleep(30) + +# Download results +sandbox_client.download_file(sandbox.id, "/app/model.pt", "./model.pt") +``` + +### Async Version + +```python +import asyncio +from prime_sandboxes import AsyncSandboxClient, CreateSandboxRequest + +async def run_training(): + async with AsyncSandboxClient() as client: + sandbox = await client.create(CreateSandboxRequest( + name="async-training", + docker_image="python:3.11-slim", + timeout_minutes=720, + )) + await client.wait_for_creation(sandbox.id) + + # Start background job + job = await client.start_background_job( + sandbox.id, + "python train.py" + ) + + # Poll until done + while True: + status = await client.get_background_job(sandbox.id, job) + if status.completed: + print(status.stdout) + break + await asyncio.sleep(30) + + await client.delete(sandbox.id) + +asyncio.run(run_training()) +``` + +## API Reference + +### SandboxClient + +Main synchronous client for sandbox operations. + +**Methods:** + +| Method | Description | +|--------|-------------| +| `create(request)` | Create a new sandbox | +| `get(sandbox_id)` | Get sandbox details | +| `list(...)` | List sandboxes with filters | +| `delete(sandbox_id)` | Delete a sandbox | +| `execute_command(sandbox_id, command)` | Execute command | +| `upload_file(sandbox_id, file_path, local_file_path)` | Upload file | +| `download_file(sandbox_id, file_path, local_file_path)` | Download file | +| `wait_for_creation(sandbox_id)` | Wait for sandbox ready | +| `bulk_wait_for_creation(sandbox_ids)` | Wait for multiple sandboxes | +| `bulk_delete(sandbox_ids, labels)` | Delete multiple sandboxes | +| `start_background_job(sandbox_id, command)` | Start long-running job | +| `get_background_job(sandbox_id, job)` | Get job status | + +### AsyncSandboxClient + +Async version with identical methods (all async). + +### Models + +| Model | Description | +|-------|-------------| +| `CreateSandboxRequest` | Request model for creating sandboxes | +| `Sandbox` | Full sandbox object with metadata | +| `SandboxStatus` | Enum: PENDING, PROVISIONING, RUNNING, STOPPED, ERROR, TERMINATED | +| `CommandResult` | Result of command execution | +| `BackgroundJob` | Background job handle | +| `BackgroundJobStatus` | Job completion status | +