فهرست منبع

调用决策优化

wangmiaomiao 9 ماه پیش
والد
کامیت
c0749587dc

+ 13 - 2
slibra-admin/src/main/java/com/slibra/web/controller/business/GRPCController.java

@@ -8,6 +8,7 @@ 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.req.WorkOrderReq;
 import com.slibra.business.res.WorkOrderRes;
 import com.slibra.business.service.IFrontService;
@@ -120,7 +121,7 @@ public class GRPCController extends BaseController {
             type = 1;//决策
         //决策请求的业务参数
         List<DecisionReq> decisionReqs = getDecisionReqs();
-        String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
+//        String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
         String dataJson = "";
         boolean needAdd = true;//标识变量是否可以保存
         try {
@@ -128,7 +129,17 @@ public class GRPCController extends BaseController {
                     .usePlaintext()
                     .build();
             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 + "}}";
+//            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);
+            policyReq.setExtra(map);
+            dataJson = JSON.toJSONString(policyReq, JSONWriter.Feature.WriteNulls);
             log.info("请求大模型的决策的参数为{}", dataJson);
             PredictionsRequest request = PredictionsRequest.newBuilder()
                     .setModelName("slibra_bot")

+ 4 - 2
slibra-system/src/main/java/com/slibra/business/req/ChatReq.java

@@ -14,10 +14,12 @@ public class ChatReq extends TXinyiChatRecord {
 
 
     //决策里是否携带alert的
-    private String feedback = "{}";
+//    private String feedback = "{}";
+    private String feedback;
 
     //2024年5月28日17:38:00 新增的请求参数 调用预测接口需要传该值
-    private String simulate = "{}";
+//    private String simulate = "{}";
+    private String simulate;
 
     /** 告警记录ID */
     @Excel(name = "告警记录ID")

+ 33 - 0
slibra-system/src/main/java/com/slibra/business/req/GenerateArgs.java

@@ -0,0 +1,33 @@
+package com.slibra.business.req;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class GenerateArgs {
+
+    @JSONField(name = "max_new_tokens")
+    private int maxNewTokens = 1024;
+
+    @JSONField(name = "max_length")
+    private int maxLength = 4096;
+
+    @JSONField(name = "num_beams")
+    private int numBeams = 1;
+
+    @JSONField(name = "do_sample")
+    private boolean doSample = true;
+
+    @JSONField(name = "top_p")
+    private double tooP = 0.7D;
+
+    @JSONField(name = "temperature")
+    private double temperature = 0.95D;
+}

+ 41 - 0
slibra-system/src/main/java/com/slibra/business/req/PolicyReq.java

@@ -0,0 +1,41 @@
+package com.slibra.business.req;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
+
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class PolicyReq {
+
+    @JSONField(name = "bot_id")
+    private String botId = "b00001";
+
+    @JSONField(name = "exp_id")
+    private String expId = "721";
+
+    @JSONField(name = "norm")
+    private String norm;
+
+    @JSONField(name = "feedback")
+    private Map<String, Object> feedback;
+
+    @JSONField(name = "simulate")
+    private Map<String, Object> simulate;
+
+    @JSONField(name = "session_id")
+    private String sessionId;
+
+    @JSONField(name = "generate_args")
+    private GenerateArgs generateArgs = new GenerateArgs();
+
+    @JSONField(name = "extra")
+    private Map<String, Object> extra;
+}