File size: 3,048 Bytes
3844d2f
 
 
072e615
 
 
 
 
 
ad78733
 
 
 
 
 
 
 
 
 
 
 
 
 
3844d2f
 
 
 
072e615
 
3844d2f
 
 
3f6ba20
 
ad78733
 
3844d2f
ad78733
 
 
 
 
3844d2f
ad78733
 
 
3844d2f
072e615
 
 
 
 
 
ad78733
 
 
 
 
3844d2f
ad78733
3844d2f
ad78733
 
 
 
 
072e615
3844d2f
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os


def to_bool(value: str, default: bool = False) -> bool:
    if value is None:
        return default
    return str(value).strip().lower() in {"true", "1", "yes", "on"}


def to_int(value: str, default: int) -> int:
    try:
        return int(str(value).strip())
    except Exception:
        return default


def to_float(value: str, default: float) -> float:
    try:
        return float(str(value).strip())
    except Exception:
        return default


class Settings:
    APP_NAME = "Chat7 CodeX Backend"
    APP_VERSION = "1.0.0"

    PRIMARY_CODE_MODEL = os.getenv("PRIMARY_CODE_MODEL", "Qwen/Qwen2.5-7B-Instruct")
    FALLBACK_CODE_MODEL = os.getenv("FALLBACK_CODE_MODEL", "Qwen/Qwen2.5-3B-Instruct")

    GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "")
    STACKOVERFLOW_KEY = os.getenv("STACKOVERFLOW_KEY", "")
    HUGGINGFACE_API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN", "")

    MODEL_TIMEOUT_SECONDS = to_int(os.getenv("MODEL_TIMEOUT_SECONDS", "90"), 90)
    SEARCH_TIMEOUT_SECONDS = to_int(os.getenv("SEARCH_TIMEOUT_SECONDS", "20"), 20)

    MAX_HISTORY_ITEMS = to_int(os.getenv("MAX_HISTORY_ITEMS", "5"), 5)
    MAX_CODE_CHARS = to_int(os.getenv("MAX_CODE_CHARS", "25000"), 25000)
    MAX_ERROR_CHARS = to_int(os.getenv("MAX_ERROR_CHARS", "8000"), 8000)
    MAX_MESSAGE_CHARS = to_int(os.getenv("MAX_MESSAGE_CHARS", "6000"), 6000)
    MAX_PREVIOUS_CONTEXT_CHARS = to_int(os.getenv("MAX_PREVIOUS_CONTEXT_CHARS", "6000"), 6000)

    MAX_STACK_RESULTS = to_int(os.getenv("MAX_STACK_RESULTS", "5"), 5)
    MAX_GITHUB_RESULTS = to_int(os.getenv("MAX_GITHUB_RESULTS", "5"), 5)
    MAX_RETRIEVED_ITEMS = to_int(os.getenv("MAX_RETRIEVED_ITEMS", "8"), 8)

    ENABLE_STACK_SEARCH = to_bool(os.getenv("ENABLE_STACK_SEARCH", "true"), True)
    ENABLE_GITHUB_SEARCH = to_bool(os.getenv("ENABLE_GITHUB_SEARCH", "true"), True)
    ENABLE_RETRIEVAL_FOR_FIX = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_FIX", "true"), True)
    ENABLE_RETRIEVAL_FOR_DEBUG = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_DEBUG", "true"), True)
    ENABLE_RETRIEVAL_FOR_GENERATE = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_GENERATE", "false"), False)
    ENABLE_RETRIEVAL_FOR_EXPLAIN = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_EXPLAIN", "false"), False)
    ENABLE_RETRIEVAL_FOR_REVIEW = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_REVIEW", "false"), False)
    ENABLE_RETRIEVAL_FOR_REFACTOR = to_bool(os.getenv("ENABLE_RETRIEVAL_FOR_REFACTOR", "false"), False)

    DEFAULT_TEMPERATURE = to_float(os.getenv("DEFAULT_TEMPERATURE", "0.2"), 0.2)
    DEFAULT_TOP_P = to_float(os.getenv("DEFAULT_TOP_P", "0.9"), 0.9)

    MAX_OUTPUT_TOKENS = to_int(os.getenv("MAX_OUTPUT_TOKENS", "1200"), 1200)

    PRESERVE_SYMBOL_NAMES_BY_DEFAULT = to_bool(
        os.getenv("PRESERVE_SYMBOL_NAMES_BY_DEFAULT", "true"),
        True,
    )
    ENABLE_SCOPE_GUARD = to_bool(os.getenv("ENABLE_SCOPE_GUARD", "true"), True)

    ALLOWED_TASK_TYPES = {
        "generate",
        "fix",
        "explain",
        "refactor",
        "review",
        "unknown",
    }


settings = Settings()