mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
feat(llm): 支持 OpenAI 兼容后端透传 chat_template_kwargs (extra_body)
This commit is contained in:
parent
61a8c04477
commit
837dfae393
2 changed files with 11 additions and 0 deletions
|
|
@ -626,6 +626,9 @@ LLM:
|
|||
max_tokens: 500 # 最大生成token数
|
||||
top_p: 1
|
||||
frequency_penalty: 0 # 频率惩罚
|
||||
# 可选: 透传给后端的 chat_template_kwargs(供 vLLM/SGLang 等 OpenAI 兼容后端控制 chat template, 例如思考开关)
|
||||
# chat_template_kwargs:
|
||||
# enable_thinking: true
|
||||
AliAppLLM:
|
||||
# 定义LLM API类型
|
||||
type: AliBL
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ 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 {}
|
||||
if "base_url" in config:
|
||||
self.base_url = config.get("base_url")
|
||||
else:
|
||||
|
|
@ -140,6 +142,9 @@ 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
|
||||
|
||||
responses = self.client.chat.completions.create(**request_params)
|
||||
|
||||
|
|
@ -186,6 +191,9 @@ 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
|
||||
|
||||
stream = self.client.chat.completions.create(**request_params)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue