AiCommandController.php
2.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Helper\Translate;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\:写入日志;
use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
class AiCommandController extends BaseController
{
//获取文本内容
public $chat_url = 'v2/openai_chat_qqs';
/**
* @name :ai生成
* @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->companyName($this->param['key'],$this->user['project_id']));
$data['text'] = Common::deal_keywords($data['text']);
$data['text'] = Common::deal_str($data['text']);
$param = [
'key'=>$this->param['key'],
'keywords'=>$this->param['keywords'],
'remark'=>json_encode($data)
];
$this->set_ai_log($param);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取公司英文名称
* @name :companyName
* @author :lyh
* @method :post
* @time :2023/10/30 11:22
*/
public function companyName($key,$project_id){
$data = [
'news_remark',
'blog_remark',
'product_long_description'
];
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id'=>$project_id],['id','company_en_name','company_en_description']);
if(in_array($key,$data)){
return $info['company_en_description'];
}else{
return $info['company_en_name'];
}
}
/**
* @name :写入日志
* @author :liyuhang
* @method
*/
public function set_ai_log($data){
//写入日志
$param = [
'key'=> $this->param['key'],
'keywords'=>$this->param['keywords'],
'remark' =>$data['remark'],
'operator_id'=>$this->uid
];
$aiLog = new AiLog();
return $aiLog->add($param);
}
}