refactor(config): 简化EULA验证并统一环境变量配置管理
- 重构EULA验证机制,从复杂的文件哈希验证改为简单的环境变量验证 - 统一host和port配置,优先从环境变量读取而非配置文件 - 移除ServerConfig配置类,简化配置结构 - 添加.env文件自动创建和管理功能 - 更新相关模板和文档注释
This commit is contained in:
@@ -3,6 +3,7 @@ import importlib.metadata
|
||||
from maim_message import MessageServer
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config import global_config
|
||||
import os
|
||||
|
||||
global_api = None
|
||||
|
||||
@@ -22,9 +23,18 @@ def get_global_api() -> MessageServer: # sourcery skip: extract-method
|
||||
maim_message_config = global_config.maim_message
|
||||
|
||||
# 设置基本参数
|
||||
|
||||
host = os.getenv("HOST", "127.0.0.1")
|
||||
port_str = os.getenv("PORT", "8000")
|
||||
|
||||
try:
|
||||
port = int(port_str)
|
||||
except ValueError:
|
||||
port = 8000
|
||||
|
||||
kwargs = {
|
||||
"host": global_config.server.host,
|
||||
"port": int(global_config.server.port),
|
||||
"host": host,
|
||||
"port": port,
|
||||
"app": get_global_server().get_app(),
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import Optional
|
||||
from uvicorn import Config, Server as UvicornServer
|
||||
from src.config.config import global_config
|
||||
from rich.traceback import install
|
||||
import os
|
||||
|
||||
install(extra_lines=3)
|
||||
|
||||
@@ -98,5 +99,14 @@ def get_global_server() -> Server:
|
||||
"""获取全局服务器实例"""
|
||||
global global_server
|
||||
if global_server is None:
|
||||
global_server = Server(host=global_config.server.host,port=int(global_config.server.port),)
|
||||
|
||||
host = os.getenv("HOST", "127.0.0.1")
|
||||
port_str = os.getenv("PORT", "8000")
|
||||
|
||||
try:
|
||||
port = int(port_str)
|
||||
except ValueError:
|
||||
port = 8000
|
||||
|
||||
global_server = Server(host=host, port=port)
|
||||
return global_server
|
||||
|
||||
@@ -42,8 +42,7 @@ from src.config.official_configs import (
|
||||
CrossContextConfig,
|
||||
PermissionConfig,
|
||||
CommandConfig,
|
||||
PlanningSystemConfig,
|
||||
ServerConfig,
|
||||
PlanningSystemConfig
|
||||
)
|
||||
|
||||
from .api_ada_configs import (
|
||||
@@ -413,7 +412,6 @@ class Config(ValidatedConfigBase):
|
||||
cross_context: CrossContextConfig = Field(
|
||||
default_factory=lambda: CrossContextConfig(), description="跨群聊上下文共享配置"
|
||||
)
|
||||
server: ServerConfig = Field(default_factory=lambda: ServerConfig(), description="主服务器配置")
|
||||
|
||||
|
||||
class APIAdapterConfig(ValidatedConfigBase):
|
||||
|
||||
@@ -477,12 +477,6 @@ class ExperimentalConfig(ValidatedConfigBase):
|
||||
pfc_chatting: bool = Field(default=False, description="启用PFC聊天")
|
||||
|
||||
|
||||
class ServerConfig(ValidatedConfigBase):
|
||||
"""主服务器配置类"""
|
||||
|
||||
host: str = Field(default="127.0.0.1", description="主服务器监听地址")
|
||||
port: int = Field(default=8080, description="主服务器监听端口")
|
||||
|
||||
|
||||
class MaimMessageConfig(ValidatedConfigBase):
|
||||
"""maim_message配置类"""
|
||||
|
||||
Reference in New Issue
Block a user