Просмотр исходного кода

优化继续策划下一集的提示词

lh 2 месяцев назад
Родитель
Сommit
4c048f9b76
1 измененных файлов с 132 добавлено и 2 удалено
  1. 132 2
      app/Services/DeepSeek/DeepSeekService.php

+ 132 - 2
app/Services/DeepSeek/DeepSeekService.php

@@ -4271,11 +4271,11 @@ class DeepSeekService
             if (!$content) {
                 Utils::throwError('20003:章节内容无法获取,请确认');
             }
-            $question = $demo."请根据以上要求分析本章剧情,完成分镜剧本(需衔接上一章内容),本章剧情内容如下: \n\n$content";
+            $question = $demo."请根据以上要求分析本章剧情,完成本章分镜剧本(需衔接上一章内容)";
 
             // 获取上一集最后记录
             $prev_sequence = $episode_number - 1;
-            $messages = $this->getEpisodeChatMessages($anime_id, $prev_sequence);
+            $messages = $this->getEpisodeChatContent($anime_id, $prev_sequence);
             // 构建消息
             $messages[] = 
                 [
@@ -4824,6 +4824,136 @@ class DeepSeekService
         return trim($content);
     }
 
+    private function getEpisodeChatContent($animeId, $sequence) {
+        if ((int)$sequence <= 0) {
+            return [];
+        }
+
+        $origin_content = DB::table('mp_animes')->where('id', $animeId)->value('content');
+        if ($origin_content) $origin_content = '原文内容:'.$origin_content;
+
+        // 获取分集信息
+        $episode = DB::table('mp_anime_episodes')
+            ->where('anime_id', $animeId)
+            ->where('sequence', $sequence)
+            ->where('is_default', 1)
+            ->first();
+        
+        if (!$episode) {
+            return [];
+        }
+        
+        $episode_id = getProp($episode, 'id');
+        $episode_number = getProp($episode, 'episode_number');
+        $title = getProp($episode, 'title');
+        $intro = getProp($episode, 'intro');
+        $art_style = getProp($episode, 'art_style');
+        $roles = json_decode(getProp($episode, 'roles'), true) ?: [];
+        $scenes = json_decode(getProp($episode, 'scenes'), true) ?: [];
+        
+        // 组装纯文本内容
+        $content = '';
+        
+        // 添加分集标题和梗概
+        $content .= "###第{$episode_number}集:{$title}\n\n";
+        $content .= "###故事梗概\n";
+        $content .= trim($intro) . "\n\n";
+        
+        // 添加美术风格
+        $content .= "###美术风格\n";
+        $content .= trim($art_style) . "\n\n";
+        
+        // 添加主体列表
+        $content .= "###主体列表\n";
+        foreach ($roles as $role) {
+            $name = getProp($role, 'name');
+            $description = getProp($role, 'description');
+            $content .= "{$name}: {$description}\n";
+        }
+        $content .= "\n";
+        
+        // 添加场景列表
+        $content .= "###场景列表\n";
+        foreach ($scenes as $scene) {
+            $name = getProp($scene, 'name');
+            $description = getProp($scene, 'description');
+            $content .= "{$name}: {$description}\n";
+        }
+        $content .= "\n";
+        
+        // 获取分镜信息
+        $segments = DB::table('mp_episode_segments')
+            ->where('anime_id', $animeId)
+            ->where('episode_id', $episode_id)
+            ->orderBy('segment_number')
+            ->get();
+        
+        if ($segments && count($segments) > 0) {
+            $content .= "###分镜剧本\n";
+            
+            // 按幕分组
+            $currentAct = null;
+            foreach ($segments as $segment) {
+                $act_number = getProp($segment, 'act_number');
+                $segment_number = getProp($segment, 'segment_number');
+                $segment_content = getProp($segment, 'segment_content');
+                $scene_description = getProp($segment, 'scene_description');
+                $scene_name = getProp($segment, 'scene_name');
+                $composition = getProp($segment, 'composition');
+                $camera_movement = getProp($segment, 'camera_movement');
+                $voice_type = getProp($segment, 'voice_type');
+                $characters = getProp($segment, 'characters');
+                $dialogue = getProp($segment, 'dialogue');
+                $frame_type = getProp($segment, 'frame_type');
+                $tail_frame_description = getProp($segment, 'tail_frame_description');
+                
+                // 如果是新的幕,添加幕标题
+                if ($act_number !== $currentAct) {
+                    $currentAct = $act_number;
+                    $content .= "##第{$act_number}幕:{$scene_name}\n";
+                }
+                
+                // 添加分镜信息
+                $content .= "分镜{$segment_number}\n";
+                $content .= "分镜内容:{$segment_content}\n";
+                // $content .= "画面描述:{$scene_description}\n";
+                // $content .= "场景:{$scene_name}\n";
+                // $content .= "构图设计:{$composition}\n";
+                // $content .= "运镜调度:{$camera_movement}\n";
+                
+                // if (!empty($voice_type)) {
+                //     $content .= "配音角色:{$voice_type}\n";
+                // }
+                
+                // if (!empty($characters)) {
+                //     $content .= "出镜角色:{$characters}\n";
+                // }
+                
+                // if (!empty($dialogue)) {
+                //     $content .= "台词内容:\"{$dialogue}\"\n";
+                // }
+                
+                // $content .= "画面类型:{$frame_type}\n";
+                // $content .= "尾帧描述:{$tail_frame_description}\n";
+                $content .= "\n";
+            }
+        }
+
+        $content = trim($content);
+        if($content) $content = "上集剧本内容:\n{$content}";
+        
+        return [
+            [
+                'role'      => 'user',
+                'content'   => $origin_content
+            ],
+            [
+                'role'      => 'assistant',
+                'content'   => $content
+            ]
+        ];
+    }
+
     private function getEpisodeChatMessages($animeId, $sequence): array
     {
         if ((int)$sequence <= 0) {