fix: guard all id/call_id fields with or "" to prevent None leaking into payload

This commit is contained in:
Liang Jiaqing
2026-04-23 11:00:04 +08:00
parent a53b7a8593
commit 17971f642a
2 changed files with 8 additions and 7 deletions

View File

@@ -75,7 +75,8 @@ class GeneraticAgent:
self.llm_no = ((self.llm_no + 1) if n < 0 else n) % len(self.llmclients) self.llm_no = ((self.llm_no + 1) if n < 0 else n) % len(self.llmclients)
lastc = self.llmclient lastc = self.llmclient
self.llmclient = self.llmclients[self.llm_no] self.llmclient = self.llmclients[self.llm_no]
self.llmclient.backend.history = lastc.backend.history try: self.llmclient.backend.history = lastc.backend.history
except: raise Exception('[ERROR] BAD Mixin config: Check your mykey.py')
self.llmclient.last_tools = '' self.llmclient.last_tools = ''
name = self.get_llm_name(model=True) name = self.get_llm_name(model=True)
if 'glm' in name or 'minimax' in name or 'kimi' in name: load_tool_schema('_cn') if 'glm' in name or 'minimax' in name or 'kimi' in name: load_tool_schema('_cn')

View File

@@ -207,7 +207,7 @@ def _parse_openai_sse(resp_lines, api_mode="chat_completions"):
fc = fc_buf[idx] fc = fc_buf[idx]
try: inp = json.loads(fc["args"]) if fc["args"] else {} try: inp = json.loads(fc["args"]) if fc["args"] else {}
except: inp = {"_raw": fc["args"]} except: inp = {"_raw": fc["args"]}
blocks.append({"type": "tool_use", "id": fc["id"], "name": fc["name"], "input": inp}) blocks.append({"type": "tool_use", "id": fc["id"] or '', "name": fc["name"], "input": inp})
return blocks return blocks
else: else:
tc_buf = {} # index -> {id, name, args} tc_buf = {} # index -> {id, name, args}
@@ -225,7 +225,7 @@ 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", ""), "name": "", "args": ""} if idx not in tc_buf: tc_buf[idx] = {"id": tc.get("id") or '', "name": "", "args": ""}
if tc.get("function", {}).get("name"): tc_buf[idx]["name"] = tc["function"]["name"] if tc.get("function", {}).get("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"]
usage = evt.get("usage") usage = evt.get("usage")
@@ -236,7 +236,7 @@ def _parse_openai_sse(resp_lines, api_mode="chat_completions"):
tc = tc_buf[idx] tc = tc_buf[idx]
try: inp = json.loads(tc["args"]) if tc["args"] else {} try: inp = json.loads(tc["args"]) if tc["args"] else {}
except: inp = {"_raw": tc["args"]} except: inp = {"_raw": tc["args"]}
blocks.append({"type": "tool_use", "id": tc["id"], "name": tc["name"], "input": inp}) blocks.append({"type": "tool_use", "id": tc["id"] or '', "name": tc["name"], "input": inp})
return blocks return blocks
def _record_usage(usage, api_mode): def _record_usage(usage, api_mode):
@@ -390,7 +390,7 @@ def _to_responses_input(messages):
result.append({"role": role, "content": parts}) result.append({"role": role, "content": parts})
for tc in (msg.get("tool_calls") or []): for tc in (msg.get("tool_calls") or []):
f = tc.get("function", {}) f = tc.get("function", {})
result.append({"type": "function_call", "call_id": tc.get("id", ""), "name": f.get("name", ""), "arguments": f.get("arguments", "")}) result.append({"type": "function_call", "call_id": tc.get("id") or '', "name": f.get("name", ""), "arguments": f.get("arguments", "")})
return result return result
@@ -407,7 +407,7 @@ def _msgs_claude2oai(messages):
if b.get("type") == "text" and b.get("text"): text_parts.append({"type": "text", "text": b.get("text", "")}) if b.get("type") == "text" and b.get("text"): text_parts.append({"type": "text", "text": b.get("text", "")})
elif b.get("type") == "tool_use": elif b.get("type") == "tool_use":
tool_calls.append({ tool_calls.append({
"id": b.get("id", ""), "type": "function", "id": b.get("id") or '', "type": "function",
"function": {"name": b.get("name", ""), "arguments": json.dumps(b.get("input", {}), ensure_ascii=False)} "function": {"name": b.get("name", ""), "arguments": json.dumps(b.get("input", {}), ensure_ascii=False)}
}) })
m = {"role": "assistant"} m = {"role": "assistant"}
@@ -426,7 +426,7 @@ def _msgs_claude2oai(messages):
tr = b.get("content", "") tr = b.get("content", "")
if isinstance(tr, list): if isinstance(tr, list):
tr = "\n".join(x.get("text", "") for x in tr if isinstance(x, dict) and x.get("type") == "text") tr = "\n".join(x.get("text", "") for x in tr if isinstance(x, dict) and x.get("type") == "text")
result.append({"role": "tool", "tool_call_id": b.get("tool_use_id", ""), "content": tr if isinstance(tr, str) else str(tr)}) result.append({"role": "tool", "tool_call_id": b.get("tool_use_id") or '', "content": tr if isinstance(tr, str) else str(tr)})
elif b.get("type") == "image": elif b.get("type") == "image":
src = b.get("source") or {} src = b.get("source") or {}
if src.get("type") == "base64" and src.get("data"): if src.get("type") == "base64" and src.get("data"):