From 7b704b5dbc0b0f07819fff4bbc329a8c3fbd03f7 Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Mon, 30 Mar 2026 11:19:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=5Fparse=5Fopenai=5Fsse=E9=98=B2?= =?UTF-8?q?=E5=BE=A1None=E5=80=BC=E8=BF=AD=E4=BB=A3(tool=5Fcalls/delta?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E4=B8=BAnull)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- llmcore.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/llmcore.py b/llmcore.py index e834405..738f146 100644 --- a/llmcore.py +++ b/llmcore.py @@ -200,10 +200,10 @@ def _parse_openai_sse(resp_lines, api_mode="chat_completions"): try: evt = json.loads(data_str) except: continue ch = (evt.get("choices") or [{}])[0] - delta = ch.get("delta", {}) + delta = ch.get("delta") or {} if delta.get("content"): text = delta["content"]; content_text += text; yield text - for tc in delta.get("tool_calls", []): + for tc in (delta.get("tool_calls") or []): idx = tc.get("index", 0) if idx not in tc_buf: tc_buf[idx] = {"id": tc.get("id", ""), "name": "", "args": ""} if tc.get("function", {}).get("name"): tc_buf[idx]["name"] = tc["function"]["name"] @@ -521,8 +521,7 @@ class NativeOAISession: _pat = next((p for p in ['[{"type":"tool_use"', '[{"type": "tool_use"'] if p in content), None) if _pat: try: - idx = content.index(_pat) - raw = json.loads(content[idx:]) + idx = content.index(_pat); raw = json.loads(content[idx:]) tool_calls = [MockToolCall(b["name"], b.get("input", {}), id=b.get("id", "")) for b in raw if b.get("type") == "tool_use"] content = content[:idx].strip() except: pass