feat(user-secret): 密钥设置支持 LLM 渠道与代理供应商切换
- 用户密钥新增 channel 列(V180):LLM 行存渠道 longtaitou/t8star,代理行存供应商 qingguo/jikip;存量与新建默认均回填 t8star/jikip(默认仍走贞贞与极客,手动可切) - 外观专利/货源查询按任务归属用户的密钥渠道路由 LLM 主机(渠道经 SecretUsageContext 下到工作线程,不逐层改签名);切到龙抬头时模型映射 gemini-3.1-flash-lite 并补 enable_thinking + thinking_budget=medium(对齐贞贞现网口径),检测链路刻意不思考 - 代理检测按供应商解析:青果 code 为字符串、隧道端点支持 域名:端口、 NO_AVAILABLE_CHANNEL 归为可重试;青果只验提取成功(账密只在客户端本地) - 密钥设置页:每个模块加渠道分段选择、代理卡加供应商选择与青果 Authkey/Authpwd (只存本机,不上报),切换渠道未重填密钥时拦住保存;换号继承带渠道与供应商 - 后管密钥管理三列显示渠道/供应商标签
This commit is contained in:
+17
-4
@@ -15,6 +15,7 @@ import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePate
|
||||
import com.nanri.aiimage.modules.brand.client.BrandCheckClient;
|
||||
import com.nanri.aiimage.modules.usersecret.service.UserSecretUsageService;
|
||||
import com.nanri.aiimage.modules.usersecret.support.SecretUsageContext;
|
||||
import com.nanri.aiimage.modules.usersecret.support.LlmChannel;
|
||||
import com.nanri.aiimage.modules.usersecret.support.UserSecretModule;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -668,7 +669,7 @@ public class AppearancePatentLlmClient {
|
||||
String responseFormat) throws Exception {
|
||||
int attempts = Math.max(1, properties.getLlmRetryTimes());
|
||||
long cooldownMillis = Math.max(0, properties.getLlmUnreachableCooldownMillis());
|
||||
String host = properties.getLlmHost();
|
||||
String host = resolveHost();
|
||||
if (unreachableCooldown.isCoolingDown(host, cooldownMillis)) {
|
||||
// 冷却期快失败不发请求、不记密钥次数(B24)
|
||||
log.debug("[appearance-patent] 客户端级冷却中,快速失败 model={} window={}ms", model, cooldownMillis);
|
||||
@@ -751,11 +752,17 @@ public class AppearancePatentLlmClient {
|
||||
int attempt) {
|
||||
recordSecretUsage();
|
||||
Map<String, Object> body = buildChatBody(model, system, userText, images, responseFormat);
|
||||
log.info("[appearance-patent] llm request attempt={} model={} url={} body={}",
|
||||
attempt, model, joinUrl(properties.getLlmHost(), "/v1/chat/completions"),
|
||||
String host = resolveHost();
|
||||
// 渠道模型映射:龙抬头那边的同款模型叫 gemini-3.1-flash-lite,直接发贞贞的模型名会 model_not_found
|
||||
String requestModel = LlmChannel.modelForHost(host, model);
|
||||
body.put("model", requestModel);
|
||||
// 思考参数按渠道补:贞贞把 thinking 写在模型名里,龙抬头要显式传(复刻现网的 thinking-medium)
|
||||
LlmChannel.applyThinkingForHost(host, body);
|
||||
log.info("[appearance-patent] llm request attempt={} model={} channelModel={} url={} body={}",
|
||||
attempt, model, requestModel, joinUrl(host, "/v1/chat/completions"),
|
||||
writeJson(maskChatBody(body)));
|
||||
RestClient.RequestBodySpec request = restClient(attempt).post()
|
||||
.uri(joinUrl(properties.getLlmHost(), "/v1/chat/completions"))
|
||||
.uri(joinUrl(host, "/v1/chat/completions"))
|
||||
.headers(headers -> {
|
||||
headers.setBearerAuth(stripBearer(apiKey));
|
||||
headers.setContentType(APPLICATION_JSON_UTF8);
|
||||
@@ -1505,6 +1512,12 @@ public class AppearancePatentLlmClient {
|
||||
return normalized.regionMatches(true, 0, "Bearer ", 0, 7) ? normalized.substring(7).trim() : normalized;
|
||||
}
|
||||
|
||||
/** 渠道主机:优先取任务上下文里按用户密钥渠道解析出的主机(龙抬头/贞贞),否则回落模块全局配置。 */
|
||||
private String resolveHost() {
|
||||
String contextual = SecretUsageContext.currentLlmHost();
|
||||
return contextual == null ? properties.getLlmHost() : contextual;
|
||||
}
|
||||
|
||||
private String joinUrl(String baseUrl, String path) {
|
||||
String base = baseUrl == null ? "" : baseUrl.trim();
|
||||
String suffix = path == null ? "" : path.trim();
|
||||
|
||||
+4
-1
@@ -74,6 +74,7 @@ import com.nanri.aiimage.modules.task.model.vo.TaskProgressLightBatchVo;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressLightAssembler;
|
||||
import com.nanri.aiimage.modules.task.service.pipeline.AbstractFileTaskPipeline;
|
||||
import com.nanri.aiimage.modules.usersecret.service.UserApiSecretService;
|
||||
import com.nanri.aiimage.modules.usersecret.support.UserSecretModule;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -410,7 +411,9 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
properties, llmClient, taskCacheService, taskFileJobService,
|
||||
rowReader()::rowKey, this::shouldInspectRow, rowReader()::readChunkRows, this::loadSubmittedChunks,
|
||||
this::isResultSubmissionComplete, this::touchJavaSideTaskActivity,
|
||||
llmSubmission::readAiPrompt, llmSubmission::readApiKey, this::mergeChunkPayload, this::firstNonBlank,
|
||||
llmSubmission::readAiPrompt, llmSubmission::readApiKey,
|
||||
task -> userApiSecretService.resolveLlmHost(task.getUserId(), UserSecretModule.APPEARANCE_PATENT),
|
||||
this::mergeChunkPayload, this::firstNonBlank,
|
||||
this::terminalizeTaskOnFatalLlmFailure);
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -81,6 +81,8 @@ public class AppearancePatentLlmBatchPipeline {
|
||||
private final Consumer<Long> taskActivityToucher;
|
||||
private final Function<FileTaskEntity, String> promptReader;
|
||||
private final Function<FileTaskEntity, String> apiKeyReader;
|
||||
/** 按任务归属用户密钥的渠道解析 LLM 主机(龙抬头/贞贞);为空表示走模块全局配置。 */
|
||||
private final Function<FileTaskEntity, String> apiHostReader;
|
||||
private final ChunkRowMerger chunkRowMerger;
|
||||
private final BiFunction<String, String, String> firstNonBlankFn;
|
||||
private final FatalLlmFailureHandler fatalLlmFailureHandler;
|
||||
@@ -97,6 +99,7 @@ public class AppearancePatentLlmBatchPipeline {
|
||||
Consumer<Long> taskActivityToucher,
|
||||
Function<FileTaskEntity, String> promptReader,
|
||||
Function<FileTaskEntity, String> apiKeyReader,
|
||||
Function<FileTaskEntity, String> apiHostReader,
|
||||
ChunkRowMerger chunkRowMerger,
|
||||
BiFunction<String, String, String> firstNonBlankFn,
|
||||
FatalLlmFailureHandler fatalLlmFailureHandler) {
|
||||
@@ -112,6 +115,7 @@ public class AppearancePatentLlmBatchPipeline {
|
||||
this.taskActivityToucher = taskActivityToucher;
|
||||
this.promptReader = promptReader;
|
||||
this.apiKeyReader = apiKeyReader;
|
||||
this.apiHostReader = apiHostReader;
|
||||
this.chunkRowMerger = chunkRowMerger;
|
||||
this.firstNonBlankFn = firstNonBlankFn;
|
||||
this.fatalLlmFailureHandler = fatalLlmFailureHandler;
|
||||
@@ -130,6 +134,8 @@ public class AppearancePatentLlmBatchPipeline {
|
||||
}
|
||||
String prompt = promptReader.apply(task);
|
||||
String apiKey = apiKeyReader.apply(task);
|
||||
// 渠道主机在任务级解析一次:同一任务的批次都发往同一个中转(密钥属于谁就发谁那家)
|
||||
String apiHost = apiHostReader == null ? null : apiHostReader.apply(task);
|
||||
int batchSize = Math.max(1, properties.getLlmBatchSize());
|
||||
ChunkRowKeyIndex rowKeyIndex = new ChunkRowKeyIndex();
|
||||
List<AppearancePatentResultRowDto> candidates = terminalizeRoundExhaustedRows(
|
||||
@@ -177,7 +183,7 @@ public class AppearancePatentLlmBatchPipeline {
|
||||
boolean batchAnswered = true;
|
||||
try {
|
||||
llmRows = SecretUsageContext.call(task.getUserId(), UserSecretModule.APPEARANCE_PATENT.key(),
|
||||
() -> llmClient.inspectRows(batchRows, prompt, apiKey));
|
||||
apiHost, () -> llmClient.inspectRows(batchRows, prompt, apiKey));
|
||||
} catch (Exception ex) {
|
||||
String message = firstNonBlank(ex.getMessage(), "LLM 检测失败");
|
||||
if (AppearancePatentResultJobSupport.isFatalLlmArrearsFailure(message)) {
|
||||
|
||||
Reference in New Issue
Block a user