fix: SSE tool_call streaming compat for non-standard index/id, MockToolCall handle list args & None fallback; sop: CDP bringToFront note
This commit is contained in:
10
llmcore.py
10
llmcore.py
@@ -243,9 +243,13 @@ def _parse_openai_sse(resp_lines, api_mode="chat_completions"):
|
|||||||
text = delta["content"]; content_text += text; yield text
|
text = delta["content"]; content_text += text; yield text
|
||||||
for tc in (delta.get("tool_calls") or []):
|
for tc in (delta.get("tool_calls") or []):
|
||||||
idx = tc.get("index", 0)
|
idx = tc.get("index", 0)
|
||||||
if idx not in tc_buf: tc_buf[idx] = {"id": tc.get("id") or '', "name": "", "args": ""}
|
has_name = bool(tc.get("function", {}).get("name"))
|
||||||
if tc.get("function", {}).get("name"): tc_buf[idx]["name"] = tc["function"]["name"]
|
if idx not in tc_buf:
|
||||||
|
if has_name or not tc_buf: tc_buf[idx] = {"id": tc.get("id") or '', "name": "", "args": ""}
|
||||||
|
else: idx = max(tc_buf)
|
||||||
|
if has_name: tc_buf[idx]["name"] = tc["function"]["name"]
|
||||||
if tc.get("function", {}).get("arguments"): tc_buf[idx]["args"] += tc["function"]["arguments"]
|
if tc.get("function", {}).get("arguments"): tc_buf[idx]["args"] += tc["function"]["arguments"]
|
||||||
|
if tc.get("id") and not tc_buf[idx]["id"]: tc_buf[idx]["id"] = tc["id"]
|
||||||
usage = evt.get("usage")
|
usage = evt.get("usage")
|
||||||
if usage: _record_usage(usage, api_mode)
|
if usage: _record_usage(usage, api_mode)
|
||||||
blocks = []
|
blocks = []
|
||||||
@@ -672,7 +676,7 @@ class MockFunction:
|
|||||||
|
|
||||||
class MockToolCall:
|
class MockToolCall:
|
||||||
def __init__(self, name, args, id=''):
|
def __init__(self, name, args, id=''):
|
||||||
arg_str = json.dumps(args, ensure_ascii=False) if isinstance(args, dict) else args
|
arg_str = json.dumps(args, ensure_ascii=False) if isinstance(args, (dict, list)) else (args or '{}')
|
||||||
self.function = MockFunction(name, arg_str); self.id = id
|
self.function = MockFunction(name, arg_str); self.id = id
|
||||||
|
|
||||||
class MockResponse:
|
class MockResponse:
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ fetch('PDF_URL').then(r=>r.blob()).then(b=>{
|
|||||||
|
|
||||||
## Chrome后台标签节流
|
## Chrome后台标签节流
|
||||||
- 后台标签中`setTimeout`被Chrome intensive throttling延迟到≥1min/次,扩展脚本中避免依赖setTimeout轮询
|
- 后台标签中`setTimeout`被Chrome intensive throttling延迟到≥1min/次,扩展脚本中避免依赖setTimeout轮询
|
||||||
|
- 某些SPA页面需CDP `Page.bringToFront`切到前台才会加载数据
|
||||||
|
|
||||||
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
|
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
|
||||||
扩展路径:`assets/tmwd_cdp_bridge/`(需安装,含debugger权限)
|
扩展路径:`assets/tmwd_cdp_bridge/`(需安装,含debugger权限)
|
||||||
|
|||||||
Reference in New Issue
Block a user