File size: 1,647 Bytes
4f9e155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from dataclasses import dataclass


@dataclass
class Config:
    api_key: str
    model_path: str
    # 视觉语言模型 - 本地
    vl_model_path: str
    # 视觉语言模型 - 在线 API (DashScope)
    vl_api_base: str
    vl_api_key: str
    vl_api_model: str
    vl_use_api: bool
    # 在线 API 最大调用次数限制(防止被刷爆,超出后自动降级到本地模型)
    vl_api_max_calls: int
    # 无论是否使用在线 API,始终加载本地 Qwen3-VL-2B-Instruct 模型
    vl_always_load_local: bool
    # 服务
    host: str
    port: int
    gradio_port: int
    device: str


def load_config() -> Config:
    return Config(
        api_key=os.getenv("XGUARD_API_KEY", "your-api-key"),
        model_path=os.getenv("XGUARD_MODEL_PATH", "Alibaba-AAIG/YuFeng-XGuard-Reason-0.6B"),
        vl_model_path=os.getenv("XGUARD_VL_MODEL_PATH","Qwen/Qwen3-VL-2B-Instruct"),
        vl_api_base=os.getenv("XGUARD_VL_API_BASE", "https://dashscope.aliyuncs.com/compatible-mode/v1"),
        vl_api_key=os.getenv("XGUARD_VL_API_KEY", ""),
        vl_api_model=os.getenv("XGUARD_VL_API_MODEL", "qwen-vl-max-latest"),
        vl_use_api=os.getenv("XGUARD_VL_USE_API", "false").lower() in ("true", "1", "yes"),
        vl_api_max_calls=int(os.getenv("XGUARD_VL_API_MAX_CALLS", "")),
        vl_always_load_local=os.getenv("XGUARD_VL_ALWAYS_LOAD_LOCAL", "true").lower() in ("true", "1", "yes"),
        host=os.getenv("XGUARD_HOST", "0.0.0.0"),
        port=int(os.getenv("XGUARD_PORT", "8080")),
        gradio_port=int(os.getenv("XGUARD_GRADIO_PORT", "7860")),
        device=os.getenv("XGUARD_DEVICE", "auto"),
    )