Coze接口配置及调用变更

This commit is contained in:
2025-12-22 18:02:35 +08:00
parent 26574e3db7
commit 180fe20347
8 changed files with 495 additions and 17 deletions
@@ -1377,8 +1377,9 @@ public class AiChatServiceImpl implements AiChatService {
while (attempt < maxAttempts) {
log.info("轮询聊天状态,第{}次尝试: chatId={}, conversationId={}", attempt + 1, chatId, conversationId);
// 构建状态查询URL
String statusUrl = config.getApiBaseUrl() + "/v3/chat/retrieve?chat_id=" + chatId + "&conversation_id="
// 构建状态查询URL(使用基础URL拼接状态查询路径)
String baseUrl = extractBaseUrl(config.getApiBaseUrl());
String statusUrl = baseUrl + "/v3/chat/retrieve?chat_id=" + chatId + "&conversation_id="
+ conversationId;
// 构建请求头
@@ -1440,8 +1441,9 @@ public class AiChatServiceImpl implements AiChatService {
log.info("获取聊天消息: chatId={}, conversationId={}", chatId, conversationId);
// 构建消息查询URL
String messagesUrl = config.getApiBaseUrl() + "/v3/chat/message/list?chat_id=" + chatId + "&conversation_id="
// 构建消息查询URL(使用基础URL拼接消息查询路径)
String baseUrl = extractBaseUrl(config.getApiBaseUrl());
String messagesUrl = baseUrl + "/v3/chat/message/list?chat_id=" + chatId + "&conversation_id="
+ conversationId;
// 构建请求头
@@ -1993,10 +1995,33 @@ public class AiChatServiceImpl implements AiChatService {
/**
* 获取配置的API路径
* apiBaseUrl已经是完整的API URL,不需要再拼接路径
*/
private String getApiPath(AiConfig config) {
// 默认使用 /v3/chat 路径
return "/v3/chat";
// apiBaseUrl已经是完整的URL,返回空字符串
return "";
}
/**
* 从apiBaseUrl中提取基础URL(用于状态查询和消息查询等辅助接口)
* 例如:https://api.coze.cn/v3/chat -> https://api.coze.cn
*/
private String extractBaseUrl(String apiBaseUrl) {
if (apiBaseUrl == null || apiBaseUrl.isEmpty()) {
return "";
}
try {
java.net.URL url = new java.net.URL(apiBaseUrl);
return url.getProtocol() + "://" + url.getHost() + (url.getPort() > 0 ? ":" + url.getPort() : "");
} catch (Exception e) {
log.warn("解析apiBaseUrl失败: {}", apiBaseUrl, e);
// 尝试简单截取
int pathIndex = apiBaseUrl.indexOf("/", apiBaseUrl.indexOf("://") + 3);
if (pathIndex > 0) {
return apiBaseUrl.substring(0, pathIndex);
}
return apiBaseUrl;
}
}
/**