فهرست منبع

prompt优化 调用决策接口调整

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

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

@@ -260,6 +260,7 @@ public class GRPCController extends BaseController {
                     }
                     //2024年6月1日08:37:09 内回流加上
                     decisionReq.setR(daily.getNhlR());
+                    decisionReq.setRR(daily.getWhlR());
                 }
             }
         }
@@ -351,6 +352,7 @@ public class GRPCController extends BaseController {
                 String question = this.buildGDQuestionCustom(workOrderRes, workOrderReq);
                 //2024年6月23日17:21:58  判断问题的长度,如果长度大于配置的值(5000),提示一句话
                 if(question.length() > MAX_QUESTION_LENGTH){
+                    log.info("*************自定义工单超长了,组装完的参数为{}", question);
                     try {
                         outputStream = response.getOutputStream();
                         outputStream.write(CHAT_GONGDAN_CUSTOM_ERROR_MSG.getBytes());
@@ -458,15 +460,15 @@ public class GRPCController extends BaseController {
             for (WorkOrderRes workOrderRe : workOrderRes) {
                 sb.append(workOrderRe.getTime()).append(":");
                 if(workOrderReq.getJsCod())
-                    sb.append("COD:").append(workOrderRe.getJsCod()).append("mg/L、");
+                    sb.append("进水COD:").append(workOrderRe.getJsCod()).append("mg/L、");
                 if(workOrderReq.getJsTn())
-                    sb.append("TN:").append(workOrderRe.getJsTn()).append("mg/L、");
+                    sb.append("进水总氮:").append(workOrderRe.getJsTn()).append("mg/L、");
                 if(workOrderReq.getJsTp())
-                    sb.append("TP:").append(workOrderRe.getJsTp()).append("mg/L、");
+                    sb.append("进水总磷:").append(workOrderRe.getJsTp()).append("mg/L、");
                 if(workOrderReq.getJsNh3())
-                    sb.append("NH3-N:").append(workOrderRe.getJsNh3()).append("mg/L、");
+                    sb.append("进水氨氮:").append(workOrderRe.getJsNh3()).append("mg/L、");
                 if(workOrderReq.getJsSs())
-                    sb.append("SS:").append(workOrderRe.getJsSs()).append("mg/L、");
+                    sb.append("进水SS:").append(workOrderRe.getJsSs()).append("mg/L、");
                 if(workOrderReq.getJsSlq())
                     sb.append("进水水量:").append(workOrderRe.getJsSlq()).append("m³/d、");
             }
@@ -476,17 +478,17 @@ public class GRPCController extends BaseController {
             for (WorkOrderRes workOrderRe : workOrderRes) {
                 sb.append(workOrderRe.getTime()).append(":");
                 if(workOrderReq.getCsCod())
-                    sb.append("COD:").append(workOrderRe.getCsCod()).append("mg/L、");
+                    sb.append("出水COD:").append(workOrderRe.getCsCod()).append("mg/L、");
                 if(workOrderReq.getCsTn())
-                    sb.append("TN:").append(workOrderRe.getCsTn()).append("mg/L、");
+                    sb.append("出水总氮:").append(workOrderRe.getCsTn()).append("mg/L、");
                 if(workOrderReq.getCsTp())
-                    sb.append("TP:").append(workOrderRe.getCsTp()).append("mg/L、");
+                    sb.append("出水总磷:").append(workOrderRe.getCsTp()).append("mg/L、");
                 if(workOrderReq.getCsNh3())
-                    sb.append("NH3-N:").append(workOrderRe.getCsNh3()).append("mg/L、");
+                    sb.append("出水氨氮:").append(workOrderRe.getCsNh3()).append("mg/L、");
                 if(workOrderReq.getCsSs())
-                    sb.append("SS:").append(workOrderRe.getCsSs()).append("mg/L、");
+                    sb.append("出水SS:").append(workOrderRe.getCsSs()).append("mg/L、");
                 if(workOrderReq.getCsSlqc())
-                    sb.append("水水量:").append(workOrderRe.getCsSlqc()).append("m³/d、");
+                    sb.append("水水量:").append(workOrderRe.getCsSlqc()).append("m³/d、");
             }
         }
         if(workOrderReq.getNo3Hlj1Jqr() || workOrderReq.getNo3Hlj2Jqr() || workOrderReq.getNh31Jqr() || workOrderReq.getNh32Jqr()

+ 18 - 3
slibra-common/src/main/java/com/slibra/common/constant/MyConstants.java

@@ -63,6 +63,7 @@ public class MyConstants {
     public static final int MAX_QUESTION_LENGTH = 5000;
 
     public static final int DAILY_RECORDS_TOTAL = 30;
+    public static final int DAILY_REPORT_COUNT_RECORD = 7;
     public static final String JIAN_BAO_END = "简报";
 
     //简报的prompt
@@ -86,6 +87,14 @@ public class MyConstants {
             "出水  -  COD:#{31}mg/L  、 TN:#{32}mg/L 、TP:#{33}mg/L、NH3-N:#{34}mg/L、SS:#{35}mg/L";
 
 
+    public static final String SHORT_REPORT_BEGIN = "作为一个工艺分析师,请生成一份#{0}分析报告,根据我提供的详细数据,输出一份详细的分析报告。报告需数据准确、分析深入,建议具体可行,以便为水务管理和决策提供支持。报告分为三部分:\n" +
+            "1、进出水水质指标表格呈现,下面分析水质数据指标超标情况分析。\n" +
+            "2、显示超标准值数据情况,并对比近七天数据,分析数据趋势 \n" +
+            "3、提出针对性的改善建议,包括优化处理工艺点,对于超标的数据推送解决方案,每项调整点不要太概括,一定要给出具体调整数据。";
+
+
+    public static final String SHORT_REPORT_END = "标准值定义:\n";
+
     /**
      * 生化报警提示词
      */
@@ -103,7 +112,7 @@ public class MyConstants {
 
     public static final String CHAT_GONGDAN_1_ERROR_MSG = "智能工单问答必须选择日期";
     public static final String CHAT_GONGDAN_2_ERROR_MSG = "很抱歉,当前日期指标没有数据,请查证后再试";
-    public static final String CHAT_GONGDAN_CUSTOM_ERROR_MSG = "您选择的自定义工单日期+指标项太多,请减少输入项";
+    public static final String CHAT_GONGDAN_CUSTOM_ERROR_MSG = "很抱歉,数据分析维度过多,请尝试减少时间区间或统计数据项再试...";
 
     public static final String GONGDAN_TITLE = "请生成#{0}智能工单分析报告";
     public static final String GONGDAN_TITLE_CUSTOM = "请成生#{0}-#{1}日的日报工单";
@@ -177,8 +186,14 @@ public class MyConstants {
             "1、指标数据的分析:";
 
     public static final String GONGDAN_PROMPT_CUSTOM_END_2 = "指标数据分析:\n" +
-            "分析所有关键水质和生化指标的达标情况,包括与国家标准和行业标准的对比。\n" +
-            "使用趋势分析法,分析水质情况\n" +
+            "\n" +
+            "分析所有关键水质和生化指标的达标情况,关键水质指标标准值为:\n" +
+            "\n" +
+            "进水COD:630mg/L、出水总磷:7.1mg/L、出水总氮:65mg/L、出水氨氮:58mg/L、出水SS:315mg/L\n" +
+            "\n" +
+            "出水COD:40mg/L、出水总磷:0.5mg/L、出水总氮:15mg/L、出水氨氮:415mg/L、出水SS:10mg/L\n" +
+            "\n" +
+            "使用趋势分析法,分析水质情况,列出超标项和有超标趋势的分析。" +
             "2、综合分析与建议:\n" +
             "根据上述数据,运用适当的分析方法,如工艺分析、数据趋势分析法、在线仪表与水质指标数据比对效果、预测分析法(分析出未来趋势),提出针对性的改善建议,包括但不限于优化处理工艺、加强水质监测、改善水源保护等。\n" +
             "结论:\n" +

+ 3 - 0
slibra-quartz/src/main/java/com/slibra/quartz/task/AsyncTask.java

@@ -885,6 +885,9 @@ public class AsyncTask {
                             decisionReq.setB(jsBod5.divide(tnIn, 4, RoundingMode.HALF_UP));
                         }
                     }
+                    //2024年6月1日08:37:09 内回流加上
+                    decisionReq.setR(daily.getNhlR());
+                    decisionReq.setRR(daily.getWhlR());
                 }
                 //如果是机器人化验室的报警,需要把总磷和总氮,获取化验室对应的数据且计算
                 if(isSpecial){

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

@@ -34,8 +34,8 @@ public class GetRealTimeData {
 
         // 给定时间段的起始时间和结束时间
 
-        LocalDateTime startTime = LocalDateTime.parse("2024-06-18T15:30:00");
-        LocalDateTime endTime = LocalDateTime.parse("2024-06-18T16:30:00");
+        LocalDateTime startTime = LocalDateTime.parse("2024-06-23T19:00:00");
+        LocalDateTime endTime = LocalDateTime.parse("2024-06-23T19:20:00");
 
         // 每个小时的时间格式
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

+ 48 - 5
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -752,6 +752,9 @@ public class RyTask
                             decisionReq.setB(jsBod5.divide(tnIn, 4, RoundingMode.HALF_UP));
                         }
                     }
+                    //2024年6月1日08:37:09 内回流加上
+                    decisionReq.setR(daily.getNhlR());
+                    decisionReq.setRR(daily.getWhlR());
                 }
             }
         }
@@ -1249,17 +1252,17 @@ public class RyTask
      * 定时生成每日简报数据
      *
      */
-    public void generageShortReport(){
+    public void generateShortReport(){
         log.info("进入了定时生成每日简报数据");
-        List<TXinyiDaily> dailyTwoRecords = this.xinyiDailyMapper.selectNRecords(2);
+        List<TXinyiDaily> dailyTwoRecords = this.xinyiDailyMapper.selectNRecords(DAILY_REPORT_COUNT_RECORD);
         //正常不会有这种问题 因为日报有很多条
-        if(CollectionUtils.isEmpty(dailyTwoRecords) || dailyTwoRecords.size() < 2){
-            log.error("进入了定时生成每日简报数据 获取最新的2条数据不足,终止");
+        if(CollectionUtils.isEmpty(dailyTwoRecords) || dailyTwoRecords.size() < DAILY_REPORT_COUNT_RECORD){
+            log.error("进入了定时生成每日简报数据 获取最新的{}条数据不足,终止", DAILY_REPORT_COUNT_RECORD);
             return;
         }
         //暂时不考虑因为没有填写日报 导致生成重复数据的问题(后续需要的话再添加)
         //处理数据 并 拼装
-        String queryData = buildShortReportQueryData(dailyTwoRecords);
+        String queryData = buildShortReportQueryDataNew(dailyTwoRecords);
         log.info("定时生成简报,组装好的请求大模型的参数为:{}", queryData);
         if(StringUtils.isBlank(queryData)){
             log.error("无法拼装请求数据!!!!!!");
@@ -2024,6 +2027,46 @@ public class RyTask
         return originStr;
     }
 
+    //2024年6月23日19:58:21 简报生成的prompt调整。
+    private String buildShortReportQueryDataNew(List<TXinyiDaily> dailyTwoRecords) {
+        //查询配置信息
+        List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
+        if(CollectionUtils.isEmpty(tXinyiNormConfigs))
+            return null;
+        TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
+        //获取数据
+        TXinyiDaily yesterdayData = dailyTwoRecords.get(0);
+        String originStr = SHORT_REPORT_BEGIN.replace("#{0}", yesterdayData.getTestDate());
+        StringBuilder sb = new StringBuilder(originStr);
+        for (TXinyiDaily dailyTwoRecord : dailyTwoRecords) {
+            sb.append("进水:");
+            sb.append("进水COD").append(dailyTwoRecord.getJsCod()).append("mg/L");
+            sb.append("进水总氮").append(dailyTwoRecord.getJsTn()).append("mg/L");
+            sb.append("进水总磷").append(dailyTwoRecord.getJsTp()).append("mg/L");
+            sb.append("进水氨氮").append(dailyTwoRecord.getJsNh3()).append("mg/L");
+            sb.append("进水SS").append(dailyTwoRecord.getJsSs()).append("mg/L");
+            sb.append("进水水量").append(dailyTwoRecord.getJSL()).append("m³/d").append(";");
+            sb.append("出水:");
+            sb.append("出水COD").append(dailyTwoRecord.getCsCod()).append("mg/L");
+            sb.append("出水总氮").append(dailyTwoRecord.getCsTn()).append("mg/L");
+            sb.append("出水总磷").append(dailyTwoRecord.getCsTp()).append("mg/L");
+            sb.append("出水氨氮").append(dailyTwoRecord.getCsNh3()).append("mg/L");
+            sb.append("出水SS").append(dailyTwoRecord.getCsSs()).append("mg/L");
+            sb.append("出水水量").append(dailyTwoRecord.getCSL()).append("m³/d").append("。");
+        }
+        sb.append(SHORT_REPORT_END);
+        sb.append("进水COD:").append(normConfig.getJscodSjz()).append("mg/L");
+        sb.append("进水总氮:").append(normConfig.getJszdSjz()).append("mg/L");
+        sb.append("进水总磷:").append(normConfig.getJszlSjz()).append("mg/L");
+        sb.append("进水氨氮:").append(normConfig.getJsadSjz()).append("mg/L");
+        sb.append("进水SS:").append(normConfig.getJsssSjz()).append("mg/L");
+        sb.append("出水COD:").append(normConfig.getCscodBzz()).append("mg/L");
+        sb.append("出水总氮:").append(normConfig.getCszzBzz()).append("mg/L");
+        sb.append("出水总磷:").append(normConfig.getCszlBzz()).append("mg/L");
+        sb.append("出水氨氮:").append(normConfig.getCsadBzz()).append("mg/L");
+        sb.append("出水SS:").append(normConfig.getCsssBzz()).append("mg/L").append("。");
+        return sb.toString();
+    }
 
     public static String handleDate(String str){
         StringBuilder sb = new StringBuilder();

+ 9 - 0
slibra-system/src/main/java/com/slibra/business/req/DecisionReq.java

@@ -104,8 +104,10 @@ public class DecisionReq {
     @JSONField(name = "TDS_in_name")
     private BigDecimal tdsInName = null;
 
+    @JSONField(name = "T")
     private BigDecimal T  = null;
 
+    @JSONField(name = "pH")
     private BigDecimal pH = null;
 
     @JSONField(name = "Q_in")
@@ -125,11 +127,13 @@ public class DecisionReq {
     @JSONField(name = "cs_continuity")
     private String csContinuity = null;
 
+    @JSONField(name = "SVI")
     private String SVI = null;
 
     @JSONField(name = "SVI_con")
     private BigDecimal sviCon = null;
 
+    @JSONField(name = "SV")
     private String SV = null;
 
     @JSONField(name = "SV_con")
@@ -168,8 +172,10 @@ public class DecisionReq {
     @JSONField(name = "BOD_in")
     private BigDecimal bodIn = null;
 
+    @JSONField(name = "c")
     private BigDecimal c = null;
 
+    @JSONField(name = "b")
     private BigDecimal b = null;
 
     @JSONField(name = "BTP_wending")
@@ -216,4 +222,7 @@ public class DecisionReq {
     @JSONField(name = "r")
     private BigDecimal r;
 
+    @JSONField(name = "R")
+    private BigDecimal RR;
+
 }

+ 3 - 2
slibra-system/src/main/java/com/slibra/business/service/impl/FrontServiceImpl.java

@@ -104,13 +104,14 @@ public class FrontServiceImpl implements IFrontService {
 
     /**
      * 2024年6月23日17:30:07  因为只展示一条数据,所以判断是不是最后一条数据是report类型的,如果是就返回; 如果不是,获取是定时任务生成的最近的一条数据
+     * 2024年6月23日20:13:34  因为决策和预测走的同一个接口,所以把type去掉,否则type为1获取不到预测数据
      * @param warningId
      * @return
      */
     @Override
     public TXinyiChatRecord qaDetailByWarningId(String warningId) {
         //2024年5月28日19:10:21 只获取决策的 因为决策和仿真预测是一个接口,所以通过类型区分
-        List<TXinyiChatRecord> tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).type(1).build());
+        List<TXinyiChatRecord> tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).build());
         if(CollectionUtils.isEmpty(tXinyiChatRecords))
             return null;
         TXinyiChatRecord tXinyiChatRecord = tXinyiChatRecords.get(0);
@@ -118,7 +119,7 @@ public class FrontServiceImpl implements IFrontService {
         if(tXinyiChatRecord.getAnswer().contains(DECISION_REPORT.getCode()))
             return tXinyiChatRecord;
         else{
-            tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).type(1).userId(WARNING_DEFAULT_CREATE).build());
+            tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).userId(WARNING_DEFAULT_CREATE).build());
             return CollectionUtils.isEmpty(tXinyiChatRecords) ? null : tXinyiChatRecords.get(0);
         }
     }