diff --git a/src/api/utils.py b/src/api/utils.py index d20cc635..6dd41949 100644 --- a/src/api/utils.py +++ b/src/api/utils.py @@ -265,7 +265,8 @@ async def collect_streaming_response(stream_generator) -> Response: collected_text = [] # 用于收集文本内容 collected_thought_text = [] # 用于收集思维链内容 - collected_other_parts = [] # 用于收集其他类型的parts(图片、文件等) + collected_other_parts = [] # 用于收集其他类型的parts(图片、文件、工具调用等) + collected_tool_parts_count = 0 # 记录工具调用相关part数量 has_data = False line_count = 0 @@ -330,6 +331,14 @@ async def collect_streaming_response(stream_generator) -> Response: if not isinstance(part, dict): continue + # 优先保留工具调用相关 part(functionCall / functionResponse) + # 避免在 stream2nostream 模式下工具调用丢失 + if "functionCall" in part or "functionResponse" in part or "function_call" in part: + collected_other_parts.append(part) + collected_tool_parts_count += 1 + log.debug(f"[STREAM COLLECTOR] Collected tool part: {list(part.keys())}") + continue + # 处理文本内容 text = part.get("text", "") if text: @@ -411,7 +420,11 @@ async def collect_streaming_response(stream_generator) -> Response: merged_response["response"]["candidates"][0]["content"]["parts"] = final_parts - log.info(f"[STREAM COLLECTOR] Collected {len(collected_text)} text chunks, {len(collected_thought_text)} thought chunks, and {len(collected_other_parts)} other parts") + log.info( + f"[STREAM COLLECTOR] Collected {len(collected_text)} text chunks, " + f"{len(collected_thought_text)} thought chunks, {len(collected_other_parts)} other parts " + f"(tool parts: {collected_tool_parts_count})" + ) # 去掉嵌套的 "response" 包装(Antigravity格式 -> 标准Gemini格式) if "response" in merged_response and "candidates" not in merged_response: @@ -476,4 +489,4 @@ def parse_quota_reset_timestamp(error_response: dict) -> Optional[float]: return None except Exception: - return None \ No newline at end of file + return None diff --git a/version.txt b/version.txt index 32448c21..826a701d 100644 --- a/version.txt +++ b/version.txt @@ -1,4 +1,4 @@ -full_hash=d9ed76a6b30f90d729a1dd8713f4c383bfb94c61 -short_hash=d9ed76a -message=优化弹窗显示 -date=2026-02-06 19:25:13 +0800 +full_hash=2a83d62d86e06159e2bd80b6bbb3a7268e23822d +short_hash=2a83d62 +message=Merge branch 'master' into master +date=2026-02-06 23:01:11 +0800