|
...
|
...
|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
|
|
use App\Models\AiCommand as AiCommandModel;
|
|
|
|
use App\Models\User\UserLog as UserLogModel;
|
|
|
|
use App\Models\User\UserLogin as UserLoginModel;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
class Common
|
|
|
|
{
|
|
...
|
...
|
@@ -46,16 +47,17 @@ class Common |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function send_openai_msg($url){
|
|
|
|
public static function send_openai_msg($url){
|
|
|
|
$param = request()->post();
|
|
|
|
$url = HTTP_OPENAI_URL.$url;
|
|
|
|
$aiCommandModel = New AiCommandModel();
|
|
|
|
//指定库获取指令
|
|
|
|
$info = $aiCommandModel->read(['key'=>$this->param['key']]);
|
|
|
|
$info = $aiCommandModel->read(['key'=>$param['key']]);
|
|
|
|
if($info === false){
|
|
|
|
response('指令不存在',400);
|
|
|
|
}
|
|
|
|
//替换关键字
|
|
|
|
$content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
|
|
|
|
$content = str_replace('$keyword$', $param['keywords'], $info['ai']);
|
|
|
|
$data = [
|
|
|
|
'messages'=>[
|
|
|
|
['role'=>'system','content'=>$info['scene']],
|
|
...
|
...
|
@@ -64,4 +66,38 @@ class Common |
|
|
|
];
|
|
|
|
return http_post($url,json_encode($data));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :获取缓存
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public static function get_user_cache($table,$id,$type = 'B'){
|
|
|
|
$key = 'cache_'.$table.'_'.$id.'_type';
|
|
|
|
$lists = Cache::get($key);
|
|
|
|
return $lists;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :写入缓存
|
|
|
|
* @return bool
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public static function set_user_cache($data = [],$table,$id,$type = 'B'){
|
|
|
|
$key = 'cache_'.$table.'_'.$id.'_type';
|
|
|
|
return Cache::add($key,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :清楚缓存
|
|
|
|
* @return bool
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public static function del_user_cache($data = [],$rule,$project_id,$type = 'B'){
|
|
|
|
$key = 'cache_user_'.$rule.'_'.$project_id.'_'.$type;
|
|
|
|
return Cache::add($key,$data);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|