S SmartDocs
シリーズ: Ricky python 66 行 · 更新日 2026-03-23

runtime.py

Ricky/RAG_project/config/runtime.py

"""
Runtime configuration: all RAG_* environment-variable accessors in one place.
Import from here instead of scattering os.getenv calls across modules.
"""
import os


def get_llm_timeout() -> int:
    return int(os.getenv("RAG_LLM_TIMEOUT", "300"))


def get_retriever_k() -> int:
    return int(os.getenv("RAG_RETRIEVER_K", "4"))


def get_max_tokens() -> int:
    return int(os.getenv("RAG_MAX_TOKENS", "160"))


def get_image_top_n() -> int:
    return max(1, int(os.getenv("RAG_IMAGE_TOP_N", "1")))


def get_confidence_threshold() -> float:
    value = float(os.getenv("RAG_CONFIDENCE_THRESHOLD", "0.7"))
    return min(max(value, 0.0), 1.0)


def is_keyword_enabled() -> bool:
    return os.getenv("RAG_ENABLE_KEYWORD", "1") == "1"


def is_force_rebuild() -> bool:
    return os.getenv("RAG_FORCE_REBUILD", "0") == "1"


def is_warmup_enabled() -> bool:
    return os.getenv("RAG_WARMUP", "0") == "1"


def is_voice_input_enabled() -> bool:
    return os.getenv("RAG_VOICE_INPUT", "0") == "1"


def prefer_openrouter() -> bool:
    return os.getenv("RAG_PREFER_OPENROUTER", "1") == "1"


def is_auto_open_image() -> bool:
    return os.getenv("RAG_AUTO_OPEN_IMAGE", "1") == "1"


def get_open_image_count() -> int:
    return max(1, int(os.getenv("RAG_OPEN_IMAGE_COUNT", "1")))


def get_voice_language() -> str:
    return os.getenv("RAG_VOICE_LANGUAGE", "yue-Hant-HK")


def get_voice_timeout() -> int:
    return int(os.getenv("RAG_VOICE_TIMEOUT", "6"))


def get_voice_phrase_time_limit() -> int:
    return int(os.getenv("RAG_VOICE_PHRASE_TIME_LIMIT", "20"))

関連記事