xiaoyi7894 commited on
Commit
22c59c6
·
1 Parent(s): 6fe2d68

fix: improve Anthropic tool_use streaming compatibility

Browse files
Files changed (1) hide show
  1. app.py +12 -17
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
- yield sse(
521
- "content_block_delta",
522
- {
523
- "type": "content_block_delta",
524
- "index": idx,
525
- "delta": {
526
- "type": "input_json_delta",
527
- "partial_json": json.dumps(blk["input"], ensure_ascii=False),
 
 
 
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: