作者 lyh

gx ai指令生成

... ... @@ -12,6 +12,8 @@ use App\Models\Ai\AiCommand;
use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Project\ProjectKeyword;
use Illuminate\Support\Facades\Cache;
class AiCommandController extends BaseController
{
... ... @@ -27,12 +29,21 @@ class AiCommandController extends BaseController
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
]);
$text = AiCommandLogic::instance()->ai_send();
$data = [
'code' => $text ? 200 : 500,
'text' => $text
];
if($this->param['key'] == 'keyword_seo_title'){
$prefix = $this->getPrefixKeyword($this->user['project_id'], 'prefix', 1);
$suffix = $this->getPrefixKeyword($this->user['project_id'], 'suffix', 2);
$text = $prefix . ' ' . $this->project['keyword']. ' ' . $suffix;
$data = [
'code' => 200,
'text' => $text
];
}else{
$text = AiCommandLogic::instance()->ai_send();
$data = [
'code' => $text ? 200 : 500,
'text' => $text
];
}
$param = [
'key' => $this->param['key'],
'keywords' => $this->param['keywords'],
... ...
... ... @@ -7,6 +7,8 @@ use App\Exceptions\BsideGlobalException;
use App\Helper\Common;
use App\Http\Controllers\Controller;
use App\Http\Requests\Scene;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectKeyword;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;
use Illuminate\Http\JsonResponse;
... ... @@ -287,4 +289,51 @@ class BaseController extends Controller
return http_post($c_url, json_encode($param));
}
/**
* @remark :随机获取前后缀
* @name :getPrefixKeyword
* @author :lyh
* @method :post
* @time :2025/2/11 14:41
*/
public function getPrefixKeyword($project_id, $type, $num)
{
$str = '';
$info = $this->getDeployOptimize($project_id);
if (!empty($info['keyword_' . $type])) {
$fix_keyword = explode(",", $info['keyword_' . $type]);
//随机取
shuffle($fix_keyword);
if (count($fix_keyword) < $num)
return $str;
$keyword = array_slice($fix_keyword, 0, $num);
$str = implode(", ", $keyword);
}
return $str;
}
/**
* @remark :获取客户选择的关键词
* @name :getDeployOptimize
* @author :lyh
* @method :post
* @time :2025/2/11 14:58
*/
public function getDeployOptimize($project_id){
$cache_key = 'project_deploy_optimize_info_' . $project_id;
$info = Cache::get($cache_key);
if(!$info){
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix']);
$projectKeywordModel = new ProjectKeyword();
$keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
$info['main_keyword'] = '';
if(!empty($keywordInfo['main_keyword'])){
$info['main_keyword'] = $keywordInfo['main_keyword'];
}
Cache::put($cache_key, $info, 600);
}
return $info;
}
}
... ...
... ... @@ -31,7 +31,6 @@ class AiCommandLogic extends BaseLogic
$this->fail('指令不存在');
}
$prompt = $ai_command->ai;
if(strpos($prompt, '{keyword}') !== false) {
$prompt = str_replace('{keyword}', $this->param['keywords'], $prompt);
}
... ...