diff --git a/.env.example b/.env.example index eaa5bd2..b2da321 100644 --- a/.env.example +++ b/.env.example @@ -53,14 +53,14 @@ AUTH_COOKIE_EXPIRE_TIME_SECONDS=604800 # 7 days ### Signs password reset, email verification, OAuth login state, and captcha cookies. ### REQUIRED: the API server refuses to start with an empty value (secure by default). ### If using install.sh this is auto-generated; if setting manually, run: openssl rand -hex 32 -USER_AUTH_SECRET= +USER_AUTH_SECRET=$(openssl rand -hex 16) ### Recommend to set this for security -# ENCRYPTION_KEY_SECRET= +ENCRYPTION_KEY_SECRET=$(openssl rand -hex 32) ### Bearer token for the API server's /metrics endpoint. Auth is REQUIRED by ### default: scrapers must send `Authorization: Bearer ` (Prometheus ### scrape config: `authorization`). If you set neither this token nor ### DISABLE_METRICS_AUTH, /metrics is locked (returns 401). -# METRICS_AUTH_TOKEN= +METRICS_AUTH_TOKEN=$(openssl rand -hex 32) ### Set to "true" to expose /metrics with NO authentication (explicit opt-out). # DISABLE_METRICS_AUTH= ### Set to "true" to expose the interactive API docs and schema (/openapi.json, @@ -97,8 +97,14 @@ ENABLE_PAID_ENTERPRISE_EDITION_FEATURES=false ## SERVICES CONFIGURATIONS ################################################################################ ## Database Configuration -POSTGRES_USER=postgres -POSTGRES_PASSWORD= +POSTGRES_USER=onyx-admin +POSTGRES_PASSWORD=$(openssl rand -hex 16) +POSTGRES_API_SERVER_POOL_SIZE=30 # Tune for your load +POSTGRES_API_SERVER_POOL_OVERFLOW=10 +POSTGRES_TCP_KEEPALIVES=1 # Enable keepalives +POSTGRES_TCP_KEEPALIVES_IDLE=60 # 60 seconds idle +POSTGRES_TCP_KEEPALIVES_INTERVAL=10 # 10 seconds between probes +POSTGRES_TCP_KEEPALIVES_COUNT=5 # 5 probes before disconnect # POSTGRES_DB= # POSTGRES_DEFAULT_SCHEMA= # POSTGRES_USE_NULL_POOL= @@ -118,7 +124,7 @@ POSTGRES_PASSWORD= ## File Store Backend: "s3" (default, uses MinIO) or "postgres" (no extra services needed) ## COMPOSE_PROFILES activates the MinIO service. To use PostgreSQL file storage instead, ## remove s3-filestore from COMPOSE_PROFILES and set FILE_STORE_BACKEND=postgres. -COMPOSE_PROFILES=s3-filestore +#COMPOSE_PROFILES=s3-filestore FILE_STORE_BACKEND=s3 ## MinIO/S3 Configuration (only needed when FILE_STORE_BACKEND=s3) @@ -126,6 +132,7 @@ FILE_STORE_BACKEND=s3 ## edit .env by hand, change all four values before production. Keep the S3_AWS_* ## pair identical to MINIO_ROOT_* (the app uses MinIO's root creds). S3_ENDPOINT_URL= +S3_REGION= S3_AWS_ACCESS_KEY_ID= S3_AWS_SECRET_ACCESS_KEY= S3_FILE_STORE_BUCKET_NAME= @@ -147,9 +154,9 @@ S3_FILE_STORE_BUCKET_NAME= ## Nginx Proxy Timeout Configuration (in seconds) ## These settings control how long nginx waits for upstream servers (api_server/web_server) ## Increase these values if you experience timeout errors with long-running requests -# NGINX_PROXY_CONNECT_TIMEOUT=300 -# NGINX_PROXY_SEND_TIMEOUT=300 -# NGINX_PROXY_READ_TIMEOUT=300 +NGINX_PROXY_CONNECT_TIMEOUT=600 # 10 minutes (complex AI queries) +NGINX_PROXY_SEND_TIMEOUT=600 +NGINX_PROXY_READ_TIMEOUT=600 ## MCP Server Configuration ## The MCP (Model Context Protocol) server allows external MCP clients to interact with Onyx @@ -199,7 +206,7 @@ LOG_ONYX_MODEL_INTERACTIONS=False # LOG_ENDPOINT_LATENCY= # LOG_POSTGRES_LATENCY= # LOG_POSTGRES_CONN_COUNTS= -# DISABLE_TELEMETRY= +DISABLE_TELEMETRY=true ## Feature Flags SHOW_EXTRA_CONNECTORS=true @@ -239,7 +246,7 @@ OAUTH_CLIENT_ID= OAUTH_CLIENT_SECRET= OPENID_CONFIG_URL= OIDC_PKCE_ENABLED=true -TRACK_EXTERNAL_IDP_EXPIRY=false +TRACK_EXTERNAL_IDP_EXPIRY=true OIDC_SCOPE_OVERRIDE=openid,email,profile,offline_access # Comma-separated list of origins allowed to make cross-origin (CORS) requests, # e.g. "https://onyx.example.com". When unset, all origins are allowed but @@ -250,13 +257,21 @@ CORS_ALLOWED_ORIGIN= ## Gen AI Settings GEN_AI_MAX_TOKENS=250000 -# LLM_SOCKET_READ_TIMEOUT= +LLM_SOCKET_READ_TIMEOUT=600 # MAX_CHUNKS_FED_TO_CHAT= -# DISABLE_LITELLM_STREAMING= +DISABLE_LITELLM_STREAMING=false # LITELLM_EXTRA_HEADERS= # GEN_AI_API_KEY= -# GENERATIVE_MODEL_ACCESS_CHECK_FREQ= -# LITELLM_CUSTOM_ERROR_MESSAGE_MAPPINGS= +GENERATIVE_MODEL_ACCESS_CHECK_FREQ=300 # 5 minutes +LITELLM_CUSTOM_ERROR_MESSAGE_MAPPINGS={ + "RateLimitError": "Service is temporarily busy. Please try again in a moment.", + "Timeout": "Request took too long. Please try with a shorter query.", + "AuthenticationError": "AI service authentication failed. Contact your administrator.", + "BadRequestError": "Invalid request format. Please rephrase your query.", + "InternalServerError": "Temporary service issue. Please retry shortly." +} +LITELLM_PROXY_API_KEY=${LITELLM_MASTER_KEY} +LITELLM_PROXY_API_BASE=http://litellm-proxy:4000 ## Query Options # DOC_TIME_DECAY= @@ -321,4 +336,12 @@ REDIS_HOST=cache MODEL_SERVER_HOST=inference_model_server INDEXING_MODEL_SERVER_HOST=indexing_model_server INTERNAL_URL=http://api_server:8080 -ENABLE_CONTEXTUAL_RAG=true \ No newline at end of file +ENABLE_CONTEXTUAL_RAG=true + +# LiteLLM Proxy Settings +LITELLM_MASTER_KEY=sk-$(openssl rand -hex 32) +LITELLM_SALT_KEY=$(openssl rand -hex 32) +LITELLM_DATABASE_URL=postgresql://llmproxy:${LITELLM_POSTGRES_PASSWORD}@litellm-db:5432/litellm +LITELLM_POSTGRES_PASSWORD=$(openssl rand -hex 16) +LITELLM_INFOMANIAK_API_KEY= +LITELLM_REDIS_PASSWORD=$(openssl rand -hex 16) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ce52f21..67d1765 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,9 +39,6 @@ name: onyx services: api_server: image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}} - build: - context: ../../backend - dockerfile: Dockerfile command: > /bin/sh -c "alembic upgrade head && echo \"Starting Onyx Api Server\" && uvicorn onyx.main:app --host 0.0.0.0 --port 8080" @@ -115,9 +112,6 @@ services: - ./file-system:/app/file-system background: image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}} - build: - context: ../../backend - dockerfile: Dockerfile command: | /bin/sh -c " if [ -f /etc/ssl/certs/custom-ca.crt ]; then update-ca-certificates; @@ -147,10 +141,10 @@ services: - REDIS_HOST=${REDIS_HOST:-cache} - MODEL_SERVER_HOST=${MODEL_SERVER_HOST:-inference_model_server} - INDEXING_MODEL_SERVER_HOST=${INDEXING_MODEL_SERVER_HOST:-indexing_model_server} - - S3_ENDPOINT_URL=${S3_ENDPOINT_URL:-http://minio:9000} - - S3_REGION=us-east-1 - - S3_AWS_ACCESS_KEY_ID=${S3_AWS_ACCESS_KEY_ID:-minioadmin} - - S3_AWS_SECRET_ACCESS_KEY=${S3_AWS_SECRET_ACCESS_KEY:-minioadmin} + - S3_ENDPOINT_URL=${S3_ENDPOINT_URL} + - S3_REGION=${S3_REGION} + - S3_AWS_ACCESS_KEY_ID=${S3_AWS_ACCESS_KEY_ID} + - S3_AWS_SECRET_ACCESS_KEY=${S3_AWS_SECRET_ACCESS_KEY} - DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN:-} - DISCORD_BOT_INVOKE_CHAR=${DISCORD_BOT_INVOKE_CHAR:-!} # API Server connection for Discord bot message processing @@ -286,18 +280,6 @@ services: inference_model_server: image: ${ONYX_MODEL_SERVER_IMAGE:-onyxdotapp/onyx-model-server:${IMAGE_TAG:-latest}} - build: - context: ../../backend - dockerfile: Dockerfile.model_server - # GPU Support: Uncomment the following lines to enable GPU support - # Requires nvidia-container-toolkit to be installed on the host - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [gpu] command: > /bin/sh -c "if [ \"${DISABLE_MODEL_SERVER:-}\" = \"True\" ] || [ \"${DISABLE_MODEL_SERVER:-}\" = \"true\" ]; then @@ -337,18 +319,6 @@ services: start_period: 600s indexing_model_server: image: ${ONYX_MODEL_SERVER_IMAGE:-onyxdotapp/onyx-model-server:${IMAGE_TAG:-latest}} - build: - context: ../../backend - dockerfile: Dockerfile.model_server - # GPU Support: Uncomment the following lines to enable GPU support - # Requires nvidia-container-toolkit to be installed on the host - # deploy: - # resources: - # reservations: - # devices: - # - driver: nvidia - # count: all - # capabilities: [gpu] command: > /bin/sh -c "if [ \"${DISABLE_MODEL_SERVER:-}\" = \"True\" ] || [ \"${DISABLE_MODEL_SERVER:-}\" = \"true\" ]; then @@ -496,9 +466,6 @@ services: # the writable /etc/nginx/conf.d/ inside the container. This avoids # "Permission denied" errors on Windows Docker bind mounts. - ./data/nginx:/nginx-templates:ro - # PRODUCTION: Add SSL certificate volumes for HTTPS support: - # - ../data/certbot/conf:/etc/letsencrypt - # - ../data/certbot/www:/var/www/certbot logging: driver: json-file options: @@ -528,13 +495,6 @@ services: cache: image: ${BASE_IMAGE_REGISTRY:-docker.io}/library/redis:7.4-alpine restart: unless-stopped - # DEV: To expose ports, either: - # 1. Use docker-compose.dev.yml: docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --wait - # 2. Uncomment the ports below - # ports: - # - "6379:6379" - # docker silently mounts /data even without an explicit volume mount, which enables - # persistence. explicitly setting save and appendonly forces ephemeral behavior. command: redis-server --save "" --appendonly no networks: - onyx-network @@ -561,22 +521,99 @@ services: user: root volumes: - ${DOCKER_SOCK_PATH:-/var/run/docker.sock}:/var/run/docker.sock - # uncomment below + comment out the above to use the `docker-in-docker` execution mode - # privileged: true - # PRODUCTION: Uncomment the following certbot service for SSL certificate management - # certbot: - # image: certbot/certbot - # restart: unless-stopped - # volumes: - # - ../data/certbot/conf:/etc/letsencrypt - # - ../data/certbot/www:/var/www/certbot - # logging: - # driver: json-file - # options: - # max-size: "50m" - # max-file: "6" - # entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" + # litellm proxy + litellm-proxy: + image: docker.litellm.ai/berriai/litellm:main-stable + restart: unless-stopped + volumes: + - ./litellm-config.yaml:/app/config.yaml + command: > + --config /app/config.yaml + --port 4000 + --num_workers 4 + --max_requests_before_restart 10000 + --max_requests_before_restart_jitter 1000 + --run_gunicorn + networks: + - litellm-network + - onyx-network + environment: + - INFOMANIAK_API_KEY=${LITELLM_INFOMANIAK_API_KEY} + - LITELLM_MASTER_KEY=${LITELLM_MASTER_KEY} + - REDIS_HOST=litellm-redis + - REDIS_PORT=6379 + - REDIS_PASSWORD=${LITELLM_REDIS_PASSWORD} + - LITELLM_SALT_KEY=${LITELLM_SALT_KEY} + - LITELLM_MODE=PRODUCTION + - LITELLM_LOG=ERROR + - NUM_WORKERS=4 + - MAX_REQUESTS_BEFORE_RESTART=10000 + - MAX_REQUESTS_BEFORE_RESTART_JITTER=1000 + - DATABASE_URL=${LITELLM_DATABASE_URL} + env_file: + - .env # Load local .env file + depends_on: + - litellm-db # Indicates that this service depends on the 'db' service, ensuring 'db' starts first + - litellm-redis + healthcheck: + # Defines the health check configuration for the container + test: + - CMD-SHELL + - python3 -c "import urllib.request; + urllib.request.urlopen('http://localhost:4000/health/liveliness')" # Command to execute for health check + interval: 30s # Perform health check every 30 seconds + timeout: 10s # Health check command times out after 10 seconds + retries: 3 # Retry up to 3 times if health check fails + start_period: 60s # Wait 40 seconds after container start before beginning health checks + deploy: + resources: + limits: + cpus: '2.0' + memory: 2G + reservations: + cpus: '0.5' + memory: 512M + litellm-db: + image: postgres:16 + restart: unless-stopped + environment: + POSTGRES_DB: litellm + POSTGRES_USER: llmproxy + POSTGRES_PASSWORD: ${LITELLM_POSTGRES_PASSWORD} + networks: + - litellm-network + volumes: + - ./litellm_postgres_data:/var/lib/postgresql/data # Persists Postgres data across container restarts + healthcheck: + test: + - CMD-SHELL + - pg_isready -d litellm -U llmproxy + interval: 10s + timeout: 5s + retries: 10 + litellm-redis: + image: redis:7-alpine + restart: unless-stopped + environment: + - REDIS_HOST=litellm-redis + - REDIS_PORT=6379 + - REDIS_SSL=False + networks: + - litellm-network + volumes: + - ./litellm_redis_data:/data + healthcheck: + test: + - CMD + - redis-cli + - -a + - ${LITELLM_REDIS_PASSWORD} + - ping + interval: 5s + timeout: 3s + retries: 5 + command: redis-server --requirepass ${LITELLM_REDIS_PASSWORD} --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru volumes: # Persistent data for OpenSearch. @@ -586,6 +623,8 @@ volumes: networks: onyx-network: driver: bridge + litellm-network: + driver: bridge web: name: web external: true diff --git a/litellm-config.yaml b/litellm-config.yaml new file mode 100644 index 0000000..9ae62a2 --- /dev/null +++ b/litellm-config.yaml @@ -0,0 +1,234 @@ +general_settings: + master_key: os.environ/LITELLM_MASTER_KEY + database_url: os.environ/DATABASE_URL + store_model_in_db: true + store_prompts_in_spend_logs: false + use_redis_transaction_buffer: true # Required for high traffic (1000+ RPS) [1] + user_api_key_cache_ttl: 300 # Optional: TTL for API key auth cache [2] + enable_redis_auth_cache: true + allow_requests_on_db_unavailable: true + json_logs: true +# LiteLLM Proxy Configuration for Infomaniak AI API +# Base URL: https://api.infomaniak.com/2/ai/105341/openai/v1 + +model_list: + # Primary Model: Qwen3.5 (LivQwen) + - model_name: LivQwen + litellm_params: + model: openai/Qwen/Qwen3.5-397B-A17B-FP8 + api_base: https://api.infomaniak.com/2/ai/105341/openai/v1 + api_key: os.environ/INFOMANIAK_API_KEY + rpm: 50 + tpm: 100000 + timeout: 600 + max_retries: 3 + retry_policy: + RateLimitError: 5 + Timeout: 3 + APIConnectionError: 3 + model_info: + id: "infomaniak-qwen-1" + base_model: "Qwen/Qwen3.5-397B-A17B-FP8" + # Model capabilities (Infomaniak doesn't provide these via API) + input_cost_per_token: 0.0 # Set based on Infomaniak pricing + output_cost_per_token: 0.0 + max_tokens: 200000 + input_cost_per_second: 0.0 + output_cost_per_second: 0.0 + # Capabilities + supports_vision: true # Qwen3.5 has vision capabilities + supports_reasoning: true # Qwen3.5 has enhanced reasoning + supports_function_calling: true + supports_parallel_function_calling: true + supports_response_schema: true + supports_system_messages: true + supports_tool_choice: true + supports_web_search: false # Unless Infomaniak enables it + supports_prompt_caching: false + supports_embedding: false + supports_audio_input: false + supports_audio_output: false + supports_computer_use: false + # Model family info + mode: "chat" + model_group: "qwen-family" + region: "eu-west" # Infomaniak is Switzerland-based + + # Secondary Model: Kimi-K2.6 (LivKimi) + - model_name: LivKimi + litellm_params: + model: openai/moonshotai/Kimi-K2.6 + api_base: https://api.infomaniak.com/2/ai/105341/openai/v1 + api_key: os.environ/INFOMANIAK_API_KEY + rpm: 50 + tpm: 100000 + timeout: 600 + max_retries: 3 + retry_policy: + RateLimitError: 5 + Timeout: 3 + APIConnectionError: 3 + model_info: + id: "infomaniak-kimi-1" + base_model: "moonshotai/Kimi-K2.6" + # Model capabilities + input_cost_per_token: 0.0 + output_cost_per_token: 0.0 + max_tokens: 256000 + input_cost_per_second: 0.0 + output_cost_per_second: 0.0 + # Capabilities + supports_vision: true # Kimi K2.5+ supports vision + supports_reasoning: true # Strong reasoning capabilities + supports_function_calling: true + supports_parallel_function_calling: true + supports_response_schema: true + supports_system_messages: true + supports_tool_choice: true + supports_web_search: false + supports_prompt_caching: false + supports_embedding: false + supports_audio_input: false + supports_audio_output: false + supports_computer_use: false + # Model family info + mode: "chat" + model_group: "kimi-family" + region: "eu-west" + + # Tertiary Model: Gemma-4 (LivGemma) + - model_name: LivGemma + litellm_params: + model: openai/google/gemma-4-31B-it + api_base: https://api.infomaniak.com/2/ai/105341/openai/v1 + api_key: os.environ/INFOMANIAK_API_KEY + rpm: 50 + tpm: 100000 + timeout: 600 + max_retries: 3 + retry_policy: + RateLimitError: 5 + Timeout: 3 + APIConnectionError: 3 + model_info: + id: "infomaniak-gemma-1" + base_model: "google/gemma-4-31B-it" + # Model capabilities + input_cost_per_token: 0.0 + output_cost_per_token: 0.0 + max_tokens: 100000 + input_cost_per_second: 0.0 + output_cost_per_second: 0.0 + # Capabilities + supports_vision: false # Gemma-4-31B-it is text-only + supports_reasoning: false # Basic reasoning, not enhanced + supports_function_calling: true + supports_parallel_function_calling: false + supports_response_schema: true + supports_system_messages: true + supports_tool_choice: true + supports_web_search: false + supports_prompt_caching: false + supports_embedding: false + supports_audio_input: false + supports_audio_output: false + supports_computer_use: false + # Model family info + mode: "chat" + model_group: "gemma-family" + region: "eu-west" + +# Cost-Optimized Model: Nemotron-3-Nano (LivNemotron) + # Best for: high-volume tasks like Onyx contextual retrieval, classification, + # summarization, and any workload where cost matters more than + # peak reasoning quality. + # Infomaniak pricing (CHF): 0.05 / 1M input tokens | 0.20 / 1M output tokens + - model_name: LivNemotron + litellm_params: + model: openai/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-FP8 + api_base: https://api.infomaniak.com/2/ai/105341/openai/v1 + api_key: os.environ/INFOMANIAK_API_KEY + rpm: 50 + tpm: 100000 + timeout: 600 + max_retries: 3 + retry_policy: + RateLimitError: 5 + Timeout: 3 + APIConnectionError: 3 + model_info: + id: "infomaniak-nemotron-nano-1" + base_model: "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-FP8" + input_cost_per_token: 0.0 + output_cost_per_token: 0.0 + max_tokens: 128000 + input_cost_per_second: 0.0 + output_cost_per_second: 0.0 + # Capabilities + supports_vision: false # Text-only model + supports_reasoning: false # Standard instruction following, not deep reasoning + supports_function_calling: true # Basic tool use supported + supports_parallel_function_calling: false + supports_response_schema: true + supports_system_messages: true + supports_tool_choice: true + supports_web_search: false + supports_prompt_caching: false + supports_embedding: false + supports_audio_input: false + supports_audio_output: false + supports_computer_use: false + # Model family info + mode: "chat" + model_group: "nemotron-family" + region: "eu-west" + + +router_settings: + redis_host: litellm-redis + redis_port: 6379 + redis_password: os.environ/REDIS_PASSWORD + routing_strategy: simple-shuffle + num_retries: 3 + retry_after: 5 + allowed_fails: 3 + cooldown_time: 30 + enable_pre_call_checks: true + + # Retry policy for different error types + retry_policy: + RateLimitErrorRetries: 5 + TimeoutErrorRetries: 3 + AuthenticationErrorRetries: 0 + BadRequestErrorRetries: 1 + InternalServerErrorRetries: 4 + + # Allowed fails policy before cooldown + allowed_fails_policy: + BadRequestErrorAllowedFails: 1000 + AuthenticationErrorAllowedFails: 5 + TimeoutErrorAllowedFails: 12 + RateLimitErrorAllowedFails: 10000 + InternalServerErrorAllowedFails: 20 + + fallbacks: + - LivQwen: [LivKimi, LivGemma] + - LivKimi: [LivGemma, LivQwen] + - LivGemma: [LivKimi, LivQwen] + +# LiteLLM module settings +litellm_settings: + drop_params: false + set_verbose: false + request_timeout: 600 + num_retries: 3 + cache: true # Enable caching [2] + cache_params: + type: redis + host: litellm-redis + port: 6379 + password: os.environ/REDIS_PASSWORD + ttl: 3600 + namespace: "litellm.livtec.caching" + redact_user_api_key_info: true + turn_off_message_logging: false \ No newline at end of file