mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
补充sql,增加字段校验
This commit is contained in:
parent
5b0c8c303b
commit
a1919f7db3
4 changed files with 29 additions and 9 deletions
|
|
@ -0,0 +1,6 @@
|
|||
-- 为 LLM 的 OpenAI 接口配置表单新增 chat_template_kwargs 字段(json-textarea)
|
||||
-- 用于向 vLLM/SGLang 等自托管 OpenAI 兼容后端透传 chat template 控制参数(如 enable_thinking)
|
||||
-- 注意: DashScope 等云服务不识别此字段, 仅供自托管后端使用
|
||||
UPDATE `ai_model_provider`
|
||||
SET `fields` = '[{"key":"base_url","label":"基础URL","type":"string"},{"key":"model_name","label":"模型名称","type":"string"},{"key":"api_key","label":"API密钥","type":"string"},{"key":"temperature","label":"温度","type":"number"},{"key":"max_tokens","label":"最大令牌数","type":"number"},{"key":"top_p","label":"top_p值","type":"number"},{"key":"top_k","label":"top_k值","type":"number"},{"key":"frequency_penalty","label":"频率惩罚","type":"number"},{"key":"chat_template_kwargs","label":"chat模板参数(JSON,仅自托管vLLM/SGLang等)","type":"json-textarea"}]'
|
||||
WHERE `id` = 'SYSTEM_LLM_openai';
|
||||
|
|
@ -774,3 +774,10 @@ databaseChangeLog:
|
|||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202611101200.sql
|
||||
- changeSet:
|
||||
id: 202611181622
|
||||
author: RanChen
|
||||
changes:
|
||||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202611181622.sql
|
||||
|
|
|
|||
|
|
@ -626,7 +626,8 @@ LLM:
|
|||
max_tokens: 500 # 最大生成token数
|
||||
top_p: 1
|
||||
frequency_penalty: 0 # 频率惩罚
|
||||
# 可选: 透传给后端的 chat_template_kwargs(供 vLLM/SGLang 等 OpenAI 兼容后端控制 chat template, 例如思考开关)
|
||||
# 可选: chat_template_kwargs 仅适用于 vLLM/SGLang 等自托管 OpenAI 兼容后端(请求级控制 chat template, 例如思考开关)
|
||||
# 注意: DashScope 等云服务不认识此字段, 配置后会被忽略; 云服务的思考开关由服务端按域名自动处理
|
||||
# chat_template_kwargs:
|
||||
# enable_thinking: true
|
||||
AliAppLLM:
|
||||
|
|
|
|||
|
|
@ -31,8 +31,13 @@ class LLMProvider(LLMProviderBase):
|
|||
# 可选实例级思考强度: off/disabled/none/disable | low/medium/high | 空/其他=按域名默认
|
||||
self.thinking_mode = str(config.get("thinking") or "").strip().lower()
|
||||
self.api_key = config.get("api_key")
|
||||
# 可选: 透传给后端的 chat_template_kwargs(供 vLLM/SGLang 等 OpenAI 兼容后端使用)
|
||||
self.chat_template_kwargs = config.get("chat_template_kwargs") or {}
|
||||
# 可选: 透传给后端的 chat_template_kwargs(供 vLLM/SGLang 等自托管 OpenAI 兼容后端使用)
|
||||
chat_template_kwargs = config.get("chat_template_kwargs")
|
||||
if chat_template_kwargs and not isinstance(chat_template_kwargs, dict):
|
||||
logger.bind(tag=TAG).warning(
|
||||
f"chat_template_kwargs 配置格式错误, 应为键值对象, 已忽略: {chat_template_kwargs!r}")
|
||||
chat_template_kwargs = None
|
||||
self.chat_template_kwargs = chat_template_kwargs or {}
|
||||
if "base_url" in config:
|
||||
self.base_url = config.get("base_url")
|
||||
else:
|
||||
|
|
@ -119,6 +124,11 @@ class LLMProvider(LLMProviderBase):
|
|||
logger.bind(tag=TAG).info(f"为域名 {domain} 禁用思考模式,参数: {params}")
|
||||
break
|
||||
|
||||
def _apply_chat_template_kwargs(self, request_params: dict):
|
||||
"""透传 chat_template_kwargs 到 extra_body(仅 vLLM/SGLang 等自托管 OpenAI 兼容后端识别, 云服务会忽略)"""
|
||||
if self.chat_template_kwargs:
|
||||
request_params.setdefault("extra_body", {})["chat_template_kwargs"] = self.chat_template_kwargs
|
||||
|
||||
def response(self, session_id, dialogue, **kwargs):
|
||||
dialogue = self.normalize_dialogue(dialogue)
|
||||
|
||||
|
|
@ -142,9 +152,7 @@ class LLMProvider(LLMProviderBase):
|
|||
|
||||
# 禁用思考模式
|
||||
self._apply_thinking_disabled(request_params)
|
||||
# 透传 chat_template_kwargs 到 extra_body(OpenAI 兼容后端)
|
||||
if self.chat_template_kwargs:
|
||||
request_params.setdefault("extra_body", {})["chat_template_kwargs"] = self.chat_template_kwargs
|
||||
self._apply_chat_template_kwargs(request_params)
|
||||
|
||||
responses = self.client.chat.completions.create(**request_params)
|
||||
|
||||
|
|
@ -191,9 +199,7 @@ class LLMProvider(LLMProviderBase):
|
|||
|
||||
# 禁用思考模式
|
||||
self._apply_thinking_disabled(request_params)
|
||||
# 透传 chat_template_kwargs 到 extra_body(OpenAI 兼容后端)
|
||||
if self.chat_template_kwargs:
|
||||
request_params.setdefault("extra_body", {})["chat_template_kwargs"] = self.chat_template_kwargs
|
||||
self._apply_chat_template_kwargs(request_params)
|
||||
|
||||
stream = self.client.chat.completions.create(**request_params)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue