作者 lyh

gx

@@ -59,18 +59,36 @@ class Common @@ -59,18 +59,36 @@ class Common
59 if($info === false){ 59 if($info === false){
60 response('指令不存在',400); 60 response('指令不存在',400);
61 } 61 }
  62 + $lang = self::detectLanguage($param['keywords']);
  63 + $str = ',请使用'.$lang.'回答';
62 //替换关键字 64 //替换关键字
63 $content = str_replace('$keyword$', $param['keywords'], $info['ai']); 65 $content = str_replace('$keyword$', $param['keywords'], $info['ai']);
64 $data = [ 66 $data = [
65 'messages'=>[ 67 'messages'=>[
66 ['role'=>'system','content'=>$info['scene']], 68 ['role'=>'system','content'=>$info['scene']],
67 - ['role'=>'assistant','content'=>$content], 69 + ['role'=>'assistant','content'=>$content.$str],
68 ] 70 ]
69 ]; 71 ];
70 return http_post($url,json_encode($data)); 72 return http_post($url,json_encode($data));
71 } 73 }
72 74
73 /** 75 /**
  76 + * @remark :识别用户输入语言
  77 + * @name :detectLanguage
  78 + * @author :lyh
  79 + * @method :post
  80 + * @time :2023/8/15 9:25
  81 + */
  82 + public static function detectLanguage($param) {
  83 + if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $param)) {
  84 + return '中文';
  85 + } elseif (preg_match('/[a-zA-Z]/', $param)) {
  86 + return '英文';
  87 + } else {
  88 + return '英文';
  89 + }
  90 + }
  91 + /**
74 * @name :获取缓存 92 * @name :获取缓存
75 * @return void 93 * @return void
76 * @author :liyuhang 94 * @author :liyuhang