作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

... ... @@ -70,4 +70,47 @@ class AiCommandController extends BaseController
return $aiLog->add($param);
}
/**
* @remark :获取排版指令
* @name :getAiTypesetting
* @author :lyh
* @method :post
* @time :2025/5/26 17:11
*/
public function getLayoutDesignInfo(){
$aiCommonModel = new AiCommand();
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
if($data === false){
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]);
}
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :保存指令
* @name :saveAiCommand
* @author :lyh
* @method :post
* @time :2025/5/26 17:15
*/
public function saveLayoutDesign(){
$this->request->validate([
'key'=>['required']
],[
'key.required' => '场景不能为空',
]);
$aiCommonModel = new AiCommand();
if($this->param['key'] != 'ai_layout_design'){
$this->response('success');
}
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
if($data === false) {
$this->param['project_id'] = $this->user['project_id'];
$id = $aiCommonModel->addReturnId($this->param);
}else{
$id = $data['id'];
$aiCommonModel->edit($this->param,['id'=>$data['id']]);
}
$this->response('success', Code::SUCCESS, ['id'=>$id]);
}
}
... ...
<?php
/**
* @remark :
* @name :AiCommandService.php
* @author :lyh
* @method :post
* @time :2025/5/26 17:01
*/
namespace App\Services;
/**
* @remark :AI指令返回数据
* @name :AiCommandService
* @author :lyh
* @method :post
* @time :2025/5/26 17:01
*/
class AiCommandService
{
public $url = 'https://api.cmer.com/v2/chat';
public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
/**
* @remark :Ai一键排版
* @name :ai_click_layout
* @author :lyh
* @method :post
* @time :2025/5/26 17:03
*/
public function ai_click_layout(){
$param = [
'messages'=>[
'content'=>'',
'role'=>'user',
],
'model'=> 'gemini-2.0-flash-lite',
'supplier'=> 'google',
'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);
return $result;
}
}
... ...
... ... @@ -148,6 +148,8 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('command')->group(function () {
//公用ai自动生成
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');
});
//ai生成相关接口
... ...