Skip to main content

CLI tool and Model Server for VirtueAI VirtueRed

Project description

VirtueRed

VirtueRed is a comprehensive package for the VirtueAI Redteaming system, providing both a CLI tool and a Model Server.

Release History

Version 2.1.1 (2025-09-10)

Enhanced

  • Model Server now supports configurable timeout parameters: connection_limit (default: 1000), cleanup_interval (default: 3600s), and channel_timeout (default: 6000s). These can be configured when initializing the ModelServer class.

Version 2.1.0 (2025-07-25)

Fixed

  • Resolved an issue where the Web UI could not connect to its configured backend URL.

Added

  • The Web UI now displays a warning banner with troubleshooting information when a scan is terminated early.

Installation

pip install virtuered

Components

1. Model Server

The Model Server allows you to serve your custom models for use with the VirtueRed system.

Usage

from virtuered.client import ModelServer

# Start the model server
server = ModelServer(
    port=4299,                  # Optional, defaults to 4299
    connection_limit=1000,       # Optional, defaults to 1000
    cleanup_interval=3600,       # Optional, defaults to 3600 seconds
    channel_timeout=6000         # Optional, defaults to 6000 seconds
)
server.start()

Local Model Setup

  1. Create a models directory:
models/
├── model1.py
└── model2.py
  1. Create a new Python file in the ./models folder with a descriptive name for your model, e.g., model1.py. Create a function called chat in model1.py, the chat function will takes a list of chat messages and returns the response from the language model. For example, if we want to create a chat function with LLAMA-3-8b from huggingface:
import os
from transformers import pipeline, LlamaTokenizer, LlamaForCausalLM

# Step 1: Load the LLaMA model and tokenizer
model_name = "meta-llama/Meta-Llama-3-8B"  # Replace with the actual model name on Hugging Face Hub
tokenizer = LlamaTokenizer.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(model_name)

# Initialize the Hugging Face pipeline with the model and tokenizer
chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer)

# Don't change the name of the function or the function signature
def chat(chats):
    """
    This function takes a list of chat messages and returns the response from the language model.
    
    Parameters:
    chats (list): A list of dictionaries. Each dictionary contains a "prompt" and optionally an "answer".
                  The last item in the list should have a "prompt" without an "answer".
    
    Returns:
    str: The response from the language model.
    
    Example of `chats` list with few-shot prompts:
    [
        {"prompt": "Hello, how are you?", "answer": "I'm an AI, so I don't have feelings, but thanks for asking!"},
        {"prompt": "What is the capital of France?", "answer": "The capital of France is Paris."},
        {"prompt": "Can you tell me a joke?"}
    ]
    
    Another example of `chats` list with one-shot prompt:
    [
        {"prompt": "What is the weather like today?"}
    ]
    """
    
    # Step 2: Prepare the chat history as a single string
    chat_history = []
    for c in chats:
        # Add the user prompt and assistant's answer to the chat history
        chat_history.append({"role": "user", "content": c["prompt"]})
        if "answer" in c.keys():
            chat_history.append({"role": "assistant", "content": c["answer"]})
        else:
            # If there is no answer, it means this is the prompt we need a response for
            break
    
    # Step 3: Generate the model's response
    response = chatbot(chat_history, max_length=1000, num_return_sequences=1)
    
    # Step 4: Extract and return the generated text
    generated_text = response[0]['generated_text']
    assistant_response = generated_text.split("Assistant:")[-1].strip()
    
    return assistant_response 

2. CLI Tool

The CLI tool provides a command-line interface for managing VirtueRed operations.

CLI Commands

# View all available commands
virtuered --help

# Configure a custom server address instead of the default http://localhost:4401(persistent)
virtuered config http://localhost:4403
virtuered show-config

# List all runs
virtuered list

# List all custom models
virtuered models

# Monitor ongoing scans
virtuered monitor

# Initialize a new scan
virtuered scan                # Uses default scan_config.json
virtuered scan myconfig.json  # Uses custom config file

# Get summary of a run
virtuered summary my_scan
virtuered summary 1

# Pause/Resume a scan
virtuered pause my_scan
virtuered resume 1

# Generate report
virtuered report my_scan

# Delete a run
virtuered delete 1

# For temporary custom server URL:
virtuered --server http://localhost:4403 list

Available Commands

  • --help: View all available commands
  • config: Set persistent default server URL
  • show-config: View current configuration
  • list: Show all runs
  • models: Show all custom models
  • scan: Initialize a new scan using configuration file
  • monitor: Monitor ongoing scans
  • summary: Get detailed summary of a run
  • report: Generate PDF report
  • pause: Pause a running scan
  • resume: Resume a paused scan
  • delete: Delete a run

Scan Configuration

Create a JSON configuration file (scan_config.json or custom name) before initiating a scan:

{
    "name": "my_scan",
    "model": "together_template",
    "datasets": [
        {
            "name": "EU Artificial Intelligence Act",
            "subcategories": [
                "Criminal justice/Predictive policing",
                "Persons (including murder)"
            ]
        },
        {
            "name": "White House AI Executive Order"
        }
    ],
    "extra_args": {
        "modelname": "model name",
        "apikey": "your-api-key"
    }
}

Configuration Fields:

  • Required:
    • name: Unique scan identifier (alphanumeric and underscores only)
    • model: Model specification (local or cloud-hosted template)
    • datasets: Array of at least one dataset object with name field
  • Optional:
    • subcategories: Array of specific subcategories to evaluate within each dataset
    • extra_args: Additional parameters for cloud-based models (credentials, settings)

Architecture

The package consists of two main components:

  1. Model Server: Serves your custom models, making them accessible to the VirtueRed system
  2. CLI Tool: Provides command-line interface for managing VirtueRed operations

The typical setup involves:

  1. Running the Model Server to serve your custom models
  2. Running the VirtueRed Docker container, configured to connect to your Model Server
  3. Using the CLI tool to manage and monitor operations

Notes

  • The Model Server must be running and accessible to the Docker container
  • For local setup, use http://127.0.0.1:4299 as client address
  • For remote setup, use http://<server-ip>:4299 as client address
  • Ensure your models directory is properly structured with required model files

Support

If you need further assistance, please contact our support team at contact@virtueai.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

virtuered-2.1.1.tar.gz (7.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

virtuered-2.1.1-py3-none-any.whl (7.1 MB view details)

Uploaded Python 3

File details

Details for the file virtuered-2.1.1.tar.gz.

File metadata

  • Download URL: virtuered-2.1.1.tar.gz
  • Upload date:
  • Size: 7.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for virtuered-2.1.1.tar.gz
Algorithm Hash digest
SHA256 b631be65b496d52d86c9e288ed145c009a059fea0c2eba0e2c81db710441274b
MD5 359bf429e611a6159ce2b44e12045d95
BLAKE2b-256 e6a5e11a0c22657ba4059686c7080456e88142115ef7b184889362377b674509

See more details on using hashes here.

File details

Details for the file virtuered-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: virtuered-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for virtuered-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92a73e35ba4b98ac7cc70f447f469f6682938bf4b13529cd0237299eb57a3bb0
MD5 fb21930a9df61a4c423786eaa4c1e15b
BLAKE2b-256 16bed89d73de0b4b5a7b2033b45ccc71ecd527f6c3343f22f6e2957685686874

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page