From 77f0205db7a5b9f3d0da4c8e18b7a706d5cf37b7 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Tue, 17 Mar 2026 17:06:31 +0800
Subject: [PATCH] refactor(yinhe): 移除产品ID查询条件和DTO字段
---
src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliApplicationLlmStrategyServiceImpl.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliApplicationLlmStrategyServiceImpl.java b/src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliApplicationLlmStrategyServiceImpl.java
index 6b5f9e7..1df1f7e 100644
--- a/src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliApplicationLlmStrategyServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliApplicationLlmStrategyServiceImpl.java
@@ -7,6 +7,7 @@
import cc.mrbird.febs.ai.strategy.param.LlmStrategyDto;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.exception.FebsException;
+import cc.mrbird.febs.yinhe.req.AiRequestDto;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
@@ -34,7 +35,7 @@
@Component("AliApplicationLlmStrategyServiceImpl")
public class AliApplicationLlmStrategyServiceImpl implements LlmStrategyService {
- private static final String apiKey = "sk-babdcf8799144134915cee2683794b2f";
+ private static final String apiKey = "sk-4b97b556ba7c4350a41f2856f75b9377";
private final String bizParam_1 = "prompt_ai_system";
private final String bizParam_2 = "question";
@@ -60,6 +61,36 @@
return bizParamsMap;
}
+ private List<Message> getMessages(List<LlmStrategyDto> dto) {
+ List<Message> messages = new ArrayList<>();
+ for (LlmStrategyDto item : dto){
+ if (StrUtil.equals(item.getRole(),AiTypeEnum.MESSAGES.getName())){
+ List<LlmStrategyDto> messagesList = item.getMessages();
+ for (LlmStrategyDto dtoItem : messagesList){
+ if (StrUtil.equals(dtoItem.getRole(),Role.SYSTEM.getValue())){
+ messages.add(Message.builder()
+ .role(Role.SYSTEM.getValue())
+ .content(dtoItem.getContent())
+ .build());
+ }
+ if (StrUtil.equals(dtoItem.getRole(),Role.USER.getValue())){
+ messages.add(Message.builder()
+ .role(Role.USER.getValue())
+ .content(dtoItem.getContent())
+ .build());
+ }
+ if (StrUtil.equals(dtoItem.getRole(),Role.ASSISTANT.getValue())){
+ messages.add(Message.builder()
+ .role(Role.ASSISTANT.getValue())
+ .content(dtoItem.getContent())
+ .build());
+ }
+ }
+ }
+ }
+ return messages;
+ }
+
private String getQuery(List<LlmStrategyDto> dto) {
String query = null;
for (LlmStrategyDto dtoItem : dto){
@@ -77,6 +108,17 @@
if (StrUtil.equals(dtoItem.getRole(),Role.TOOL.getValue())){
int code = Integer.parseInt(dtoItem.getContent());
appId = LlmApplicationAppIdEnum.HIGH_LIGHT.getAppIdByCode(code);
+ break;
+ }
+ }
+ return appId;
+ }
+
+ private String getAppIdV2(List<LlmStrategyDto> dto) {
+ String appId = null;
+ for (LlmStrategyDto dtoItem : dto){
+ if (StrUtil.equals(dtoItem.getRole(),Role.TOOL.getValue())){
+ appId = dtoItem.getContent();
break;
}
}
@@ -166,7 +208,8 @@
}
HashMap prompt = getPrompt(dto);
String query = getQuery(dto);
- String appId = getAppId(dto);
+// String appId = getAppId(dto);
+ String appId = getAppIdV2(dto);
if (prompt == null || prompt.size() == 0){
throw new FebsException("百炼工作流初始化异常");
}
@@ -176,6 +219,8 @@
if (appId == null){
throw new FebsException("百炼工作流初始化异常");
}
+
+ List<Message> messages = getMessages(dto);
long startTime = System.currentTimeMillis();
ApplicationParam param = ApplicationParam.builder()
// 若没有配置环境变量,可用百炼API Key将下行替换为:.apiKey("sk-xxx")。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
@@ -183,6 +228,7 @@
.appId(appId) //替换为实际的应用 ID
.flowStreamMode(FlowStreamMode.MESSAGE_FORMAT)
.prompt(query)
+ .messages( messages)
.bizParams(JsonUtils.toJsonObject( prompt))
.build();
@@ -210,4 +256,9 @@
throw new FebsException(StrUtil.format("百炼工作流输出失败:{}",error));
});
}
+
+ @Override
+ public Flux<FebsResponse> llmInvokeStreamingNoThink(AiRequestDto aiRequestDto) {
+ return null;
+ }
}
--
Gitblit v1.9.1