48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
DATA_DIR = ROOT / "data"
|
|
STATIC_DIR = ROOT / "static"
|
|
|
|
EMBEDDING_MODEL = "BAAI/bge-small-zh-v1.5"
|
|
COLLECTION_NAME = "knowledge_bge_small_zh_v15"
|
|
CHUNK_SIZE = 360
|
|
CHUNK_OVERLAP = 60
|
|
DEFAULT_TOP_K = 4
|
|
LOW_SCORE = 0.45
|
|
|
|
os.environ.setdefault("ANONYMIZED_TELEMETRY", "False")
|
|
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
|
|
|
|
|
def load_dotenv() -> None:
|
|
path = ROOT / ".env"
|
|
if not path.exists():
|
|
return
|
|
for raw in path.read_text(encoding="utf-8").splitlines():
|
|
line = raw.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
key, value = line.split("=", 1)
|
|
key = key.strip()
|
|
value = value.strip().strip('"').strip("'")
|
|
if key and key not in os.environ:
|
|
os.environ[key] = value
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
def llm_config() -> dict | None:
|
|
key = os.getenv("OPENAI_API_KEY", "").strip()
|
|
if not key:
|
|
return None
|
|
base = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1").strip()
|
|
model = os.getenv("OPENAI_MODEL", "gpt-4o-mini").strip()
|
|
return {
|
|
"key": key,
|
|
"base": (base or "https://api.openai.com/v1").rstrip("/"),
|
|
"model": model or "gpt-4o-mini",
|
|
}
|