Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -476,4 +489,4 @@ def parse_quota_reset_timestamp(error_response: dict) -> Optional[float]:
return None

except Exception:
return None
return None
8 changes: 4 additions & 4 deletions version.txt
Original file line number Diff line number Diff line change
@@ -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