Browse Source

更新 'app/Http/Controllers/V1/Ai/AiController.php'

qiang 10 months ago
parent
commit
0e27fd8db9
1 changed files with 8 additions and 5 deletions
  1. 8 5
      app/Http/Controllers/V1/Ai/AiController.php

+ 8 - 5
app/Http/Controllers/V1/Ai/AiController.php

xqd xqd xqd xqd xqd
@@ -328,7 +328,7 @@ class AiController extends Controller
     {
         $keyword = Config::query()->where('key','prompt_style')->value('value');
         $prompt     = $prompt . $keyword;
-        $promptTo   = '我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会将翻译的结果用于stable diffusion、midjourney等绘画场景生成图片,语言要求尽量优美。我会用任何语言和你交流,你会识别语言,将其翻译为英语并仅回答翻译的最终结果,不要写解释。我的第一句话是:' . $prompt . '。请立刻翻译,不要回复其它内容。';
+        $promptTo   = '我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会将翻译的结果用于stable diffusion绘画场景生成图片,语言要求尽量优美。我会用任何语言和你交流,你会识别语言,将其翻译为英语并仅回答翻译的最终结果,不要写解释。我的第一句话是:' . $prompt . '。请立刻翻译,不要回复其它内容。';
         $messages[] = ['role' => 'user', 'content' => $promptTo];
         $data       = [
             'messages' => $messages,
@@ -407,6 +407,7 @@ class AiController extends Controller
             $task->state = 3;
             $task->desc = $res['data']['fail_reason'];
         }
+        Log::warning('这个是SD进度信息:'.json_encode($res,256));
         $task->save();
         if ('success' == $res['data']['state']) {
             $path           = $this->saveImage($res['data']['gen_img']);
@@ -439,7 +440,7 @@ class AiController extends Controller
             if (!is_dir($imageDir)) {
                 mkdir($imageDir, 0755, true);
             }
-            $shell = 'wkhtmltoimage --quality 50 https://hb.swdz.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
+            $shell = 'wkhtmltoimage --quality 50 ' . request()->getHost() . '/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
             exec($shell, $result, $status);
             if ($status) {
                 $this->exit_out('生成图片失败', ['生成图片失败' => [$shell, $result, $status]]);
@@ -485,7 +486,7 @@ class AiController extends Controller
             if (!is_dir($imageDir)) {
                 mkdir($imageDir, 0755, true);
             }
-            $shell = "wkhtmltopdf 'https://hb.swdz.com/api/ai/Pinyin?type=1&id=" . $task->id . "' ". "'".$path."'";
+            $shell = "wkhtmltopdf ' . request()->getHost() . '/api/ai/Pinyin?type=1&id=" . $task->id . "' ". "'".$path."'";
             exec($shell, $result, $status);
             if ($status) {
                 $this->exit_out('生成PDF失败', ['生成PDF失败' => [$shell, $result, $status]]);
@@ -591,16 +592,18 @@ class AiController extends Controller
     private function saveImage($image_url)
     {
         $imageContent = file_get_contents($image_url);
-        $imageDir     = $_SERVER['DOCUMENT_ROOT'] . '/file/sd/' . date('Ymd') . '/';
+        $imageDir     = public_path(). '/file/sd/' . date('Ymd') . '/';
         $imageName    = uniqid() . time() . '_image.png';
         $imagePath    = $imageDir . $imageName;
+       Log::warning('saveImage imageDir:'.$imageDir);
         if (!is_dir($imageDir)) {
+       Log::warning('saveImage imageDir mkdir:'.$imageDir);
             mkdir($imageDir, 0777, true);
         }
         if (false !== $imageContent) {
             $savedImages = file_put_contents($imagePath, $imageContent);
             if (false !== $savedImages) {
-                return request()->getHost(). '/file/sd/' . date('Ymd') . '/' . $imageName;
+                return request()->getHost() . '/file/sd/' . date('Ymd') . '/' . $imageName;
             }
             return false;
         }