소스 검색

所有调用决策的地方 全部处理非JSON字符串拼接 新增请求参数是标准值超标还是管控值超标

wangmiaomiao 9 달 전
부모
커밋
7d90c60641

+ 5 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/GRPCController.java

@@ -138,6 +138,11 @@ public class GRPCController extends BaseController {
             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);
             log.info("请求大模型的决策的参数为{}", dataJson);

+ 19 - 2
slibra-quartz/src/main/java/com/slibra/quartz/task/AsyncTask.java

@@ -8,10 +8,12 @@ import com.slibra.business.domain.*;
 import com.slibra.business.mapper.*;
 import com.slibra.business.req.ChatReq;
 import com.slibra.business.req.DecisionReq;
+import com.slibra.business.req.PolicyReq;
 import com.slibra.business.res.ShowValueBasic;
 import com.slibra.common.constant.MyConstants;
 import com.slibra.common.enums.BusinessEnum;
 import com.slibra.common.utils.DateUtils;
+import com.slibra.common.utils.StringUtils;
 import com.slibra.common.utils.uuid.IdUtils;
 import inference.InferenceAPIsServiceGrpc;
 import inference.PredictionResponse;
@@ -912,7 +914,7 @@ public class AsyncTask {
                 }
             }
         }
-        String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
+//        String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
         // 获取输出流
         ManagedChannel channel = null;
         String dataJson = "";
@@ -921,7 +923,22 @@ public class AsyncTask {
                     .usePlaintext()
                     .build();
             InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
-            dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"" + tXinyiWarningRecord.getCategory() + "\",\"feedback\":" + feedback + ",\"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 + "}}";
+//            dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"" + tXinyiWarningRecord.getCategory() + "\",\"feedback\":" + feedback + ",\"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(tXinyiWarningRecord.getLevel()) || WARNING_LEVEL_TWO.equals(tXinyiWarningRecord.getLevel()))
+                map.put("source", "bzz");
+            else
+                map.put("source", "gkz");
+            policyReq.setExtra(map);
+            dataJson = JSON.toJSONString(policyReq, JSONWriter.Feature.WriteNulls);
             log.info("请求大模型的决策的参数为{}", dataJson);
             PredictionsRequest request = PredictionsRequest.newBuilder()
                     .setModelName("slibra_bot")