AiCommandController.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\:写入日志;
use App\Models\Ai\AiLog;
class AiCommandController extends BaseController
{
public $chat_url = 'v2/openai_chat';
/**
* @name :ai生成
* @return void
* @author :liyuhang
* @method
*/
public function ai_http_post(){
$this->request->validate([
'keywords'=>['required'],
'key'=>['required']
],[
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
]);
#TODO 通过key获取到ai指令对象
$data = Common::send_openai_msg($this->chat_url,$this->param);
$this->set_ai_log($data);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :写入日志
* @return void
* @author :liyuhang
* @method
*/
public function set_ai_log($data){
//写入日志
$param = [
'key'=> $this->param['key'],
'keywords'=>$this->param['key'],
'remark' =>$data
];
$aiLog = new AiLog();
return $aiLog->add($param);
}
}