From 12bc6617901f5ab2f60a69f415478099ee67f6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Wed, 3 Dec 2025 11:45:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E6=9C=80=E5=A4=A7token=E6=95=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/api_ada_configs.py | 3 +++ src/llm_models/utils_model.py | 11 ++++++++++- template/model_config_template.toml | 10 +++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/config/api_ada_configs.py b/src/config/api_ada_configs.py index 24b7896e..a5d5f059 100644 --- a/src/config/api_ada_configs.py +++ b/src/config/api_ada_configs.py @@ -63,6 +63,9 @@ class ModelInfo(ConfigBase): temperature: float | None = field(default=None) """模型级别温度(可选),会覆盖任务配置中的温度""" + max_tokens: int | None = field(default=None) + """模型级别最大token数(可选),会覆盖任务配置中的max_tokens""" + force_stream_mode: bool = field(default=False) """是否强制使用流式输出模式""" diff --git a/src/llm_models/utils_model.py b/src/llm_models/utils_model.py index 2d2c1c86..7fb4cfd0 100644 --- a/src/llm_models/utils_model.py +++ b/src/llm_models/utils_model.py @@ -324,11 +324,20 @@ class LLMRequest: if effective_temperature is None: effective_temperature = self.model_for_task.temperature + # max_tokens 优先级:参数传入 > 模型级别配置 > extra_params > 任务配置 + effective_max_tokens = max_tokens + if effective_max_tokens is None: + effective_max_tokens = model_info.max_tokens + if effective_max_tokens is None: + effective_max_tokens = (model_info.extra_params or {}).get("max_tokens") + if effective_max_tokens is None: + effective_max_tokens = self.model_for_task.max_tokens + return await client.get_response( model_info=model_info, message_list=(compressed_messages or message_list), tool_options=tool_options, - max_tokens=self.model_for_task.max_tokens if max_tokens is None else max_tokens, + max_tokens=effective_max_tokens, temperature=effective_temperature, response_format=response_format, stream_response_handler=stream_response_handler, diff --git a/template/model_config_template.toml b/template/model_config_template.toml index 1e072d13..225b94f1 100644 --- a/template/model_config_template.toml +++ b/template/model_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "1.8.2" +version = "1.9.0" # 配置文件版本号迭代规则同bot_config.toml @@ -54,9 +54,11 @@ name = "siliconflow-deepseek-v3.2" api_provider = "SiliconFlow" price_in = 2.0 price_out = 3.0 +# temperature = 0.5 # 可选:为该模型单独指定温度,会覆盖任务配置中的温度 +# max_tokens = 4096 # 可选:为该模型单独指定最大token数,会覆盖任务配置中的max_tokens [models.extra_params] # 可选的额外参数配置 enable_thinking = false # 不启用思考 -# temperature = 0.5 # 可选:为该模型单独指定温度,会覆盖任务配置中的温度 + [[models]] model_identifier = "deepseek-ai/DeepSeek-V3.2-Exp" @@ -64,9 +66,11 @@ name = "siliconflow-deepseek-v3.2-think" api_provider = "SiliconFlow" price_in = 2.0 price_out = 3.0 +# temperature = 0.7 # 可选:为该模型单独指定温度,会覆盖任务配置中的温度 +# max_tokens = 4096 # 可选:为该模型单独指定最大token数,会覆盖任务配置中的max_tokens [models.extra_params] # 可选的额外参数配置 enable_thinking = true # 启用思考 -# temperature = 0.7 # 可选:为该模型单独指定温度,会覆盖任务配置中的温度 + [[models]] model_identifier = "Qwen/Qwen3-Next-80B-A3B-Instruct"