Open WebUI Pipelines

repository·main·Indexed 25 days ago

https://github.com/open-webui/pipelines

A framework for extending Open WebUI with custom pipelines to enhance LLM capabilities and integrations. It provides an OpenAI-compatible chat completions endpoint, a plugin system for arbitrary code execution via Python modules, and support for filter inlet/outlet hooks. The system includes tools for managing pipeline lifecycles via API, configuring 'valves' for settings, and automated dependency installation from module frontmatter. Deployment is supported via Docker Compose and a dedicated start.sh script.

Tokens
2.1K
Snippets
2
Records
15
Agent score
81%

What's inside open-webui-pipelines

  1. Secure Pipelines Execution Best Practices

    main

    Because Pipelines function as a plugin system with arbitrary code execution capabilities, you should follow these security best practices to mitigate risks:

    1. Use Trusted Sources: Only fetch and execute Pipelines from sources you trust. Avoid running Pipelines from unknown or untrusted origins.
    2. Use Fixed Versions: Rather than always pulling the latest version of a Pipeline, use a specific, audited version to ensure you are running code that has been verified for stability and security.
    3. Leverage Sandboxing: Pipelines are executed within a sandboxed environment designed to limit access to system resources and prevent harm to the host system.
    4. Code Review: Ensure any custom Pipelines you implement undergo a thorough code review process.
    5. Monitor Execution: Continuously monitor Pipeline execution for any suspicious or malicious activity.
  2. Set up the LangGraph Stream Pipeline

    main

    Follow these steps to deploy the LangGraph integration:

    1. Upload the pipeline file: Upload langgraph_stream_pipeline.py to your Open WebUI Pipelines instance.
    2. Configure the URL: Set up your LangGraph API URL in the pipeline settings.
    3. Select the model: In the Open WebUI interface, choose "LangGraph stream" as your model.
    4. Install Python dependencies: Navigate to the pipeline directory and install the required packages:
      pip install -r requirements.txt
    5. Start the LangGraph API server: Run the example application using uvicorn:
      uvicorn langgraph_example:app --reload
    pip install -r requirements.txt
    
    uvicorn langgraph_example:app --reload
  3. Implement filter inlet and outlet hooks

    main

    Pipelines of type filter can intercept and modify request/response bodies using inlet and outlet methods.

    • inlet: Called before the main processing. It receives the request body and user information, allowing you to modify the input.
    • outlet: Called after the main processing. It receives the processed body and user information, allowing you to modify the output.

    These are exposed via the following endpoints:

    • POST /v1/{pipeline_id}/filter/inlet
    • POST /v1/{pipeline_id}/filter/outlet
  4. Automatic dependency installation from Pipeline frontmatter

    main

    The start.sh script automatically detects and installs Python dependencies defined within the pipeline files themselves. It looks for a requirements: key inside the first triple-quoted block (""" ... """) of any .py file located in the PIPELINES_DIR.

    Example of a compatible pipeline file structure:

    """
    requirements: requests, numpy, pandas
    """
    
    class MyPipeline:
        ... 
  5. Deploy Open WebUI and Pipelines using Docker Compose

    main

    You can deploy the full stack using the provided docker-compose.yaml. This setup includes two services: openwebui (the main interface) and pipelines (the backend for processing pipelines).

    Service Configuration

    openwebui

    • Image: ghcr.io/open-webui/open-webui:main
    • Ports: Maps host port 3000 to container port 8080.
    • Volumes: Persists data at /app/backend/data using the open-webui volume.

    pipelines

    • Image: ghcr.io/open-webui/pipelines:main
    • Restart Policy: Set to always to ensure the service recovers from failures.
    • Volumes: Persists pipeline data/code at /app/pipelines using the pipelines volume.
    • Environment Variables:
      • PIPELINES_API_KEY: A required key used to secure communication with the pipelines service. The default in this file is 0p3n-w3bu!.
    services:
      openwebui:
          image: ghcr.io/open-webui/open-webui:main
          ports:
            - "3000:8080"
          volumes:
            - open-webui:/app/backend/data
    
      pipelines:
          image: ghcr.io/open-webui/pipelines:main
          volumes:
            - pipelines:/app/pipelines
          restart: always
          environment:
            - PIPELINES_API_KEY=0p3n-w3bu!
    
    volumes:
      open-webui: {}
      pipelines: {}
  6. Start the Pipelines service using start.sh

    main

    The start.sh script is the primary entrypoint for managing the Pipelines service. It supports three modes to control the lifecycle of the service: downloading pipelines, installing dependencies, and running the Uvicorn server.

    Execution Modes

    Use the --mode flag to specify how the script should behave:

    • setup: Only performs the setup tasks (resetting the directory, installing requirements, and downloading/installing pipelines).
    • run: Only starts the Uvicorn server.
    • full (default): Performs both setup and run.

    Environment Variables

    You can configure the service behavior using the following environment variables:

    • PORT: The port to run the service on (default: 9099).
    • HOST: The host address (default: 0.0.0.0).
    • PIPELINES_DIR: The directory where pipelines are stored (default: ./pipelines).
    • PIPELINES_REQUIREMENTS_PATH: Path to a requirements.txt file to install before starting.
    • PIPELINES_URLS: A semicolon-separated list (;) of GitHub URLs or direct .py file URLs to download as pipelines.
    • RESET_PIPELINES_DIR: Set to true to wipe the PIPELINES_DIR before setup.
    • UVICORN_LOOP: The loop class for Uvicorn (default: auto).
  7. Manage pipelines via API

    main
    The Pipelines API allows you to dynamically manage the lifecycle of pipeline modules. You can add pipelines from a URL, upload local Python files, delete existing pipelines, or reload the entire pipeline registry. Most management endpoints require a valid API_KEY for authorization.
  8. Pipeline module structure and requirements

    main

    Pipelines are Python modules loaded from the PIPELINES_DIR. To support dependencies, you can include a requirements string in the module's docstring frontmatter. The loader will automatically install these using pip before loading the module.

    Example module structure with requirements:

    """
    requirements: requests, numpy
    """
    
    class Pipeline:
        def __init__(self):
            self.valves = MyValves()
        # ... other methods
    """
  9. Configure the PIPELINES_API_KEY environment variable

    main
    The PIPELINES_API_KEY environment variable is used by the pipelines service to authenticate requests. When using Docker Compose, you should define this under the environment section of the pipelines service to ensure secure connectivity between Open WebUI and the Pipelines backend.
  10. Configure Pipelines via PIPELINES_URLS

    main

    The PIPELINES_URLS environment variable allows you to automate the retrieval of pipeline files. The script supports three types of URLs:

    1. GitHub Blob URLs: (e.g., https://github.com/owner/repo/blob/main/file.py) The script downloads the raw file content.
    2. GitHub Tree URLs: (e.g., https://github.com/owner/repo/tree/main/subdir) The script performs a sparse git clone to download only the specified subdirectory.
    3. Direct Python Files: (e.g., https://example.com/pipeline.py) The script downloads the file via curl.

    URLs should be separated by a semicolon (;).