|
@@ -118,8 +118,8 @@ public class GRPCController extends BaseController {
|
|
|
//决策请求的业务参数
|
|
|
List<DecisionReq> decisionReqs = getDecisionReqs();
|
|
|
// String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
|
|
|
- String dataJson = "";
|
|
|
boolean needAdd = true;//标识变量是否可以保存
|
|
|
+ String dataJson = "";
|
|
|
try {
|
|
|
channel = ManagedChannelBuilder.forAddress("10.0.0.24", 17070)
|
|
|
.usePlaintext()
|
|
@@ -127,20 +127,7 @@ public class GRPCController extends BaseController {
|
|
|
InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
|
|
|
// dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"" + chatReq.getCategory() + "\",\"feedback\":" + feedback + ",\"simulate\":" + simulate + ",\"session_id\":" + "\"" + sessionId + "\"" + ",\"generate_args\":{\"max_new_tokens\":1024,\"max_length\":4096,\"num_beams\":1,\"do_sample\":true,\"top_p\":0.7,\"temperature\":0.95},\"extra\":{\"rows\":" + rows + "}}";
|
|
|
//2024年6月24日17:59:17 优化,不再拼接JSON字符串
|
|
|
- PolicyReq policyReq = new PolicyReq();
|
|
|
- policyReq.setNorm(chatReq.getCategory());
|
|
|
- policyReq.setFeedback(StringUtils.isBlank(feedback) ? null : JSON.parseObject(feedback, Map.class));
|
|
|
- policyReq.setSimulate(StringUtils.isBlank(simulate) ? null : JSON.parseObject(simulate, Map.class));
|
|
|
- policyReq.setSessionId(sessionId);
|
|
|
- HashMap<String, Object> map = new HashMap<>();
|
|
|
- map.put("rows", decisionReqs);
|
|
|
- //2024年6月25日14:16:05 增加报警是管控值报警还是标准值报警
|
|
|
- if(WARNING_LEVEL_ONE.equals(xinyiWarningRecord.getLevel()) || WARNING_LEVEL_TWO.equals(xinyiWarningRecord.getLevel()))
|
|
|
- map.put("source", "bzz");
|
|
|
- else
|
|
|
- map.put("source", "gkz");
|
|
|
- policyReq.setExtra(map);
|
|
|
- dataJson = JSON.toJSONString(policyReq, JSONWriter.Feature.WriteNulls);
|
|
|
+ dataJson = buildBigModelReqForDecision(chatReq, feedback, simulate, sessionId, decisionReqs, xinyiWarningRecord);
|
|
|
log.info("请求大模型的决策的参数为{}", dataJson);
|
|
|
PredictionsRequest request = PredictionsRequest.newBuilder()
|
|
|
.setModelName("slibra_bot")
|
|
@@ -220,7 +207,24 @@ public class GRPCController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void addChatRecord(ChatReq chatReq, String sessionId, int type, String warningId, String dataJson, List<String> resultData) {
|
|
|
+ private static String buildBigModelReqForDecision(ChatReq chatReq, String feedback, String simulate, String sessionId, List<DecisionReq> decisionReqs, TXinyiWarningRecord xinyiWarningRecord) {
|
|
|
+ PolicyReq policyReq = new PolicyReq();
|
|
|
+ policyReq.setNorm(chatReq.getCategory());
|
|
|
+ policyReq.setFeedback(StringUtils.isBlank(feedback) ? null : JSON.parseObject(feedback, Map.class));
|
|
|
+ policyReq.setSimulate(StringUtils.isBlank(simulate) ? null : JSON.parseObject(simulate, Map.class));
|
|
|
+ policyReq.setSessionId(sessionId);
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("rows", decisionReqs);
|
|
|
+ //2024年6月25日14:16:05 增加报警是管控值报警还是标准值报警
|
|
|
+ if(WARNING_LEVEL_ONE.equals(xinyiWarningRecord.getLevel()) || WARNING_LEVEL_TWO.equals(xinyiWarningRecord.getLevel()))
|
|
|
+ map.put("source", "bzz");
|
|
|
+ else
|
|
|
+ map.put("source", "gkz");
|
|
|
+ policyReq.setExtra(map);
|
|
|
+ return JSON.toJSONString(policyReq, JSONWriter.Feature.WriteNulls);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addChatRecord(ChatReq chatReq, String sessionId, int type, String warningId, String question, List<String> resultData) {
|
|
|
chatReq.setSessionId(sessionId);
|
|
|
chatReq.setType(type);//类型(0问答 1决策 2本地 3仿真预测)
|
|
|
chatReq.setModule(3);//0=专家问答,1=智能工单,2=智能体助手,3.告警
|
|
@@ -230,7 +234,7 @@ public class GRPCController extends BaseController {
|
|
|
List<TXinyiChatRecord> tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).build());
|
|
|
if(!CollectionUtils.isEmpty(tXinyiChatRecords))
|
|
|
chatReq.setShowVal(tXinyiChatRecords.get(0).getShowVal());
|
|
|
- chatReq.setQuestion(dataJson);
|
|
|
+ chatReq.setQuestion(question);
|
|
|
chatReq.setAnswer(JSON.toJSONString(resultData));
|
|
|
chatReq.setWarningId(warningId);
|
|
|
chatReq.setCounts(1);//问答次数
|
|
@@ -409,14 +413,7 @@ public class GRPCController extends BaseController {
|
|
|
InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
|
|
|
// String dataJson = "{\"bot_id\":\"721\",\"exp_id\":\"721\",\"session_id\":\"" + sessionId + "\",\"use_rag\":\"true\",\"prompt\":\"你是LibraAI水务大模型,由红杉天枰开发的水务垂直大语言模型,能够提供水务行业专家问答、智能决策、报表分析、智能工单管理等一系列功能,作为水务人的AI助手,你会竭尽全力帮助我处理工作问题。\",\"history_dia\":" + JSON.toJSONString(historyDates) + ",\"generate_args\":{\"max_new_tokens\":2048,\"max_length\":4096,\"num_beams\":1,\"do_sample\":true,\"top_p\":0.7,\"temperature\":0.95},\"extra\":{ \"ip_address\": \"" + ipAddr + "\" },\"strengthen\":" + (isStrong == 1) + "}";
|
|
|
//2024年6月25日18:12:23 优化,不再使用拼接JSON字符串
|
|
|
- ChatRequest chatRequest = new ChatRequest();
|
|
|
- chatRequest.setSessionId(sessionId);
|
|
|
- chatRequest.setHistoryDia(historyDates);
|
|
|
- Map<String, Object> extra = new HashMap<>();
|
|
|
- extra.put("ip_address", ipAddr);
|
|
|
- chatRequest.setExtra(extra);
|
|
|
- chatRequest.setStrengthen(isStrong == 1);
|
|
|
- String dataJson = JSON.toJSONString(chatRequest);
|
|
|
+ String dataJson = buildBigModelReqForChat(sessionId, historyDates, ipAddr, isStrong);
|
|
|
log.info("请求大模型的问答参数为{}", dataJson);
|
|
|
PredictionsRequest request = PredictionsRequest.newBuilder()
|
|
|
.setModelName("slibra_bot")
|
|
@@ -475,6 +472,16 @@ public class GRPCController extends BaseController {
|
|
|
// return AjaxResult.success("ok");
|
|
|
}
|
|
|
|
|
|
+ private static String buildBigModelReqForChat(String sessionId, List<String> historyDates, String ipAddr, int isStrong) {
|
|
|
+ ChatRequest chatRequest = new ChatRequest();
|
|
|
+ chatRequest.setSessionId(sessionId);
|
|
|
+ chatRequest.setHistoryDia(historyDates);
|
|
|
+ Map<String, Object> extra = new HashMap<>();
|
|
|
+ extra.put("ip_address", ipAddr);
|
|
|
+ chatRequest.setExtra(extra);
|
|
|
+ chatRequest.setStrengthen(isStrong == 1);
|
|
|
+ return JSON.toJSONString(chatRequest);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private String buildGDQuestionCustom(List<WorkOrderRes> workOrderRes, WorkOrderReq workOrderReq) {
|
|
@@ -717,8 +724,10 @@ public class GRPCController extends BaseController {
|
|
|
.usePlaintext()
|
|
|
.build();
|
|
|
InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
|
|
|
- String dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"出水氨氮\",\"session_id\":\" " + IdUtils.simpleUUID() + " \",\"extra\":{}}";
|
|
|
- log.info("请求大模型的问答参数为{}", dataJson);
|
|
|
+// String dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"出水氨氮\",\"session_id\":\" " + IdUtils.simpleUUID() + " \",\"extra\":{}}";
|
|
|
+ //2024年6月27日13:23:25 优化:改成非拼接JSON字符串
|
|
|
+ String dataJson = buildBigModelReqForPredictor("出水氨氮");
|
|
|
+ log.info("请求大模型的预测的参数为{}", dataJson);
|
|
|
PredictionsRequest request = PredictionsRequest.newBuilder()
|
|
|
.setModelName("slibra_bot")
|
|
|
.putInput("method", ByteString.copyFrom("predictor", "utf-8"))//推理
|
|
@@ -739,5 +748,12 @@ public class GRPCController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static String buildBigModelReqForPredictor(String type) {
|
|
|
+ PredictorRequest predictorRequest = new PredictorRequest();
|
|
|
+ predictorRequest.setNorm(type);
|
|
|
+ predictorRequest.setSessionId(IdUtils.simpleUUID());
|
|
|
+ return JSON.toJSONString(predictorRequest);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|