作者 lyh

gx

... ... @@ -59,18 +59,36 @@ class Common
if($info === false){
response('指令不存在',400);
}
$lang = self::detectLanguage($param['keywords']);
$str = ',请使用'.$lang.'回答';
//替换关键字
$content = str_replace('$keyword$', $param['keywords'], $info['ai']);
$data = [
'messages'=>[
['role'=>'system','content'=>$info['scene']],
['role'=>'assistant','content'=>$content],
['role'=>'assistant','content'=>$content.$str],
]
];
return http_post($url,json_encode($data));
}
/**
* @remark :识别用户输入语言
* @name :detectLanguage
* @author :lyh
* @method :post
* @time :2023/8/15 9:25
*/
public static function detectLanguage($param) {
if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $param)) {
return '中文';
} elseif (preg_match('/[a-zA-Z]/', $param)) {
return '英文';
} else {
return '英文';
}
}
/**
* @name :获取缓存
* @return void
* @author :liyuhang
... ...