Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions main/manager-api/src/main/resources/db/changelog/202507251333.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- 将OpenAI供应器的thinking_type参数改为更通用的extra_body参数
-- 支持不同模型的额外参数配置
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":"extra_body","label":"extra_body","type":"dict"}]'
WHERE `id` = 'SYSTEM_LLM_openai';

-- 更新豆包大模型配置说明,添加extra_body参数说明
UPDATE `ai_model_config` SET
`remark` = '豆包大模型配置说明:
1. 访问 https://console.volcengine.com/ark/region:ark+cn-beijing/openManagement
2. 开通Doubao-Seed-1.6服务
3. 访问 https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey 获取API密钥
4. 填入配置文件中
5. extra_body关闭深度思考示例(默认开启):{"thinking": {"type": "disabled"}}
注意:有免费额度500000token'
WHERE `id` = 'LLM_DoubaoLLM';

-- 更新通义千问大模型配置说明,添加extra_body参数说明
UPDATE `ai_model_config` SET
`remark` = '通义千问配置说明:
1. 访问 https://bailian.console.aliyun.com/?apiKey=1#/api-key
2. 获取API密钥
3. 填入配置文件中,当前配置使用qwen-turbo模型
4. 支持自定义参数:temperature=0.7, max_tokens=500, top_p=1, top_k=50
5. extra_body关闭深度思考示例:{"enable_thinking": false}'
WHERE `id` = 'LLM_AliLLM';
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,10 @@ databaseChangeLog:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202507081646.sql
- changeSet:
id: 202507251333
author: whyuds
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202507251333.sql
6 changes: 5 additions & 1 deletion main/xiaozhi-server/core/providers/llm/openai/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(self, config):
except (ValueError, TypeError):
setattr(self, param, default)

# 处理extra_body参数,用于传递额外的API参数
self.extra_body = {} if config.get('extra_body', {}) == "" else config.get('extra_body', {})

logger.debug(
f"意图识别参数初始化: {self.temperature}, {self.max_tokens}, {self.top_p}, {self.frequency_penalty}"
)
Expand All @@ -60,6 +63,7 @@ def response(self, session_id, dialogue, **kwargs):
frequency_penalty=kwargs.get(
"frequency_penalty", self.frequency_penalty
),
extra_body=self.extra_body
)

is_active = True
Expand Down Expand Up @@ -91,7 +95,7 @@ def response(self, session_id, dialogue, **kwargs):
def response_with_functions(self, session_id, dialogue, functions=None):
try:
stream = self.client.chat.completions.create(
model=self.model_name, messages=dialogue, stream=True, tools=functions
model=self.model_name, messages=dialogue, stream=True, tools=functions, extra_body=self.extra_body
)

for chunk in stream:
Expand Down