Skip to content

Commit bdf672f

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents f86735a + 111ec1c commit bdf672f

File tree

18 files changed

+879
-190
lines changed

18 files changed

+879
-190
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# 变更日志
2+
## [2.8.8] - 2025-06-24
3+
4+
### 其他变更
5+
- chore: update version to 2.8.8 [skip ci]
6+
27
## [2.8.7] - 2025-06-20
38

49
### 其他变更

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ Xiaozhi ESP32 Server Java 是基于 [Xiaozhi ESP32](https://github.com/78/xiaozh
206206

207207
### 微信
208208

209-
一群已满,扫码加入二群
209+
微信群超200人无法扫码进群,可以加我微信备注 **小智** 我拉你进微信群
210210

211-
<img src="docs/images/wechat_group.jpg" alt="微信" width="200" />
211+
<img src="./web/static/img/wechat.jpg" alt="微信" width="200" />
212212

213213
### QQ
214214

@@ -220,8 +220,6 @@ Xiaozhi ESP32 Server Java 是基于 [Xiaozhi ESP32](https://github.com/78/xiaozh
220220

221221
我们接受各种定制化开发项目,如果您有特定需求,欢迎通过微信联系洽谈。
222222

223-
<img src="./web/static/img/wechat.jpg" alt="微信" width="200" />
224-
225223
---
226224

227225
## 免责声明 ⚠️

db/2025_06_14.sql

Lines changed: 0 additions & 32 deletions
This file was deleted.

db/2025_06_25.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE xiaozhi.sys_config MODIFY COLUMN sk text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT 'Secret Key';

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>com.xiaozhi.server</groupId>
1111
<artifactId>xiaozhi.server</artifactId>
12-
<version>2.8.7</version>
12+
<version>2.8.8</version>
1313
<name>xiaozhi-server</name>
1414
<description></description>
1515

@@ -239,6 +239,12 @@
239239
<artifactId>dashscope-sdk-java</artifactId>
240240
<version>2.20.2</version>
241241
</dependency>
242+
<!-- 阿里云Token -->
243+
<dependency>
244+
<groupId>com.aliyun</groupId>
245+
<artifactId>aliyun-java-sdk-core</artifactId>
246+
<version>3.7.1</version>
247+
</dependency>
242248
<!-- 讯飞 -->
243249
<dependency>
244250
<groupId>cn.xfyun</groupId>

src/main/java/com/xiaozhi/dialogue/llm/factory/ChatModelFactory.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xiaozhi.communication.common.ChatSession;
44
import com.xiaozhi.dialogue.llm.providers.CozeChatModel;
55
import com.xiaozhi.dialogue.llm.providers.DifyChatModel;
6+
import com.xiaozhi.dialogue.token.factory.TokenServiceFactory;
67
import com.xiaozhi.entity.SysConfig;
78
import com.xiaozhi.entity.SysDevice;
89
import com.xiaozhi.entity.SysRole;
@@ -50,6 +51,8 @@ public class ChatModelFactory {
5051
private SysRoleService roleService;
5152
@Autowired
5253
private ToolCallingManager toolCallingManager;
54+
@Autowired
55+
private TokenServiceFactory tokenService;
5356
private final Logger logger = LoggerFactory.getLogger(ChatModelFactory.class);
5457

5558
/**
@@ -85,15 +88,21 @@ private ChatModel createChatModel(SysConfig config, SysRole role) {
8588
Double temperature = role.getTemperature();
8689
Double topP = role.getTopP();
8790
provider = provider.toLowerCase();
91+
// Coze和Dify 拥有全局唯一配置,所以需要查询唯一配置信息来作为模型的 Token 获取
92+
SysConfig agentConfig = new SysConfig().setConfigType("agent").setUserId(config.getUserId());
93+
SysConfig queryConfig;
8894
switch (provider) {
8995
case "ollama":
9096
return newOllamaChatModel(endpoint, appId, apiKey, apiSecret, model, temperature, topP);
9197
case "zhipu":
9298
return newZhipuChatModel(endpoint, appId, apiKey, apiSecret, model, temperature, topP);
9399
case "dify":
94-
return new DifyChatModel(endpoint, appId, apiKey, apiSecret, model);
100+
queryConfig = configService.query(agentConfig.setProvider("dify"), null).get(0);
101+
return new DifyChatModel(endpoint, queryConfig.getApiKey());
95102
case "coze":
96-
return new CozeChatModel(endpoint, appId, apiKey, apiSecret, model);
103+
queryConfig = configService.query(agentConfig.setProvider("coze"), null).get(0);
104+
String token = tokenService.getTokenService(queryConfig).getToken();
105+
return new CozeChatModel(token, model);
97106
// 默认为 openai 协议
98107
default:
99108
return newOpenAiChatModel(endpoint, appId, apiKey, apiSecret, model, temperature, topP);

src/main/java/com/xiaozhi/dialogue/llm/providers/CozeChatModel.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.coze.openapi.client.connversations.message.model.MessageType;
88
import com.coze.openapi.service.auth.TokenAuth;
99
import com.coze.openapi.service.service.CozeAPI;
10+
1011
import io.reactivex.Flowable;
12+
1113
import org.slf4j.Logger;
1214
import org.slf4j.LoggerFactory;
1315
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -32,29 +34,16 @@ public class CozeChatModel implements ChatModel {
3234
private final CozeAPI coze;
3335
private final String botId;
3436

35-
private final String endpoint;
36-
private final String apiKey;
37-
private final String model;
38-
private final String appId;
39-
private final String apiSecret;
4037
private final Logger logger = LoggerFactory.getLogger(getClass());
4138
public static final String PROVIDER_NAME = "coze";
4239

40+
4341
/**
4442
* 构造函数
4543
*
46-
* @param endpoint API端点
47-
* @param appId 应用ID (在Coze中对应botId)
48-
* @param apiKey API密钥 (在Coze中不使用)
49-
* @param apiSecret API密钥 (在Coze中对应access_token)
5044
* @param model 模型名称 (在Coze中不使用)
5145
*/
52-
public CozeChatModel(String endpoint, String appId, String apiKey, String apiSecret, String model) {
53-
this.endpoint = endpoint;
54-
this.appId = appId;
55-
this.apiSecret = apiSecret;
56-
this.apiKey = apiKey;
57-
this.model = model;
46+
public CozeChatModel(String apiSecret, String model) {
5847

5948
// 使用apiSecret作为access_token
6049
this.authCli = new TokenAuth(apiSecret);

src/main/java/com/xiaozhi/dialogue/llm/providers/DifyChatModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class DifyChatModel implements ChatModel {
3333
* @param apiSecret
3434
* @param model 模型名称
3535
*/
36-
public DifyChatModel(String endpoint, String appId, String apiKey, String apiSecret, String model) {
36+
public DifyChatModel(String endpoint, String apiKey) {
3737
chatClient = DifyClientFactory.createChatClient(endpoint, apiKey);
3838
}
3939

src/main/java/com/xiaozhi/dialogue/service/VadService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public VadResult processAudio(String sessionId, byte[] opusData) {
444444
float adjustedSilenceThreshold = adjustVadThreshold(silenceThreshold, agcStats);
445445

446446
// 添加到预缓冲区
447-
state.addToPreBuffer(pcmData);
447+
// state.addToPreBuffer(pcmData);
448448

449449
// 处理短帧数据
450450
if (pcmData.length < MIN_PCM_LENGTH && !state.isSpeaking()) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.xiaozhi.dialogue.token;
2+
3+
public interface TokenService {
4+
/**
5+
* 获取Token (统一入口)
6+
*/
7+
String getToken();
8+
9+
/**
10+
* 获取服务提供商名称
11+
*/
12+
String getProviderName();
13+
14+
/**
15+
* 手动刷新Token
16+
*/
17+
String refreshToken();
18+
19+
/**
20+
* 检查Token是否有效
21+
*/
22+
boolean isTokenValid();
23+
24+
/**
25+
* 清理指定配置的Token缓存
26+
*/
27+
void clearTokenCache();
28+
}

0 commit comments

Comments
 (0)