瀏覽代碼

1.调整文生文通用非流式兼容流式输出,sse返回2.重新生成分镜片段接口新增审查模式

lh 3 周之前
父節點
當前提交
776f68f093
共有 1 個文件被更改,包括 20 次插入5 次删除
  1. 20 5
      app/Services/DeepSeek/DeepSeekService.php

+ 20 - 5
app/Services/DeepSeek/DeepSeekService.php

@@ -3219,11 +3219,10 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
         if (isset($post_data['reasoning_effort'])) {
             unset($post_data['reasoning_effort']);
         }
-        // 中转站不识别 response_format,可能被误转成 JSON 输出模式
-        if (isset($post_data['response_format'])) {
-            unset($post_data['response_format']);
-        }
+        // 流式场景下保留 response_format(json 输出时强制模型输出完整 JSON,与非流式 gpt54ChatOnly 对齐)
+        // 中转站对 response_format 的兼容性由请求方控制:仅在需要 json 输出时传入
         $post_data['max_completion_tokens'] = 100000;
+        $post_data['max_tokens'] = 100000;
         // 流式请求显式声明返回 usage(在最后一个 chunk 中返回)
         $post_data['stream_options'] = ['include_usage' => true];
 
@@ -3235,6 +3234,10 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
             $fullContent = '';
             $usage = [];
             $buffer = '';
+            // JSON 输出场景:不启用"整段正文包成 JSON 字符串"的暂缓缓存,流式过程中直接输出供前端展示
+            $isJsonRequest = isset($post_data['response_format'])
+                && is_array($post_data['response_format'])
+                && ($post_data['response_format']['type'] ?? '') === 'json_object';
             $suspectJsonWrap = false;
             $pendingContent = '';
             $requestStartedAt = microtime(true);
@@ -3309,7 +3312,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                                     $fullContent .= $delta['content'];
 
                                     $trimmed = ltrim($fullContent);
-                                    if (!$suspectJsonWrap && $trimmed !== '' && ($trimmed[0] === '{' || $trimmed[0] === '[')) {
+                                    if (!$suspectJsonWrap && !$isJsonRequest && $trimmed !== '' && ($trimmed[0] === '{' || $trimmed[0] === '[')) {
                                         // 可能模型把整段正文包成了 JSON 字符串,先暂缓输出
                                         $suspectJsonWrap = true;
                                     }
@@ -12183,6 +12186,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
         $template_id = getProp($data, 'template_id', 0);
         $act_id = getProp($data, 'act_id', 0);
         $episode_id = getProp($data, 'episode_id', 0);
+        $check_mode = (int)getProp($data, 'check_mode', 0); // 1=预览确认模式(仅 act_id 模式生效,不落库,返回 editAct 入参)
         
         // 验证:prompt和template_id至少提供一个
         if (empty($prompt) && empty($template_id)) {
@@ -12715,6 +12719,17 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                 // 单个片段模式:更新单条记录
                 if (count($parsed_segments) > 0) {
                     $new_segment = $parsed_segments[0];
+
+                    // 预览确认模式(check_mode=1):不落库,组装 editAct 入参返回,由前端确认后调用 editAct 更新
+                    if ($check_mode === 1) {
+                        return [
+                            'check_mode'   => 1,
+                            'act_id'       => (int)$act_id,
+                            'act_title'    => getProp($new_segment, 'act_title', ''),
+                            'act_duration' => getProp($new_segment, 'act_duration', 0),
+                            'act_content'  => getProp($new_segment, 'act_show_content', ''),
+                        ];
+                    }
                     
                     $update_data = [
                         'act_content' => getProp($new_segment, 'act_content', ''),