84 lines
2.8 KiB
Python
84 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
_PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
_DEFAULT_ALLOWED_MIME_TYPES = (
|
|
"image/*",
|
|
"audio/*",
|
|
"application/pdf",
|
|
"text/html",
|
|
"application/xhtml+xml",
|
|
"text/plain",
|
|
"text/markdown",
|
|
"text/csv",
|
|
"application/json",
|
|
"application/msword",
|
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
"application/vnd.ms-excel",
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"application/vnd.ms-powerpoint",
|
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class GatewayConfig:
|
|
backend_base_url: str = "http://127.0.0.1:1995"
|
|
database_path: Path = _PROJECT_ROOT / "data" / "memory_gateway.sqlite3"
|
|
storage_dir: Path = _PROJECT_ROOT / "data" / "storage"
|
|
resource_search_batch_size: int = 50
|
|
max_upload_bytes: int = 25 * 1024 * 1024
|
|
allowed_mime_types: tuple[str, ...] = _DEFAULT_ALLOWED_MIME_TYPES
|
|
backend_ingest_attempts: int = 3
|
|
backend_retry_delay_seconds: float = 0.25
|
|
backend_timeout_seconds: float = 120.0
|
|
|
|
@classmethod
|
|
def from_env(cls) -> GatewayConfig:
|
|
allowed_mime_types = tuple(
|
|
item.strip()
|
|
for item in os.environ.get(
|
|
"MEMORY_GATEWAY_ALLOWED_MIME_TYPES",
|
|
",".join(_DEFAULT_ALLOWED_MIME_TYPES),
|
|
).split(",")
|
|
if item.strip()
|
|
)
|
|
return cls(
|
|
backend_base_url=os.environ.get(
|
|
"MEMORY_GATEWAY_BACKEND_BASE_URL",
|
|
"http://127.0.0.1:1995",
|
|
).rstrip("/"),
|
|
database_path=Path(
|
|
os.environ.get(
|
|
"MEMORY_GATEWAY_DB_PATH",
|
|
str(_PROJECT_ROOT / "data" / "memory_gateway.sqlite3"),
|
|
)
|
|
),
|
|
storage_dir=Path(
|
|
os.environ.get(
|
|
"MEMORY_GATEWAY_STORAGE_DIR",
|
|
str(_PROJECT_ROOT / "data" / "storage"),
|
|
)
|
|
),
|
|
resource_search_batch_size=int(
|
|
os.environ.get("MEMORY_GATEWAY_RESOURCE_SEARCH_BATCH_SIZE", "50")
|
|
),
|
|
max_upload_bytes=int(
|
|
os.environ.get("MEMORY_GATEWAY_MAX_UPLOAD_BYTES", str(25 * 1024 * 1024))
|
|
),
|
|
allowed_mime_types=allowed_mime_types,
|
|
backend_ingest_attempts=int(
|
|
os.environ.get("MEMORY_GATEWAY_BACKEND_INGEST_ATTEMPTS", "3")
|
|
),
|
|
backend_retry_delay_seconds=float(
|
|
os.environ.get("MEMORY_GATEWAY_BACKEND_RETRY_DELAY_SECONDS", "0.25")
|
|
),
|
|
backend_timeout_seconds=float(
|
|
os.environ.get("MEMORY_GATEWAY_BACKEND_TIMEOUT_SECONDS", "120")
|
|
),
|
|
)
|