ShuanghongS пре 5 месеци
родитељ
комит
5d8639f415
2 измењених фајлова са 62 додато и 50 уклоњено
  1. 56 50
      service/robot.class.php
  2. 6 0
      utils/utils.class.php

+ 56 - 50
service/robot.class.php

@@ -583,60 +583,66 @@ class robot{
          * ai 自由聊天
         */
         if($operate == "ai_chat"){
-            //前端生成一个唯一的serial_no
-            $serial_no = common::check_input($_POST["serial_no"]);
-            //系统提示词
-            $systemPrompt = common::check_input($_POST["prompt"]);
-            $question_type = common::check_input($_POST['question_type']);
-            $question_type = $question_type == 'Free Question' ? "Free Text" : $question_type;
-            $question_content = common::check_input($_POST['question_content']);
-
-            //固定问题的原始问题
-            $fixed_faq = common::check_input($_POST['fixed_faq']);
-            //claude  deepseek  根據賬號信息判断
-            $model = common::getUserCountry();
-            //$model = "deepseek"; 
+            try {
+                //前端生成一个唯一的serial_no
+                $serial_no = common::check_input($_POST["serial_no"]);
+                //系统提示词
+                $systemPrompt = common::check_input($_POST["prompt"]);
+                $question_type = common::check_input($_POST['question_type']);
+                $question_type = $question_type == 'Free Question' ? "Free Text" : $question_type;
+                $question_content = common::check_input($_POST['question_content']);
+
+                //固定问题的原始问题
+                $fixed_faq = common::check_input($_POST['fixed_faq']);
+                //claude  deepseek  根據賬號信息判断
+                $model = common::getUserCountry();
+                //$model = "deepseek"; 
+
+                //获取自然序列
+                $sequence = common::getChatAiSequence();
+                $name = $model == 'deepseek' ? "DS" : "CD";   
+                $request_id = "R".$name."".date("Ymd").$sequence; 
+                $question_id = "Q"."".date("Ymd").$sequence; 
+
+                //处理一下参数
+                $user_name = common::check_input(_getLoginName());
+                $user_type = _isApexLogin() ? "employee" : "customer";
+                
+                //首先生成基本记录数据 以便以后根据情况更新状态
+                $sql = "INSERT INTO public.kln_robot_chat_log(serial_no, question_id, user_name, user_type, question_type, question_content, 
+                        question_date, question_time, request_id, request_time,ai_model)
+                VALUES ('$serial_no','$question_id', '$user_name', '$user_type', '$question_type', '$question_content', 
+                        now(),to_char(CURRENT_TIME::time, 'HH24:MI:SS'), '$request_id',now(),'$model');";
+                $rs = common::excuteUpdateSql($sql);
+                if (!$rs) {
+                    $data = array("type"=>"markdown","data" => "AI Chat Save Error");
+                    common::echo_json_encode(200,$data);
+                    exit();
+                }
 
-            //获取自然序列
-            $sequence = common::getChatAiSequence();
-            $name = $model == 'deepseek' ? "DS" : "CD";   
-            $request_id = "R".$name."".date("Ymd").$sequence; 
-            $question_id = "Q"."".date("Ymd").$sequence; 
+                if ($question_type == 'Predefined Question'){
+                    $answer = $this->doFixedAnswerAndLog($serial_no,$fixed_faq,$question_content);
+
+                    //判断固定回答是否结束
+                    $is_fixedAnswer_end = false;
+                    $fixedChat = common::excuteObjectSql("select * from public.kln_robot_chat_fixed where fixed_faq = '$fixed_faq'");
+                    if (empty($fixedChat['secondary_interaction_content']) || $question_content != $fixedChat['fixed_faq'] ){
+                        $is_fixedAnswer_end = true;
+                    } 
+                } else {
+                    $answer = $this->doFreeAnswerAndLog($serial_no,$model,$systemPrompt, $question_content, $history = []);
+                    //自由问题固定为true
+                    $is_fixedAnswer_end = true;
+                }
 
-            //处理一下参数
-            $user_name = common::check_input(_getLoginName());
-            $user_type = _isApexLogin() ? "employee" : "customer";
-            
-            //首先生成基本记录数据 以便以后根据情况更新状态
-            $sql = "INSERT INTO public.kln_robot_chat_log(serial_no, question_id, user_name, user_type, question_type, question_content, 
-                    question_date, question_time, request_id, request_time,ai_model)
-            VALUES ('$serial_no','$question_id', '$user_name', '$user_type', '$question_type', '$question_content', 
-                    now(),to_char(CURRENT_TIME::time, 'HH24:MI:SS'), '$request_id',now(),'$model');";
-            $rs = common::excuteUpdateSql($sql);
-            if (!$rs) {
-                $data = array("type"=>"markdown","data" => "AI Chat Save Error");
-                common::echo_json_encode(200,$data);
+                $return = array("type"=>"markdown","is_fixedAnswer_end"=>$is_fixedAnswer_end,"data" =>$answer);
+                common::echo_json_encode(200,$return);            
+                exit();
+            } catch (Exception $e) {
+                $return = array("type"=>"markdown","is_fixedAnswer_end"=>true,"data" =>$e->getMessage());
+                common::echo_json_encode(200,$return);            
                 exit();
             }
-
-            if ($question_type == 'Predefined Question'){
-                $answer = $this->doFixedAnswerAndLog($serial_no,$fixed_faq,$question_content);
-
-                //判断固定回答是否结束
-                $is_fixedAnswer_end = false;
-                $fixedChat = common::excuteObjectSql("select * from public.kln_robot_chat_fixed where fixed_faq = '$fixed_faq'");
-                if (empty($fixedChat['secondary_interaction_content']) || $question_content != $fixedChat['fixed_faq'] ){
-                    $is_fixedAnswer_end = true;
-                } 
-            } else {
-                $answer = $this->doFreeAnswerAndLog($serial_no,$model,$systemPrompt, $question_content, $history = []);
-                //自由问题固定为true
-                $is_fixedAnswer_end = true;
-            }
-
-            $return = array("type"=>"markdown","is_fixedAnswer_end"=>$is_fixedAnswer_end,"data" =>$answer);
-            common::echo_json_encode(200,$return);            
-            exit();
         }
 
         if($operate == "ai_chat_stop"){

+ 6 - 0
utils/utils.class.php

@@ -358,6 +358,11 @@ class utils {
             || ($_REQUEST["action"] == "ocean_booking" && $_REQUEST["operate"] == "setting_display")){
             return;
         }
+        //排除robot的相关的记录
+        if((stripos($_REQUEST["action"], "robot") === 0)){
+            return;
+        }
+
         if($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "tracking_checked"){
             //public tracking_checked 的user name 记录对应IP 地址
             $user_type = "Customer";
@@ -442,6 +447,7 @@ class utils {
     }
 
     public static function analyzeOperationDetail($action,$operate){
+        $detail = "";
         if($action == "login" && $operate == "do_login"){
             $detail = 'System Account';
             if($_REQUEST['token']){