summaryrefslogtreecommitdiff
path: root/src/ollama_web/config.py
blob: ac567a28b2f6187fbab6c60be3f6a7201a8e5590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Application configuration for ollama-web."""

from __future__ import annotations

import os
import secrets
from dataclasses import dataclass, field


def _csv_env(name: str) -> list[str]:
    raw = os.environ.get(name, "")
    return [part.strip() for part in raw.split(",") if part.strip()]


@dataclass
class Settings:
    """Runtime settings resolved from environment variables."""

    ollama_host: str = field(default_factory=lambda: os.environ.get("OLLAMA_HOST", "http://127.0.0.1:11434"))
    default_model: str = field(
        default_factory=lambda: os.environ.get("OLLAMA_WEB_MODEL", "llama3.2")
    )
    host: str = field(default_factory=lambda: os.environ.get("OLLAMA_WEB_HOST", "127.0.0.1"))
    port: int = field(default_factory=lambda: int(os.environ.get("OLLAMA_WEB_PORT", "8000")))
    data_dir: str = field(
        default_factory=lambda: os.environ.get("OLLAMA_WEB_DATA_DIR", "data")
    )
    max_upload_mb: int = field(
        default_factory=lambda: int(os.environ.get("OLLAMA_WEB_MAX_UPLOAD_MB", "20"))
    )
    pin: str = field(
        default_factory=lambda: os.environ.get("OLLAMA_WEB_PIN") or secrets.token_urlsafe(6)
    )
    pin_generated: bool = field(default_factory=lambda: "OLLAMA_WEB_PIN" not in os.environ)
    secret_key: str = field(
        default_factory=lambda: os.environ.get("OLLAMA_WEB_SECRET_KEY") or secrets.token_urlsafe(32)
    )
    allowed_origins: list[str] = field(
        default_factory=lambda: _csv_env("OLLAMA_WEB_ALLOWED_ORIGINS")
    )
    mcp_stdio_allowlist: list[str] = field(
        default_factory=lambda: _csv_env("OLLAMA_WEB_MCP_STDIO_ALLOWLIST")
    )
    mcp_https_allowlist: list[str] = field(
        default_factory=lambda: _csv_env("OLLAMA_WEB_MCP_HTTPS_ALLOWLIST")
    )
    ollama_timeout: float = 120.0
    scrape_timeout: float = 15.0
    scrape_max_chars: int = 4000
    search_max_results: int = 5
    fetch_max_results: int = 3
    fetch_max_chars: int = 8000
    max_fetch_mb: int = 10
    max_pdf_pages: int = 25
    max_message_chars: int = 20000
    max_attachment_text_chars: int = 20000
    max_image_pixels: int = 16_000_000
    max_tool_result_chars: int = 3000


settings = Settings()
"""Process-wide settings instance."""