作者 lyh

gx指令

... ... @@ -2,6 +2,8 @@
use App\Models\File\Image;
use App\Models\File\File as FileModel;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectKeyword;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Utils\EncryptUtils;
... ... @@ -9,6 +11,7 @@ use App\Utils\LogUtils;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
... ... @@ -1081,5 +1084,50 @@ function getRandByRatio($proArr){
}
/**
* @remark :随机获取前后缀
* @name :getPrefixKeyword
* @author :lyh
* @method :post
* @time :2025/2/11 14:41
*/
function getPrefixKeyword($project_id, $type, $num)
{
$str = '';
$info = 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
*/
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;
}
... ...
... ... @@ -30,8 +30,8 @@ class AiCommandController extends BaseController
'key.required' => '场景不能为空',
]);
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);
$prefix = getPrefixKeyword($this->user['project_id'], 'prefix', 1);
$suffix = getPrefixKeyword($this->user['project_id'], 'suffix', 2);
$text = $prefix . ' ' . $this->param['keyword']. ' ' . $suffix;
$data = [
'code' => 200,
... ...
... ... @@ -289,51 +289,4 @@ 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;
}
}
... ...
... ... @@ -55,6 +55,24 @@ class AiCommandLogic extends BaseLogic
$prompt = '';
}
}
// 前缀关键词
if(preg_match_all("/\{qz_(\d+)\}/", $prompt, $matches)) {
foreach ($matches[0] as $key=>$val) {
$keyword = getPrefixKeyword($this->user['project_id'], 'prefix', $matches[1][$key]);
if($keyword){
$prompt = str_replace($val, $keyword, $prompt);
}
}
}
// 后缀关键词
if(preg_match_all("/\{hz_(\d+)\}/", $prompt, $matches)) {
foreach ($matches[0] as $key=>$val) {
$keyword = getPrefixKeyword($this->user['project_id'], 'suffix', $matches[1][$key]);
if($keyword){
$prompt = str_replace($val, $keyword, $prompt);
}
}
}
if(strpos($prompt, '{company detail}') !== false) {
$company_introduction = $this->getDeployOptimize('company_en_description');
$prompt = str_replace('{company detail}', $company_introduction, $prompt);
... ... @@ -67,14 +85,13 @@ class AiCommandLogic extends BaseLogic
$prompt .= '.Please answer in ' . $lang;
$ai_send = true;
}
return [
'prompt' => $prompt,
'scene' => $ai_command->scene,
'ai_send' => $ai_send,
];
}
/**
* @param $content
* @return string
... ...