Browse Source

公文特殊处理 传工具过来

wangmiaomiao 8 months ago
parent
commit
fef37ed06c

+ 15 - 7
slibra-admin/src/main/java/com/slibra/web/controller/business/GRPCController.java

@@ -11,7 +11,6 @@ import com.slibra.business.res.WorkOrderRes;
 import com.slibra.business.service.IFrontService;
 import com.slibra.common.DecimalUtils;
 import com.slibra.common.config.BigModelConfig;
-import com.slibra.common.constant.MyConstants;
 import com.slibra.common.core.controller.BaseController;
 import com.slibra.common.core.domain.DecisionReq;
 import com.slibra.common.core.domain.TXinyiDaily;
@@ -37,8 +36,6 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.util.*;
 
 import static com.slibra.common.constant.MyConstants.*;
@@ -494,7 +491,8 @@ public class GRPCController extends BaseController {
         StringBuilder sb = new StringBuilder();
         String sessionId = chatReq.getSessionId();
         int isStrong = Objects.isNull(chatReq.getIsStrong()) ? 0 : chatReq.getIsStrong();
-        boolean tools = true;//问答因为不确认是否走工具,所以传true; 但是工单一定是不用工具的,传false
+        String tools = null;
+        boolean toolsFlag = true;//问答因为不确认是否走工具,所以传true; 但是工单一定是不用工具的,传false
         boolean useRag = true;//只有问答才传true,其他默认都false
         //如果是工单,需要特殊处理一下showVal和question
         if(1 == module){
@@ -548,7 +546,7 @@ public class GRPCController extends BaseController {
                 chatReq.setRemark(JSON.toJSONString(frontService.customWorkOrderHandleByData(workOrderReq, workOrderRes), JSONWriter.Feature.WriteNulls));
             }
             isStrong = 1;
-            tools = false;
+            toolsFlag = false;
             useRag = false;
         }
         String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型
@@ -578,6 +576,16 @@ 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字符串
+            //2024年7月27日18:13:47  前端传过来tools
+            String toolsReq = chatReq.getTools();
+            if(StringUtils.isNotBlank(toolsReq)){
+                useRag = false;//2024年7月27日18:20:23 走本地工具,不需要文本增强
+                isStrong = 0;
+                tools = toolsReq;
+            }
+            else
+                tools = String.valueOf(toolsFlag);
+
             String dataJson = buildBigModelReqForChat(sessionId, historyDates, ipAddr, isStrong, chatReq.getTopP(), chatReq.getTemperature(), tools, useRag);
 //            log.info("请求大模型的问答参数为{}", dataJson);
             PredictionsRequest request = PredictionsRequest.newBuilder()
@@ -635,7 +643,7 @@ public class GRPCController extends BaseController {
 //        return AjaxResult.success("ok");
     }
 
-    private String buildBigModelReqForChat(String sessionId, List<String> historyDates, String ipAddr, int isStrong, Double topP, Double temperature, boolean tools, boolean useRag) {
+    private String buildBigModelReqForChat(String sessionId, List<String> historyDates, String ipAddr, int isStrong, Double topP, Double temperature, String tools, boolean useRag) {
         ChatRequest chatRequest = new ChatRequest();
         chatRequest.setSessionId(sessionId);
         chatRequest.setHistoryDia(historyDates);
@@ -648,7 +656,7 @@ public class GRPCController extends BaseController {
         extra.put("ip_address", ipAddr);
         chatRequest.setExtra(extra);
         chatRequest.setStrengthen(isStrong == 1);
-        chatRequest.setTools(String.valueOf(tools));
+        chatRequest.setTools(tools);
         chatRequest.setUseRag(useRag);
         return JSON.toJSONString(chatRequest);
     }

+ 10 - 0
slibra-system/src/main/java/com/slibra/business/req/ChatReq.java

@@ -114,6 +114,16 @@ public class ChatReq extends TXinyiChatRecord {
 
     private Double temperature;
 
+    //2024年7月27日18:12:45 新增参数
+    private String tools;
+
+    public String getTools() {
+        return tools;
+    }
+
+    public void setTools(String tools) {
+        this.tools = tools;
+    }
 
     public Double getTopP() {
         return topP;