作者 lyh

gx脚本

@@ -13,6 +13,7 @@ use App\Models\Ai\AiLog; @@ -13,6 +13,7 @@ use App\Models\Ai\AiLog;
13 use App\Models\Project\DeployOptimize; 13 use App\Models\Project\DeployOptimize;
14 use App\Models\Project\Project; 14 use App\Models\Project\Project;
15 use App\Models\Project\ProjectKeyword; 15 use App\Models\Project\ProjectKeyword;
  16 +use App\Services\AiCommandService;
16 use Illuminate\Support\Facades\Cache; 17 use Illuminate\Support\Facades\Cache;
17 18
18 class AiCommandController extends BaseController 19 class AiCommandController extends BaseController
@@ -113,4 +114,27 @@ class AiCommandController extends BaseController @@ -113,4 +114,27 @@ class AiCommandController extends BaseController
113 } 114 }
114 $this->response('success', Code::SUCCESS, ['id'=>$id]); 115 $this->response('success', Code::SUCCESS, ['id'=>$id]);
115 } 116 }
  117 +
  118 + /**
  119 + * @remark :根据指令获取内容
  120 + * @name :sendLayoutDesign
  121 + * @author :lyh
  122 + * @method :post
  123 + * @time :2025/5/26 17:39
  124 + */
  125 + public function sendLayoutDesign(){
  126 + $this->request->validate([
  127 + 'key'=>['required']
  128 + ],[
  129 + 'key.required' => '场景不能为空',
  130 + ]);
  131 + $aiCommonModel = new AiCommand();
  132 + $info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
  133 + if($info === false){
  134 + $info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]);
  135 + }
  136 + $aiCommandService = new AiCommandService();
  137 + $result = $aiCommandService->send_layout_design($info['ai']);
  138 + $this->response('success', Code::SUCCESS, $result);
  139 + }
116 } 140 }
@@ -22,6 +22,10 @@ class AiCommandService @@ -22,6 +22,10 @@ class AiCommandService
22 22
23 public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg'; 23 public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
24 24
  25 + public $model = 'gemini-2.0-flash-lite';
  26 +
  27 + public $supplier = 'google';
  28 +
25 /** 29 /**
26 * @remark :Ai一键排版 30 * @remark :Ai一键排版
27 * @name :ai_click_layout 31 * @name :ai_click_layout
@@ -29,29 +33,23 @@ class AiCommandService @@ -29,29 +33,23 @@ class AiCommandService
29 * @method :post 33 * @method :post
30 * @time :2025/5/26 17:03 34 * @time :2025/5/26 17:03
31 */ 35 */
32 - public function ai_click_layout(){ 36 + public function send_layout_design($content){
33 $param = [ 37 $param = [
34 'messages'=>[ 38 'messages'=>[
35 - 'content'=>'', 39 + 'content'=>$content,
36 'role'=>'user', 40 'role'=>'user',
37 ], 41 ],
38 - 'model'=> 'gemini-2.0-flash-lite',  
39 - 'supplier'=> 'google', 42 + 'model'=> $this->model,
  43 + 'supplier'=> $this->supplier,
40 'security_check'=> false 44 'security_check'=> false
41 ]; 45 ];
42 - $header = [  
43 - 'accept'=>'application/json',  
44 - 'X-CmerApi-Host'=>'llm-chat.p.cmer.com',  
45 - 'apikey'=>$this->api_key,  
46 - 'Content-Type'=>'application/json'  
47 - ];  
48 $header = array( 46 $header = array(
49 "Accept: application/json", 47 "Accept: application/json",
50 "X-CmerApi-Host: llm-chat.p.cmer.com", 48 "X-CmerApi-Host: llm-chat.p.cmer.com",
51 "apikey: $this->api_key", 49 "apikey: $this->api_key",
52 "Content-Type:application/json;charset=utf-8", 50 "Content-Type:application/json;charset=utf-8",
53 ); 51 );
54 - $result = http_post($this->url,$param,$header); 52 + $result = http_post($this->url,json_encode($param,true),$header);
55 return $result; 53 return $result;
56 } 54 }
57 } 55 }