作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !2047
... ... @@ -13,6 +13,7 @@ use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Project\ProjectKeyword;
use App\Services\AiCommandService;
use Illuminate\Support\Facades\Cache;
class AiCommandController extends BaseController
... ... @@ -79,9 +80,9 @@ class AiCommandController extends BaseController
*/
public function getLayoutDesignInfo(){
$aiCommonModel = new AiCommand();
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['key','ai']);
if($data === false){
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]);
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['key','ai']);
}
$this->response('success', Code::SUCCESS, $data);
}
... ... @@ -95,22 +96,48 @@ class AiCommandController extends BaseController
*/
public function saveLayoutDesign(){
$this->request->validate([
'key'=>['required']
'ai'=>['required'],
],[
'key.required' => '场景不能为空',
'ai.required' => '指令不能为空',
]);
$aiCommonModel = new AiCommand();
if($this->param['key'] != 'ai_layout_design'){
$this->response('success');
$this->response('非法key',Code::USER_ERROR);
}
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['id']);
if($data === false) {
$this->param['project_id'] = $this->user['project_id'];
$id = $aiCommonModel->addReturnId($this->param);
$param = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['name','key']);
$param['project_id'] = $this->user['project_id'];
$param['ai'] = $this->param['ai'];
$id = $aiCommonModel->addReturnId($param);
}else{
$id = $data['id'];
$aiCommonModel->edit($this->param,['id'=>$data['id']]);
$aiCommonModel->edit(['ai'=>$this->param['ai']],['id'=>$data['id']]);
}
$this->response('success', Code::SUCCESS, ['id'=>$id]);
}
/**
* @remark :根据指令获取内容
* @name :sendLayoutDesign
* @author :lyh
* @method :post
* @time :2025/5/26 17:39
*/
public function sendLayoutDesign(){
$this->request->validate([
'html'=>['required']
],[
'html.required' => 'html不能为空',
]);
$aiCommonModel = new AiCommand();
$info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['ai']);
if($info === false){
$info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['ai']);
}
$aiCommandService = new AiCommandService();
$ai = str_replace('{html}',$this->param['html'],$info['ai']);
$result = $aiCommandService->send_layout_design($ai);
$this->response('success', Code::SUCCESS, $result);
}
}
... ...
... ... @@ -22,6 +22,10 @@ class AiCommandService
public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
public $model = 'gemini-2.0-flash-lite';
public $supplier = 'google';
/**
* @remark :Ai一键排版
* @name :ai_click_layout
... ... @@ -29,29 +33,23 @@ class AiCommandService
* @method :post
* @time :2025/5/26 17:03
*/
public function ai_click_layout(){
public function send_layout_design($content){
$param = [
'messages'=>[
'content'=>'',
'role'=>'user',
['content'=>$content, 'role'=>'user'],
],
'model'=> 'gemini-2.0-flash-lite',
'supplier'=> 'google',
'model'=> $this->model,
'supplier'=> $this->supplier,
'security_check'=> false
];
$header = [
'accept'=>'application/json',
'X-CmerApi-Host'=>'llm-chat.p.cmer.com',
'apikey'=>$this->api_key,
'Content-Type'=>'application/json'
];
$header = array(
"Accept: application/json",
"X-CmerApi-Host: llm-chat.p.cmer.com",
"apikey: $this->api_key",
"Content-Type:application/json;charset=utf-8",
);
$result = http_post($this->url,$param,$header);
$result = http_post($this->url,json_encode($param,true),$header);
return $result;
}
}
... ...
... ... @@ -150,6 +150,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post');
Route::any('/getLayoutDesignInfo', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'getLayoutDesignInfo'])->name('ai_getLayoutDesignInfo');
Route::any('/saveLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'saveLayoutDesign'])->name('ai_saveLayoutDesign');
Route::any('/sendLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'sendLayoutDesign'])->name('ai_sendLayoutDesign');
});
//ai生成相关接口
... ...