diff --git a/src/plugins/config/config.py b/src/plugins/config/config.py index 66c3af659..be53c7bea 100644 --- a/src/plugins/config/config.py +++ b/src/plugins/config/config.py @@ -316,16 +316,21 @@ class BotConfig: elif config.INNER_VERSION in SpecifierSet(">=0.0.1"): stable_item = ["name", "pri_in", "pri_out"] - + + stream_item = ["stream"] if config.INNER_VERSION in SpecifierSet(">=1.0.1"): stable_item.append("stream") - + pricing_item = ["pri_in", "pri_out"] # 从配置中原始拷贝稳定字段 for i in stable_item: # 如果 字段 属于计费项 且获取不到,那默认值是 0 if i in pricing_item and i not in cfg_item: cfg_target[i] = 0 + + if i in stream_item and i not in cfg_item: + cfg_target[i] = False + else: # 没有特殊情况则原样复制 try: diff --git a/src/plugins/config/config_env.py b/src/plugins/config/config_env.py index e19f0c316..cf5037717 100644 --- a/src/plugins/config/config_env.py +++ b/src/plugins/config/config_env.py @@ -2,54 +2,58 @@ import os from pathlib import Path from dotenv import load_dotenv + class EnvConfig: _instance = None - + def __new__(cls): if cls._instance is None: cls._instance = super(EnvConfig, cls).__new__(cls) cls._instance._initialized = False return cls._instance - + def __init__(self): if self._initialized: return - + self._initialized = True self.ROOT_DIR = Path(__file__).parent.parent.parent.parent self.load_env() - + def load_env(self): - env_file = self.ROOT_DIR / '.env' + env_file = self.ROOT_DIR / ".env" if env_file.exists(): load_dotenv(env_file) - + # 根据ENVIRONMENT变量加载对应的环境文件 - env_type = os.getenv('ENVIRONMENT', 'prod') - if env_type == 'dev': - env_file = self.ROOT_DIR / '.env.dev' - elif env_type == 'prod': - env_file = self.ROOT_DIR / '.env' - + env_type = os.getenv("ENVIRONMENT", "prod") + if env_type == "dev": + env_file = self.ROOT_DIR / ".env.dev" + elif env_type == "prod": + env_file = self.ROOT_DIR / ".env" + if env_file.exists(): load_dotenv(env_file, override=True) - + def get(self, key, default=None): return os.getenv(key, default) - + def get_all(self): return dict(os.environ) - + def __getattr__(self, name): return self.get(name) + # 创建全局实例 env_config = EnvConfig() + # 导出环境变量 def get_env(key, default=None): return os.getenv(key, default) + # 导出所有环境变量 def get_all_env(): - return dict(os.environ) \ No newline at end of file + return dict(os.environ) diff --git a/src/plugins/models/utils_model.py b/src/plugins/models/utils_model.py index 6c2fba5c8..51f34a077 100644 --- a/src/plugins/models/utils_model.py +++ b/src/plugins/models/utils_model.py @@ -179,6 +179,10 @@ class LLM_request: # logger.debug(f"{logger_msg}发送请求到URL: {api_url}") # logger.info(f"使用模型: {self.model_name}") + # 流式输出标志 + if stream_mode: + payload["stream"] = stream_mode + # 构建请求体 if image_base64: payload = await self._build_payload(prompt, image_base64, image_format)