Explorar o código

更新拼音显示

王大坤 hai 1 ano
pai
achega
7cd4a1acc4

+ 62 - 0
.idea/workspace.xml

xqd
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="AutoImportSettings">
+    <option name="autoReloadType" value="SELECTIVE" />
+  </component>
+  <component name="ChangeListManager">
+    <list default="true" id="8414349a-a5c1-4581-af28-3957a3c3ac31" name="Changes" comment="" />
+    <option name="SHOW_DIALOG" value="false" />
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+    <option name="LAST_RESOLUTION" value="IGNORE" />
+  </component>
+  <component name="ComposerSettings" synchronizationState="SYNCHRONIZE">
+    <pharConfigPath>$PROJECT_DIR$/server/composer.json</pharConfigPath>
+    <execution />
+  </component>
+  <component name="Git.Settings">
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
+  </component>
+  <component name="MarkdownSettingsMigration">
+    <option name="stateVersion" value="1" />
+  </component>
+  <component name="PhpWorkspaceProjectConfiguration" interpreter_name="/opt/homebrew/Cellar/php/8.2.8/bin/php" />
+  <component name="ProjectColorInfo">{
+  &quot;associatedIndex&quot;: 3
+}</component>
+  <component name="ProjectId" id="2eLshOYN7sx6QPbyOH6W4WBXz7d" />
+  <component name="ProjectViewState">
+    <option name="hideEmptyMiddlePackages" value="true" />
+    <option name="showLibraryContents" value="true" />
+  </component>
+  <component name="PropertiesComponent"><![CDATA[{
+  "keyToString": {
+    "RunOnceActivity.OpenProjectViewOnStart": "true",
+    "RunOnceActivity.ShowReadmeOnStart": "true",
+    "WebServerToolWindowFactoryState": "false",
+    "git-widget-placeholder": "main",
+    "node.js.detected.package.eslint": "true",
+    "node.js.detected.package.tslint": "true",
+    "node.js.selected.package.eslint": "(autodetect)",
+    "node.js.selected.package.tslint": "(autodetect)",
+    "nodejs_package_manager_path": "npm",
+    "vue.rearranger.settings.migration": "true"
+  }
+}]]></component>
+  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
+  <component name="TaskManager">
+    <task active="true" id="Default" summary="Default task">
+      <changelist id="8414349a-a5c1-4581-af28-3957a3c3ac31" name="Changes" comment="" />
+      <created>1711695310942</created>
+      <option name="number" value="Default" />
+      <option name="presentableId" value="Default" />
+      <updated>1711695310942</updated>
+      <workItem from="1711695312175" duration="1119000" />
+      <workItem from="1712109768440" duration="1126000" />
+    </task>
+    <servers />
+  </component>
+  <component name="TypeScriptGeneratedFilesManager">
+    <option name="version" value="3" />
+  </component>
+</project>

+ 55 - 42
server/app/Http/Controllers/V1/Ai/AiController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -48,6 +48,7 @@ class AiController extends Controller
                     'age'     => $request->post('age', ''),
                     'star'    => $request->post('star', ''),
                     'level'   => $request->post('level', ''),
+//                    'is_piny'   => $request->post('is_piny', 1),
                 ]);
                 if (!$role) {
                     return Response::fail('提交失败,请稍后再试!');
@@ -61,6 +62,7 @@ class AiController extends Controller
                 'surplus_diamond' => Auth::$user->diamond - $plot,
                 'nickname'        => 'AI绘本生成',
                 'plot'            => $plot,
+                'is_piny'   => $request->post('pinYin', 1),
             ]);
             if (!$task) {
                 return Response::fail('任务提交失败');
@@ -93,20 +95,22 @@ class AiController extends Controller
     }
 
     /**
-     * 获取字数
+     * 获取字数.
      *
-     * @param $level
      * @return int|mixed
      */
-    private function getBuildCountString($level = 1){
-        $string = Config::query()->where('key','class_count')->first()->toArray();
-        foreach ($string['value'] ?? [] as $value){
-            if ($level == $value['lv']){
+    private function getBuildCountString($level = 1)
+    {
+        $string = Config::query()->where('key', 'class_count')->first()->toArray();
+        foreach ($string['value'] ?? [] as $value) {
+            if ($level == $value['lv']) {
                 return $value['count'];
             }
         }
+
         return 200;
     }
+
     /**
      * 生成故事.
      */
@@ -117,16 +121,16 @@ class AiController extends Controller
             if (!$task) {
                 return Response::fail('暂无任务');
             }
-            $key     = [];
-//            $keyword = Keyword::query()->pluck('keyword');
-//            foreach ($keyword as $value) {
-//                $key[] = $value;
-//            }
-//            $keyword     = implode(',', $key);
-            $keyword = Config::query()->where('key','prompt_gushi')->value('value');
+            $key = [];
+            //            $keyword = Keyword::query()->pluck('keyword');
+            //            foreach ($keyword as $value) {
+            //                $key[] = $value;
+            //            }
+            //            $keyword     = implode(',', $key);
+            $keyword     = Config::query()->where('key', 'prompt_gushi')->value('value');
             $task->state = 1;
             $task->save();
-            Log::warning('这个是当前的次数:'.$this->getBuildCountString($task->level));
+            Log::warning('这个是当前的次数:' . $this->getBuildCountString($task->level));
             $prompt     = "一个{$task->role->sex},叫{$task->role->name},{$task->role->age}岁。{$keyword},要求不低于{$this->getBuildCountString($task->role->level)}字。备注:不要加什么特殊符号只需要正常的逗号句号叹号这些。";
             $messages[] = ['role' => 'user', 'content' => $prompt];
             $data       = [
@@ -164,8 +168,8 @@ class AiController extends Controller
             $data       = [
                 'messages' => $messages,
             ];
-            $postData    = json_encode($data);
-            $complete    = $this->host($postData);
+            $postData = json_encode($data);
+            $complete = $this->host($postData);
             // $task->state = 2;
             $task->title = $complete['result'];
             $task->save();
@@ -190,16 +194,16 @@ class AiController extends Controller
             if (!$task) {
                 return Response::fail('暂无任务');
             }
-            $keyword = Config::query()->where('key','prompt_keyword')->value('value');
+            $keyword    = Config::query()->where('key', 'prompt_keyword')->value('value');
             $prompt     = $task->init_content . $keyword;
             $messages[] = ['role' => 'user', 'content' => $prompt];
             $data       = [
                 'messages' => $messages,
             ];
-            $task->state   = 3;
+            $task->state = 3;
             $task->save();
-            $postData      = json_encode($data);
-            $complete      = $this->host($postData);
+            $postData = json_encode($data);
+            $complete = $this->host($postData);
             // $task->state   = 3;
             $task->keyword = $complete['result'];
             $task->save();
@@ -217,7 +221,7 @@ class AiController extends Controller
      */
     private function toEnglish($prompt)
     {
-        $keyword = Config::query()->where('key','prompt_style')->value('value');
+        $keyword    = Config::query()->where('key', 'prompt_style')->value('value');
         $prompt     = $prompt . $keyword;
         $promptTo   = '我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会将翻译的结果用于如stable diffusion、midjourney等绘画场景生成图片,语言要求尽量优美。我会用任何语言和你交流,你会识别语言,将其翻译为英语并仅回答翻译的最终结果,不要写解释。我的第一句话是:' . $prompt . '。请立刻翻译,不要回复其它内容。';
         $messages[] = ['role' => 'user', 'content' => $promptTo];
@@ -259,15 +263,15 @@ class AiController extends Controller
                 'keywords'            => $keyword,
             ];
 
-            $result      = (new Helper())->opensd($param);
-            $result      = json_decode($result, true);
-            Log::warning('这个是SD回调信息:'.json_encode($result,256));
-            if(isset($result['data']['id'])){
+            $result = (new Helper())->opensd($param);
+            $result = json_decode($result, true);
+            Log::warning('这个是SD回调信息:' . json_encode($result, 256));
+            if (isset($result['data']['id'])) {
                 $task->sd_id = $result['data']['id'];
-            }else{
-               $task->state = 3; 
+            } else {
+                $task->state = 3;
             }
-            
+
             $task->save();
 
             return Response::success($result['data']);
@@ -296,7 +300,7 @@ class AiController extends Controller
         }
         if ('fail' == $res['data']['state']) {
             $task->state = 3;
-            $task->desc = $res['data']['fail_reason'];
+            $task->desc  = $res['data']['fail_reason'];
         }
         $task->save();
         if ('success' == $res['data']['state']) {
@@ -325,7 +329,7 @@ class AiController extends Controller
                 $file_name = md5(time()) . '.png';
             }
             $path  = public_path() . '/images/' . $file_name;
-            $shell = 'wkhtmltoimage https://t18.9026.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
+            $shell = 'wkhtmltoimage https://hb.swdz.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
             exec($shell, $result, $status);
             if ($status) {
                 $this->exit_out('生成图片失败', ['生成图片失败' => [$shell, $result, $status]]);
@@ -366,7 +370,7 @@ class AiController extends Controller
                 $file_name = md5(time()) . '.pdf';
             }
             $path  = public_path() . '/pdf/' . $file_name;
-            $shell = 'wkhtmltopdf https://t18.9026.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
+            $shell = 'wkhtmltopdf https://hb.swdz.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
             exec($shell, $result, $status);
             if ($status) {
                 $this->exit_out('生成PDF失败', ['生成PDF失败' => [$shell, $result, $status]]);
@@ -409,7 +413,7 @@ class AiController extends Controller
             $task   = TaskList::query()->find($id);
             $result = $this->extracted($task);
 
-            return view('pdf', ['data' => $result, 'img' => $task->image,'title' => $task->title]);
+            return view('pdf', ['data' => $result, 'img' => $task->image, 'title' => $task->title]);
         } catch (\Exception $exception) {
             LogHelper::exceptionLog($exception, $this->code);
 
@@ -504,17 +508,18 @@ class AiController extends Controller
         ]);
         $res = curl_exec($ch);
         curl_close($ch);
-
+        Log::warning('请求头:' .$postData);
+        Log::warning('请求返回值:' .$res);
         return json_decode(trim($res), true);
     }
 
-   public function extracted($result,$type = 0,$sdImage = ''): string
+    public function extracted($result, $type = 0, $sdImage = ''): string
     {
-      if ($type == 0){
-            $inputString    = $result->init_content;
-            $sdImage = $result->sd_image;
-        }else{
-            $inputString    = $result;
+        if (0 == $type) {
+            $inputString = $result->init_content;
+            $sdImage     = $result->sd_image;
+        } else {
+            $inputString = $result;
         }
         $inputString    = str_replace('“', '', $inputString);
         $inputString    = str_replace('”', '', $inputString);
@@ -547,16 +552,24 @@ class AiController extends Controller
                 $string = $string . $img;
             }
             if (in_array($key + 1, $arr)) {
-                $string = $string . "<span><sup>{$value}</sup>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
+                if ($result->is_piny){
+                    $string = $string . "<span><sup>{$value}</sup>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
+                }else{
+                    $string = $string . "<span>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
+                }
+
             } else {
                 $style = '';
                 // if (in_array($key, $arr) || 0 == $key) {
                 //     $style = 'style="margin-left: 5rem"';
                 // }
-                $string = $string . '<span ' . $style . "><sup>{$value}</sup>{$splitCharacters[$key]}</span>";
+                if ($result->is_piny){
+                    $string = $string . '<span ' . $style . "><sup>{$value}</sup>{$splitCharacters[$key]}</span>";
+                }else{
+                    $string = $string . '<span ' . $style . ">{$splitCharacters[$key]}</span>";
+                }
             }
         }
-
         return $string;
     }
 }

+ 1 - 1
server/app/Models/TaskList.php

xqd
@@ -8,7 +8,7 @@ class TaskList extends Model
 {
     protected $table    = 'task_list';
     protected $fillable = ['user_id', 'title', 'role_id', 'content', 'created_at', 'updated_at', 'state', 'image', 'init_content', 'keyword', 'sd_image',
-        'desc', 'sd_id', 'surplus_diamond', 'nickname', 'plot', 'is_handpick', 'sort', 'pinyin_content', 'pdf_path', 'image_path'];
+        'desc', 'sd_id', 'surplus_diamond', 'nickname', 'plot', 'is_handpick', 'sort', 'pinyin_content', 'pdf_path', 'image_path','is_piny'];
     public static $state = [
         0 => '已提交',
         1 => '生成中',