ZyphrZero
commited on
Commit
·
6e09c2f
1
Parent(s):
7561cf7
♻️ refactor(config): enhance configuration management with environment variables
Browse files- modified docker-compose.yml to remove redundant DEBUG_MODE setting
- improved debug logging to show partial auth token for better security
- converted static configuration values to dynamic environment-based configuration
- standardized configuration handling across deployment and application code
- deploy/docker-compose.yml +1 -2
- main.py +14 -13
deploy/docker-compose.yml
CHANGED
|
@@ -9,10 +9,9 @@ services:
|
|
| 9 |
ports:
|
| 10 |
- "8080:8080"
|
| 11 |
environment:
|
| 12 |
-
- DEBUG_MODE=false
|
| 13 |
# Auth Configuration
|
| 14 |
- AUTH_TOKEN=sk-your-api-key
|
| 15 |
-
# Server
|
| 16 |
- DEBUG_LOGGING=true
|
| 17 |
# Feature Configuration
|
| 18 |
- THINKING_PROCESSING=think
|
|
|
|
| 9 |
ports:
|
| 10 |
- "8080:8080"
|
| 11 |
environment:
|
|
|
|
| 12 |
# Auth Configuration
|
| 13 |
- AUTH_TOKEN=sk-your-api-key
|
| 14 |
+
# Server Configurations
|
| 15 |
- DEBUG_LOGGING=true
|
| 16 |
# Feature Configuration
|
| 17 |
- THINKING_PROCESSING=think
|
main.py
CHANGED
|
@@ -9,6 +9,7 @@ to the Z.AI chat service with proper authentication and response formatting.
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
import json
|
|
|
|
| 12 |
import re
|
| 13 |
import time
|
| 14 |
from datetime import datetime
|
|
@@ -28,24 +29,24 @@ class ServerConfig:
|
|
| 28 |
"""Centralized server configuration"""
|
| 29 |
|
| 30 |
# API Configuration
|
| 31 |
-
API_ENDPOINT: str = "https://chat.z.ai/api/chat/completions"
|
| 32 |
-
AUTH_TOKEN: str = "sk-your-api-key"
|
| 33 |
-
BACKUP_TOKEN: str = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMxNmJjYjQ4LWZmMmYtNGExNS04NTNkLWYyYTI5YjY3ZmYwZiIsImVtYWlsIjoiR3Vlc3QtMTc1NTg0ODU4ODc4OEBndWVzdC5jb20ifQ.PktllDySS3trlyuFpTeIZf-7hl8Qu1qYF3BxjgIul0BrNux2nX9hVzIjthLXKMWAf9V0qM8Vm_iyDqkjPGsaiQ"
|
| 34 |
|
| 35 |
# Model Configuration
|
| 36 |
-
PRIMARY_MODEL: str = "GLM-4.5"
|
| 37 |
-
THINKING_MODEL: str = "GLM-4.5-Thinking"
|
| 38 |
-
SEARCH_MODEL: str = "GLM-4.5-Search"
|
| 39 |
|
| 40 |
# Server Configuration
|
| 41 |
-
LISTEN_PORT: int = 8080
|
| 42 |
-
DEBUG_LOGGING: bool =
|
| 43 |
|
| 44 |
# Feature Configuration
|
| 45 |
-
THINKING_PROCESSING: str = "think" # strip: 去除<details>标签;think: 转为</think>标签;raw: 保留原样
|
| 46 |
-
ANONYMOUS_MODE: bool =
|
| 47 |
-
TOOL_SUPPORT: bool =
|
| 48 |
-
SCAN_LIMIT: int = 200000
|
| 49 |
|
| 50 |
# Browser Headers
|
| 51 |
CLIENT_HEADERS: Dict[str, str] = {
|
|
@@ -1062,7 +1063,7 @@ async def chat_completions(
|
|
| 1062 |
debug_log(f"无效的API key: {api_key}")
|
| 1063 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
| 1064 |
|
| 1065 |
-
debug_log("API key
|
| 1066 |
debug_log(f"请求解析成功 - 模型: {request.model}, 流式: {request.stream}, 消息数: {len(request.messages)}")
|
| 1067 |
|
| 1068 |
# Generate IDs
|
|
|
|
| 9 |
"""
|
| 10 |
|
| 11 |
import json
|
| 12 |
+
import os
|
| 13 |
import re
|
| 14 |
import time
|
| 15 |
from datetime import datetime
|
|
|
|
| 29 |
"""Centralized server configuration"""
|
| 30 |
|
| 31 |
# API Configuration
|
| 32 |
+
API_ENDPOINT: str = os.getenv("API_ENDPOINT", "https://chat.z.ai/api/chat/completions")
|
| 33 |
+
AUTH_TOKEN: str = os.getenv("AUTH_TOKEN", "sk-your-api-key")
|
| 34 |
+
BACKUP_TOKEN: str = os.getenv("BACKUP_TOKEN", "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMxNmJjYjQ4LWZmMmYtNGExNS04NTNkLWYyYTI5YjY3ZmYwZiIsImVtYWlsIjoiR3Vlc3QtMTc1NTg0ODU4ODc4OEBndWVzdC5jb20ifQ.PktllDySS3trlyuFpTeIZf-7hl8Qu1qYF3BxjgIul0BrNux2nX9hVzIjthLXKMWAf9V0qM8Vm_iyDqkjPGsaiQ")
|
| 35 |
|
| 36 |
# Model Configuration
|
| 37 |
+
PRIMARY_MODEL: str = os.getenv("PRIMARY_MODEL", "GLM-4.5")
|
| 38 |
+
THINKING_MODEL: str = os.getenv("THINKING_MODEL", "GLM-4.5-Thinking")
|
| 39 |
+
SEARCH_MODEL: str = os.getenv("SEARCH_MODEL", "GLM-4.5-Search")
|
| 40 |
|
| 41 |
# Server Configuration
|
| 42 |
+
LISTEN_PORT: int = int(os.getenv("LISTEN_PORT", "8080"))
|
| 43 |
+
DEBUG_LOGGING: bool = os.getenv("DEBUG_LOGGING", "true").lower() == "true"
|
| 44 |
|
| 45 |
# Feature Configuration
|
| 46 |
+
THINKING_PROCESSING: str = os.getenv("THINKING_PROCESSING", "think") # strip: 去除<details>标签;think: 转为</think>标签;raw: 保留原样
|
| 47 |
+
ANONYMOUS_MODE: bool = os.getenv("ANONYMOUS_MODE", "true").lower() == "true"
|
| 48 |
+
TOOL_SUPPORT: bool = os.getenv("TOOL_SUPPORT", "true").lower() == "true"
|
| 49 |
+
SCAN_LIMIT: int = int(os.getenv("SCAN_LIMIT", "200000"))
|
| 50 |
|
| 51 |
# Browser Headers
|
| 52 |
CLIENT_HEADERS: Dict[str, str] = {
|
|
|
|
| 1063 |
debug_log(f"无效的API key: {api_key}")
|
| 1064 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
| 1065 |
|
| 1066 |
+
debug_log(f"API key验证通过,AUTH_TOKEN={api_key[:8]}......")
|
| 1067 |
debug_log(f"请求解析成功 - 模型: {request.model}, 流式: {request.stream}, 消息数: {len(request.messages)}")
|
| 1068 |
|
| 1069 |
# Generate IDs
|