Load and cache project settings.
()
| 53 | data_dir.mkdir(parents=True, exist_ok=True) |
| 54 | sessions_dir.mkdir(parents=True, exist_ok=True) |
| 55 | runtime_logs_dir.mkdir(parents=True, exist_ok=True) |
| 56 | |
| 57 | return Settings( |
| 58 | app_host=os.getenv("APP_HOST", "127.0.0.1").strip() or "127.0.0.1", |
| 59 | app_port=_parse_int(os.getenv("APP_PORT", "8787"), field_name="APP_PORT"), |
| 60 | data_dir=data_dir, |
| 61 | runtime_logs_dir=runtime_logs_dir, |
| 62 | accounts_path=data_dir / "accounts.json", |
| 63 | tasks_path=data_dir / "tasks.json", |
| 64 | sessions_dir=sessions_dir, |
| 65 | bigmodel_api_base=os.getenv("BIGMODEL_API_BASE", "https://www.bigmodel.cn/api").rstrip("/"), |
| 66 | bigmodel_origin=os.getenv("BIGMODEL_ORIGIN", "https://www.bigmodel.cn").rstrip("/"), |
| 67 | bigmodel_referer=os.getenv("BIGMODEL_REFERER", "https://www.bigmodel.cn/glm-coding").strip(), |
| 68 | browser_impersonate=os.getenv("BROWSER_IMPERSONATE", "chrome124").strip() or "chrome124", |
| 69 | request_timeout_seconds=_parse_float( |
| 70 | os.getenv("REQUEST_TIMEOUT_SECONDS", "20"), |
| 71 | field_name="REQUEST_TIMEOUT_SECONDS", |
| 72 | ), |
| 73 | default_language=os.getenv("DEFAULT_LANGUAGE", "zh-CN").strip() or "zh-CN", |
| 74 | tencent_captcha_domain=os.getenv( |
| 75 | "TENCENT_CAPTCHA_DOMAIN", |
| 76 | "https://turing.captcha.qcloud.com", |
| 77 | ).rstrip("/"), |
| 78 | tencent_captcha_aid=os.getenv("TENCENT_CAPTCHA_AID", "196026326").strip() or "196026326", |
| 79 | tencent_captcha_entry_url=os.getenv( |
| 80 | "TENCENT_CAPTCHA_ENTRY_URL", |
| 81 | "https://www.bigmodel.cn/glm-coding", |
| 82 | ).strip() |
| 83 | or "https://www.bigmodel.cn/glm-coding", |
| 84 | tencent_captcha_max_retries=_parse_int( |
| 85 | os.getenv("TENCENT_CAPTCHA_MAX_RETRIES", "3"), |
| 86 | field_name="TENCENT_CAPTCHA_MAX_RETRIES", |
| 87 | ), |
| 88 | tencent_captcha_min_confidence=_parse_float( |
| 89 | os.getenv("TENCENT_CAPTCHA_MIN_CONFIDENCE", "0.55"), |
| 90 | field_name="TENCENT_CAPTCHA_MIN_CONFIDENCE", |
| 91 | ), |
| 92 | tencent_captcha_node=os.getenv("TENCENT_CAPTCHA_NODE", "node").strip() or "node", |
| 93 | tencent_ocr_enabled=_parse_bool(os.getenv("TENCENT_OCR_ENABLED", "1")), |
| 94 | tencent_ocr_include_debug=_parse_bool(os.getenv("TENCENT_OCR_INCLUDE_DEBUG", "0")), |
| 95 | tencent_ocr_workers=_parse_int( |
| 96 | os.getenv("TENCENT_OCR_WORKERS", str(max(1, min(4, os.cpu_count() or 1)))), |
| 97 | field_name="TENCENT_OCR_WORKERS", |
| 98 | ), |
| 99 | tencent_ocr_timeout_seconds=_parse_int( |
| 100 | os.getenv("TENCENT_OCR_TIMEOUT_SECONDS", "6"), |
| 101 | field_name="TENCENT_OCR_TIMEOUT_SECONDS", |
| 102 | ), |
| 103 | runtime_log_level=os.getenv("RUNTIME_LOG_LEVEL", "INFO").strip() or "INFO", |
| 104 | runtime_log_retention_days=_parse_int( |
| 105 | os.getenv("RUNTIME_LOG_RETENTION_DAYS", "7"), |
| 106 | field_name="RUNTIME_LOG_RETENTION_DAYS", |
| 107 | ), |
| 108 | ) |
| 109 | |
| 110 | |
| 111 | def _resolve_path(raw: str) -> Path: |
| 112 | normalized = (raw or "").strip() |
no test coverage detected