mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 03:49:21 +08:00
feat: 支持 Completions/Responses 双协议,并在同选型下续链加速
This commit is contained in:
+5
@@ -16,4 +16,9 @@ public class CreateAgentLlmProviderDTO {
|
||||
private String apiKey;
|
||||
|
||||
private String displayName;
|
||||
|
||||
/**
|
||||
* API 协议:auto | completions | responses;空则 auto
|
||||
*/
|
||||
private String apiStyle;
|
||||
}
|
||||
|
||||
+5
@@ -16,4 +16,9 @@ public class UpdateAgentLlmProviderDTO {
|
||||
|
||||
/** 传 null 表示不改;传空串可清空备注 */
|
||||
private String displayName;
|
||||
|
||||
/**
|
||||
* API 协议:auto | completions | responses;null 不改
|
||||
*/
|
||||
private String apiStyle;
|
||||
}
|
||||
|
||||
+6
@@ -33,6 +33,12 @@ public class AgentCompanyLlmProviderPO {
|
||||
@TableField("display_name")
|
||||
private String displayName;
|
||||
|
||||
/**
|
||||
* API 协议:auto | completions | responses
|
||||
*/
|
||||
@TableField("api_style")
|
||||
private String apiStyle;
|
||||
|
||||
@TableField("extra_headers_json")
|
||||
private String extraHeadersJson;
|
||||
|
||||
|
||||
+4
@@ -16,5 +16,9 @@ public class AgentLlmProviderVO {
|
||||
private String displayName;
|
||||
private String apiKeyMasked;
|
||||
private String updateTime;
|
||||
/**
|
||||
* API 协议:auto | completions | responses
|
||||
*/
|
||||
private String apiStyle;
|
||||
private List<AgentLlmModelVO> models = new ArrayList<>();
|
||||
}
|
||||
|
||||
+4
@@ -15,5 +15,9 @@ public class AgentLlmRuntimeVO {
|
||||
private String model;
|
||||
/** 上下文窗口 token;可能为 null */
|
||||
private Integer contextWindow;
|
||||
/**
|
||||
* API 协议:auto | completions | responses
|
||||
*/
|
||||
private String apiStyle;
|
||||
private Map<String, String> extraHeaders;
|
||||
}
|
||||
|
||||
+20
@@ -98,6 +98,7 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
po.setApiKeyEncrypted(crypto.encrypt(plain));
|
||||
po.setApiKeySuffix(plain.length() >= 4 ? plain.substring(plain.length() - 4) : plain);
|
||||
po.setDisplayName(trimToNull(dto.getDisplayName()));
|
||||
po.setApiStyle(normalizeApiStyle(dto.getApiStyle()));
|
||||
po.setCreateBy(userId);
|
||||
po.setUpdateBy(userId);
|
||||
providerMapper.insert(po);
|
||||
@@ -123,6 +124,9 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
if (dto.getDisplayName() != null) {
|
||||
existing.setDisplayName(trimToNull(dto.getDisplayName()));
|
||||
}
|
||||
if (dto.getApiStyle() != null) {
|
||||
existing.setApiStyle(normalizeApiStyle(dto.getApiStyle()));
|
||||
}
|
||||
existing.setUpdateBy(userId);
|
||||
providerMapper.updateById(existing);
|
||||
evictRuntimeCache(companyId);
|
||||
@@ -432,6 +436,7 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
vo.setApiKey(crypto.decrypt(provider.getApiKeyEncrypted()));
|
||||
vo.setModel(model.getModel());
|
||||
vo.setContextWindow(model.getContextWindow());
|
||||
vo.setApiStyle(normalizeApiStyle(provider.getApiStyle()));
|
||||
vo.setExtraHeaders(parseHeaders(provider.getExtraHeadersJson()));
|
||||
return vo;
|
||||
}
|
||||
@@ -450,6 +455,17 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeApiStyle(String raw) {
|
||||
if (!StringUtils.hasText(raw)) {
|
||||
return "auto";
|
||||
}
|
||||
String s = raw.trim().toLowerCase();
|
||||
if ("auto".equals(s) || "completions".equals(s) || "responses".equals(s)) {
|
||||
return s;
|
||||
}
|
||||
throw new BusinessException("apiStyle 必须是 auto / completions / responses");
|
||||
}
|
||||
|
||||
private static Integer normalizeContextWindow(Integer raw) {
|
||||
if (raw == null || raw <= 0) {
|
||||
return null;
|
||||
@@ -546,6 +562,7 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
vo.setConfigured(true);
|
||||
vo.setBaseUrl(provider.getBaseUrl());
|
||||
vo.setDisplayName(provider.getDisplayName());
|
||||
vo.setApiStyle(normalizeApiStyle(provider.getApiStyle()));
|
||||
vo.setApiKeyMasked("****" + (provider.getApiKeySuffix() == null ? "" : provider.getApiKeySuffix()));
|
||||
if (provider.getUpdateTime() != null) {
|
||||
vo.setUpdateTime(provider.getUpdateTime().format(ISO));
|
||||
@@ -570,6 +587,7 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
payload.put("api_key", runtime.getApiKey());
|
||||
payload.put("model", runtime.getModel());
|
||||
payload.put("context_window", runtime.getContextWindow());
|
||||
payload.put("api_style", runtime.getApiStyle() == null ? "auto" : runtime.getApiStyle());
|
||||
payload.put("extra_headers",
|
||||
runtime.getExtraHeaders() == null ? Map.of() : runtime.getExtraHeaders());
|
||||
stringRedisTemplate.opsForValue().set(
|
||||
@@ -612,6 +630,8 @@ public class AgentCompanyLlmSettingsServiceImpl implements AgentCompanyLlmSettin
|
||||
} else {
|
||||
vo.setContextWindow(null);
|
||||
}
|
||||
Object style = map.get("api_style");
|
||||
vo.setApiStyle(style == null ? "auto" : normalizeApiStyle(String.valueOf(style)));
|
||||
Object headers = map.get("extra_headers");
|
||||
if (headers instanceof Map<?, ?> m) {
|
||||
Map<String, String> h = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user