Security: deep /api/health (DB+MinIO probes, 503 on failure) + /api/live; rate-limited public forms with honeypots; real client IP behind Traefik (--proxy-headers); TipTap URL sanitization on write (nh3); non-root containers + slim .dockerignore; prod MinIO console bound to 127.0.0.1; HSTS/nosniff on TLS routers; JWT 8h; no default credentials in code. Reliability: Alembic migrations (create_all baseline); graceful shutdown (exec uvicorn); hardened backups (checksums, sanity check, freshness gauge, optional rclone off-site) + restore.sh + hourly db-backup sidecar (ops profile); stack.sh ops tooling (deploy/logs/health/backup/restore/monitoring); .gitattributes LF for shell scripts. Orchestration: json-file log rotation, pinned images, per-service memory limits, edge/internal networks, Traefik ping/accesslog/metrics + flood limiter, conditional minio-setup, pgvector db image, one-shot db-init (umami + aramesh_chatbot databases). Chatbot: unified from site-chatbot branch (RAG + pgvector, SSE, ChatWidget). Monitoring: Prometheus/Alertmanager/Loki/Promtail/Grafana + cAdvisor, node/postgres/blackbox exporters, provisioned dashboards and 10 alert rules; alerts delivered to Bale (tapi.bale.ai — Telegram-compatible). Analytics: Umami on shared Postgres, build-time tracker injection, custom events (contact/newsletter/phone/chat/lang) via frontend/src/analytics.ts. Hygiene: CSV export for contact messages and subscribers; upload image optimization (Pillow); CI script + GitHub-compatible workflow; audit.sh; gen-env.sh for strong credentials.
58 lines
2.9 KiB
Python
58 lines
2.9 KiB
Python
"""تنظیمات سرویس چتبات — از متغیرهای محیطی یا فایل .env خوانده میشود."""
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
|
|
|
# دیتابیس سایت (فقط خواندن) — همان DATABASE_URL بکاند
|
|
database_url: str = "postgresql+psycopg://aramesh:aramesh@localhost:5432/arameshplaza"
|
|
# دیتابیس اختصاصی چتبات روی همان نمونه Postgres — بردارها اینجا نوشته میشوند
|
|
# تا دیتابیس سایت فقطخواندنی بماند؛ در شروع سرویس خودکار ساخته میشود
|
|
chatbot_db_name: str = "aramesh_chatbot"
|
|
|
|
# LLM سازگار با OpenAI — اجباری؛ بدون آن پاسخگویی غیرفعال است
|
|
llm_base_url: str = ""
|
|
llm_api_key: str = ""
|
|
llm_model: str = "openai/gpt-oss-120b"
|
|
|
|
# مدلهای بازیابی
|
|
embedding_model: str = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
|
# بعد بردار خروجی مدل امبدینگ (MiniLM-L12 = 384) — با تغییر مدل باید عوض شود
|
|
embedding_dim: int = 384
|
|
reranker_model: str = "BAAI/bge-reranker-v2-m3"
|
|
reranker_enabled: bool = True
|
|
reranker_device: str = "cpu"
|
|
|
|
# وزن جستوجوی معنایی در ترکیب نمرهها (۰ = فقط کلیدواژه، ۱ = فقط معنایی)
|
|
alpha_dense: float = 0.5
|
|
# تعداد سند نهایی که به LLM داده میشود
|
|
best_of_k: int = 3
|
|
# تعداد نتیجه هر پایگاه (معنایی و کلیدواژه) برای هر پرسوجو
|
|
retrieve_k: int = 12
|
|
# بازنویسی پرسوجو با تاریخچه گفتگو (فقط وقتی تاریخچه هست صدا زده میشود)
|
|
contextualize_enabled: bool = True
|
|
# گسترش پرسوجو به چند نوع — برای پیکره کوچک پیشفرض خاموش (تأخیر کمتر)
|
|
query_expansion: bool = False
|
|
|
|
# مسیر کش مدلها (در داکر روی والیوم /data سوار میشود)
|
|
hf_cache_dir: str = "/data/hf"
|
|
|
|
# محدودسازی نرخ درخواست هر IP (تعداد پیام در پنجره زمانی به ثانیه)
|
|
rate_limit_messages: int = 20
|
|
rate_limit_window: int = 300
|
|
|
|
# توکن بازسازی ایندکس — اگر خالی باشد مسیر reindex فقط از داخل شبکه کار میکند
|
|
reindex_token: str = ""
|
|
|
|
# ماندگاری کش پیشنهادها و زمینه سایت (ثانیه)
|
|
suggestions_ttl: int = 600
|
|
site_context_ttl: int = 120
|
|
|
|
# بازسازی خودکار ایندکس وقتی محتوای دیتابیس عوض شود (۰ = خاموش)
|
|
index_refresh_seconds: int = 600
|
|
|
|
|
|
settings = Settings()
|