feat: 增强 Gemini 流式响应兼容性,支持 JSON-array 格式解析

- 添加 Gemini JSON-array/chunks 格式的解析支持(兼容非 SSE 返回)
- 在上游请求中添加 alt=sse 参数,优先使用 SSE 格式
- 为 OpenAI 客户端统一补齐 [DONE] 流结束标记
- 更新 Gemini finishReason 判断逻辑,采用更宽松的结束判定
This commit is contained in:
fawney19
2026-01-23 23:34:38 +08:00
parent c3be83bf94
commit 76ed7e9fcb
5 changed files with 154 additions and 115 deletions

View File

@@ -91,6 +91,8 @@ async def test_create_response_stream_converts_claude_to_openai() -> None:
events = []
for line in text.splitlines():
if line.startswith("data: "):
if line == "data: [DONE]":
continue
events.append(json.loads(line[6:]))
assert len(events) >= 2
@@ -100,4 +102,3 @@ async def test_create_response_stream_converts_claude_to_openai() -> None:
for e in events
if isinstance(e, dict)
)