open-webui / pipelines

Pipelines: Versatile, UI-Agnostic OpenAI-Compatible Plugin Framework
MIT License
1.01k stars 319 forks source link

Add PIPELINES_ENV #316

Open azdolinski opened 3 weeks ago

azdolinski commented 3 weeks ago

Enhance the start.sh script to recognize and utilize the PIPELINES_ENV environment variable as follows:

This change will accommodate both development and production environments seamlessly.

sir3mat commented 2 weeks ago

is it possible to add env for uvicorn options? It could be useful to increase the number of workers like this fastapi with workers

azdolinski commented 2 weeks ago

@sir3mat - yes... it should be possible... env like PIPELINES_WORKERS

based on docs - https://github.com/defunkt/unicorn/blob/master/README "unicorn can spawn and manage any number of worker processes you choose to scale to your backend." https://www.engineyard.com/blog/everything-you-need-to-know-about-unicorn/

it could be somthing like this...

if [ "$PIPELINES_ENV" = "production" ] || [ -z "$PIPELINES_ENV" ]; then
    if [ "$PIPELINES_WORKERS" = "auto" ]; then
        CPU_COUNT=$(nproc)
        WORKERS=$((2 * CPU_COUNT + 1))
    else
        WORKERS="${PIPELINES_WORKERS:-1}"
    fi

    uvicorn main:app --host "$HOST" --port "$PORT" --workers "$WORKERS" --forwarded-allow-ips '*'
else
    echo "INFO:     Running in development mode"
    # "workers" flag will be ignored when reloading is enabled.
    uvicorn main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' --reload
fi

i will try to check that later... but now i need also support venv for requirments and that is on my top task list

azdolinski commented 2 weeks ago

New Environment Variables for start.sh

  1. PIPELINES_ENV (string)

    • Description: Specifies the environment mode in which the application should run. It typically toggles between configurations optimized for development or production. If set to any value other than "production", uvicorn will be configured to run with 1 worker and the --reload flag. Information about this flag can be found in the uvicorn development documentation.
    • Default Value: production
    • Default Usage: Often not set, it defaults to production mode if not explicitly defined.
  2. PIPELINES_WORKERS (number|auto)

    • Description: Determines the number of worker processes to handle tasks. It helps in managing parallel processes to optimize resource usage.
    • Default Value: uvicorn starts by default only with 1 worker.
    • Default Usage: In some setups, this might switch to auto, which calculates the ideal number of workers based on available CPU cores.
  3. PIPELINES_VENV (boolean)

    • Description: Controls whether a virtual environment should be used for executing pipelines.
    • Default Value: False
    • Example Usage: Setting this to True will ensure that the pipelines run within a specified virtual environment.
  4. PIPELINES_VENV_AUTOUPGRADE (boolean)

    • Description: Indicates if automatic upgrades should occur for pip and package dependencies defined in requirements.txt when using a virtual environment. This parameter makes sense only if you are using a permanent volume for the venv folder.
    • Default Value: False
    • Example Usage: Set to True to enable the automatic pip and package upgrade process during start.
  5. PIPELINES_VENV_PATH (os path string)

    • Description: Defines the path where the virtual environment is stored or should be created.
    • Default Value: Typically set to ${PIPELINES_DIR}/venv, aligning with the directory structure of the pipelines.
    • Example Usage: Customizing this path allows for alternate locations of the virtual environment if needed.
sir3mat commented 1 week ago

Is it possible to enable also the "workers" params in openwebui interface?

azdolinski commented 1 week ago

@sir3mat Pipelines is a separate, dedicated container and project. The number of pipeline workers is a parameter set at the start of the pipelines container and needs to be predefined at startup. Settings such as env parameters SHOULD NOT be influenced or driven by other projects from the outside; instead, they should be defined by the administrator during the startup process, as these env parameters impact how the entire system behaves.