Skip to content

Commit c4e7839

Browse files
author
wangyudong
committed
feat: 增加OPENAI的extra_body配置各厂商独有特性
1 parent 6066c20 commit c4e7839

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- 将OpenAI供应器的thinking_type参数改为更通用的extra_body参数
2+
-- 支持不同模型的额外参数配置
3+
UPDATE `ai_model_provider` SET
4+
`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"}]'
5+
WHERE `id` = 'SYSTEM_LLM_openai';
6+
7+
-- 更新豆包大模型配置说明,添加extra_body参数说明
8+
UPDATE `ai_model_config` SET
9+
`remark` = '豆包大模型配置说明:
10+
1. 访问 https://console.volcengine.com/ark/region:ark+cn-beijing/openManagement
11+
2. 开通Doubao-Seed-1.6服务
12+
3. 访问 https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey 获取API密钥
13+
4. 填入配置文件中
14+
5. extra_body关闭深度思考示例(默认开启):{"thinking": {"type": "disabled"}}
15+
注意:有免费额度500000token'
16+
WHERE `id` = 'LLM_DoubaoLLM';
17+
18+
-- 更新通义千问大模型配置说明,添加extra_body参数说明
19+
UPDATE `ai_model_config` SET
20+
`remark` = '通义千问配置说明:
21+
1. 访问 https://bailian.console.aliyun.com/?apiKey=1#/api-key
22+
2. 获取API密钥
23+
3. 填入配置文件中,当前配置使用qwen-turbo模型
24+
4. 支持自定义参数:temperature=0.7, max_tokens=500, top_p=1, top_k=50
25+
5. extra_body关闭深度思考示例:{"enable_thinking": false}'
26+
WHERE `id` = 'LLM_AliLLM';

main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,10 @@ databaseChangeLog:
282282
- sqlFile:
283283
encoding: utf8
284284
path: classpath:db/changelog/202507081646.sql
285+
- changeSet:
286+
id: 202507251333
287+
author: whyuds
288+
changes:
289+
- sqlFile:
290+
encoding: utf8
291+
path: classpath:db/changelog/202507251333.sql

main/xiaozhi-server/core/providers/llm/openai/openai.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def __init__(self, config):
3939
except (ValueError, TypeError):
4040
setattr(self, param, default)
4141

42+
# 处理extra_body参数,用于传递额外的API参数
43+
self.extra_body = {} if config.get('extra_body', {}) == "" else config.get('extra_body', {})
44+
4245
logger.debug(
4346
f"意图识别参数初始化: {self.temperature}, {self.max_tokens}, {self.top_p}, {self.frequency_penalty}"
4447
)
@@ -60,6 +63,7 @@ def response(self, session_id, dialogue, **kwargs):
6063
frequency_penalty=kwargs.get(
6164
"frequency_penalty", self.frequency_penalty
6265
),
66+
extra_body=self.extra_body
6367
)
6468

6569
is_active = True
@@ -91,7 +95,7 @@ def response(self, session_id, dialogue, **kwargs):
9195
def response_with_functions(self, session_id, dialogue, functions=None):
9296
try:
9397
stream = self.client.chat.completions.create(
94-
model=self.model_name, messages=dialogue, stream=True, tools=functions
98+
model=self.model_name, messages=dialogue, stream=True, tools=functions, extra_body=self.extra_body
9599
)
96100

97101
for chunk in stream:

0 commit comments

Comments
 (0)