From 952fb2dc09ab6c5fe4fe87195c1c43e682ad97bc Mon Sep 17 00:00:00 2001 From: XianYuDaXian Date: Wed, 4 Mar 2026 00:40:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=E6=89=80=E6=9C=89=20?= =?UTF-8?q?API=20=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=9A=84=20post=5Fid=20?= =?UTF-8?q?=E5=9B=9E=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/chat.py | 3 --- app/api/v1/nsfw.py | 20 +++----------------- app/services/grok/services/video.py | 9 ++------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/app/api/v1/chat.py b/app/api/v1/chat.py index 2d90c6e..01ae373 100644 --- a/app/api/v1/chat.py +++ b/app/api/v1/chat.py @@ -954,9 +954,6 @@ async def chat_completions(request: ChatCompletionRequest, raw_request: Request) "completion_tokens": usage_completion, "total_tokens": usage_total, } - # [NEW] 包含 post_id (取第一个结果的) - if results and results[0].get("post_id"): - merged["post_id"] = results[0]["post_id"] result = merged diff --git a/app/api/v1/nsfw.py b/app/api/v1/nsfw.py index 84ae02b..630c611 100644 --- a/app/api/v1/nsfw.py +++ b/app/api/v1/nsfw.py @@ -558,12 +558,10 @@ async def _generate_nsfw_inner(data: NSFWRequest) -> Dict[str, Any]: "index": index, "image_url": image_url, "parent_post_id": parent_post_id, - "post_id": task_post_id, "error": "parent_post_video_not_ready", "url": "", "poster_url": "", "content": video_content, - "raw_response": raw_video_response, } return { "index": index, @@ -571,19 +569,16 @@ async def _generate_nsfw_inner(data: NSFWRequest) -> Dict[str, Any]: "content": video_content, "url": _clean_url(video_url), "poster_url": _clean_url(poster_url), - "raw_response": raw_video_response, "parent_post_id": parent_post_id, - "post_id": task_post_id, } except Exception as e: logger.warning(f"NSFW video failed: {task_tag}, error={e}") - # 从 processor 中尝试挽救 post_id + # 从 processor 中尝试挽救 post_id (内部记录用,不再返回) rescue_post_id = getattr(locals().get("processor"), "video_post_id", "") or task_post_id return { "index": index, "image_url": image_url, "parent_post_id": parent_post_id, - "post_id": rescue_post_id, "error": str(e), "url": "", "poster_url": "", @@ -615,17 +610,8 @@ async def _generate_nsfw_inner(data: NSFWRequest) -> Dict[str, Any]: clean_links.append(cu) lines = ["返回链接:"] - for idx, u in enumerate(images, 1): - lines.append(f"{idx}. (Image) {u}") - - for idx, item in enumerate(video_results, 1): - v_url = _clean_url(item.get("url", "")) - p_id = item.get("post_id", "") - if v_url: - msg = f"{idx}. (Video) {v_url}" - if p_id: - msg += f" (post_id: {p_id})" - lines.append(msg) + for idx, u in enumerate(clean_links, 1): + lines.append(f"{idx}. {u}") response_payload["result"] = "\n".join(lines) return response_payload diff --git a/app/services/grok/services/video.py b/app/services/grok/services/video.py index 029bb30..ec47d5d 100644 --- a/app/services/grok/services/video.py +++ b/app/services/grok/services/video.py @@ -994,7 +994,7 @@ class VideoStreamProcessor(BaseProcessor): logger.warning(f"Video upscale failed: {e}") return video_url - def _sse(self, content: str = "", role: str = None, finish: str = None, post_id: str = None) -> str: + def _sse(self, content: str = "", role: str = None, finish: str = None) -> str: """Build SSE response.""" delta = {} if role: @@ -1002,9 +1002,6 @@ class VideoStreamProcessor(BaseProcessor): delta["content"] = "" elif content: delta["content"] = content - - if post_id: - delta["post_id"] = post_id chunk = { "id": self.response_id or f"chatcmpl-{uuid.uuid4().hex[:24]}", @@ -1096,7 +1093,7 @@ class VideoStreamProcessor(BaseProcessor): rendered = await dl_service.render_video( video_url, self.token, thumbnail_url ) - yield self._sse(rendered, post_id=video_post_id) + yield self._sse(rendered) logger.info(f"Video generated: {video_url} (post_id={video_post_id})") continue @@ -1400,13 +1397,11 @@ class VideoCollectProcessor(BaseProcessor): "role": "assistant", "content": content, "refusal": None, - "post_id": post_id, }, "finish_reason": "stop", } ], "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}, - "post_id": post_id, }