Browse Source

问答优化 预测报警调整

wangmiaomiao 9 tháng trước cách đây
mục cha
commit
ad0c6cbbc7

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

@@ -6,10 +6,7 @@ import com.alibaba.fastjson2.JSON;
 import com.google.protobuf.ByteString;
 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.req.*;
 import com.slibra.business.res.WorkOrderRes;
 import com.slibra.business.service.IFrontService;
 import com.slibra.common.core.controller.BaseController;
@@ -405,7 +402,16 @@ public class GRPCController extends BaseController {
                     .usePlaintext()
                     .build();
             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) + "}";
+//            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);
             log.info("请求大模型的问答参数为{}", dataJson);
             PredictionsRequest request = PredictionsRequest.newBuilder()
                     .setModelName("slibra_bot")

+ 8 - 0
slibra-system/src/main/java/com/slibra/business/domain/TXinyiWarningRecord.java

@@ -2,6 +2,8 @@ package com.slibra.business.domain;
 
 import java.math.BigDecimal;
 import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -114,4 +116,10 @@ public class TXinyiWarningRecord extends BaseEntity
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
     private Date createTime;
 
+
+    /** 更新时间 */
+    @TableField(exist = false)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
+    private Date updateTime;
+
 }

+ 46 - 0
slibra-system/src/main/java/com/slibra/business/req/ChatRequest.java

@@ -0,0 +1,46 @@
+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.List;
+import java.util.Map;
+
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class ChatRequest {
+
+    @JSONField(name = "bot_id")
+    private String botId = "721";
+
+    @JSONField(name = "exp_id")
+    private String expId = "721";
+
+    @JSONField(name = "session_id")
+    private String sessionId;
+
+    @JSONField(name = "use_rag")
+    private String useRag = "true";
+
+    @JSONField(name = "prompt")
+    private String prompt = "你是LibraAI水务大模型,由红杉天枰开发的水务垂直大语言模型,能够提供水务行业专家问答、智能决策、报表分析、智能工单管理等一系列功能,作为水务人的AI助手,你会竭尽全力帮助我处理工作问题。";
+
+    @JSONField(name = "history_dia")
+    private List<String> historyDia;
+
+    @JSONField(name = "generate_args")
+    private GenerateArgs generateArgs = new GenerateArgs(2048);
+
+    @JSONField(name = "extra")
+    private Map<String, Object> extra;
+
+    @JSONField(name = "strengthen")
+    private Boolean strengthen;
+
+}

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

@@ -30,4 +30,9 @@ public class GenerateArgs {
 
     @JSONField(name = "temperature")
     private double temperature = 0.95D;
+
+
+    public GenerateArgs(int maxNewTokens) {
+        this.maxNewTokens = maxNewTokens;
+    }
 }