Spaces:
Running
Running
Commit ·
22c59c6
1
Parent(s): 6fe2d68
fix: improve Anthropic tool_use streaming compatibility
Browse files
app.py
CHANGED
|
@@ -513,21 +513,22 @@ def anthropic_stream(upstream_resp, model_for_output: str, has_tools: bool):
|
|
| 513 |
"type": "tool_use",
|
| 514 |
"id": blk["id"],
|
| 515 |
"name": blk["name"],
|
| 516 |
-
"input": {},
|
| 517 |
},
|
| 518 |
},
|
| 519 |
)
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
"
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
"
|
| 527 |
-
"
|
|
|
|
|
|
|
|
|
|
| 528 |
},
|
| 529 |
-
|
| 530 |
-
)
|
| 531 |
yield sse(
|
| 532 |
"content_block_stop",
|
| 533 |
{"type": "content_block_stop", "index": idx},
|
|
@@ -898,12 +899,6 @@ def chat_completions():
|
|
| 898 |
)
|
| 899 |
|
| 900 |
|
| 901 |
-
log.info("启动 umans2api:http://%s:%d", HOST, PORT)
|
| 902 |
-
log.info("默认模型: %s", DEFAULT_MODEL)
|
| 903 |
-
log.info("可用模型: %s", ", ".join(AVAILABLE_MODELS))
|
| 904 |
-
log.info("Claude 映射: %s", CLAUDE_MODEL_MAP)
|
| 905 |
-
app.run(host=HOST, port=PORT, threaded=True)
|
| 906 |
-
|
| 907 |
# ---------- 管理页辅助 ----------
|
| 908 |
def mask_cookie_value(v):
|
| 909 |
if not isinstance(v, str) or not v:
|
|
|
|
| 513 |
"type": "tool_use",
|
| 514 |
"id": blk["id"],
|
| 515 |
"name": blk["name"],
|
|
|
|
| 516 |
},
|
| 517 |
},
|
| 518 |
)
|
| 519 |
+
_tool_json = json.dumps(blk["input"], ensure_ascii=False)
|
| 520 |
+
for _i in range(0, len(_tool_json), 120):
|
| 521 |
+
yield sse(
|
| 522 |
+
"content_block_delta",
|
| 523 |
+
{
|
| 524 |
+
"type": "content_block_delta",
|
| 525 |
+
"index": idx,
|
| 526 |
+
"delta": {
|
| 527 |
+
"type": "input_json_delta",
|
| 528 |
+
"partial_json": _tool_json[_i:_i+120],
|
| 529 |
+
},
|
| 530 |
},
|
| 531 |
+
)
|
|
|
|
| 532 |
yield sse(
|
| 533 |
"content_block_stop",
|
| 534 |
{"type": "content_block_stop", "index": idx},
|
|
|
|
| 899 |
)
|
| 900 |
|
| 901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
# ---------- 管理页辅助 ----------
|
| 903 |
def mask_cookie_value(v):
|
| 904 |
if not isinstance(v, str) or not v:
|