Fix the bug where Claude cannot use tool use.
Browse files- request.py +10 -8
request.py
CHANGED
@@ -387,9 +387,10 @@ async def get_vertex_claude_payload(request, engine, provider):
|
|
387 |
|
388 |
messages = []
|
389 |
system_prompt = None
|
|
|
390 |
for msg in request.messages:
|
391 |
-
tool_calls = None
|
392 |
tool_call_id = None
|
|
|
393 |
if isinstance(msg.content, list):
|
394 |
content = []
|
395 |
for item in msg.content:
|
@@ -402,6 +403,7 @@ async def get_vertex_claude_payload(request, engine, provider):
|
|
402 |
else:
|
403 |
content = msg.content
|
404 |
tool_calls = msg.tool_calls
|
|
|
405 |
tool_call_id = msg.tool_call_id
|
406 |
|
407 |
if tool_calls:
|
@@ -414,11 +416,10 @@ async def get_vertex_claude_payload(request, engine, provider):
|
|
414 |
"input": json.loads(tool_call.function.arguments),
|
415 |
})
|
416 |
messages.append({"role": msg.role, "content": tool_calls_list})
|
417 |
-
elif tool_call_id
|
418 |
-
tool_call = tool_calls[0]
|
419 |
messages.append({"role": "user", "content": [{
|
420 |
"type": "tool_result",
|
421 |
-
"tool_use_id":
|
422 |
"content": content
|
423 |
}]})
|
424 |
elif msg.role != "system":
|
@@ -650,9 +651,10 @@ async def get_claude_payload(request, engine, provider):
|
|
650 |
|
651 |
messages = []
|
652 |
system_prompt = None
|
|
|
653 |
for msg in request.messages:
|
654 |
-
tool_calls = None
|
655 |
tool_call_id = None
|
|
|
656 |
if isinstance(msg.content, list):
|
657 |
content = []
|
658 |
for item in msg.content:
|
@@ -665,6 +667,7 @@ async def get_claude_payload(request, engine, provider):
|
|
665 |
else:
|
666 |
content = msg.content
|
667 |
tool_calls = msg.tool_calls
|
|
|
668 |
tool_call_id = msg.tool_call_id
|
669 |
|
670 |
if tool_calls:
|
@@ -677,11 +680,10 @@ async def get_claude_payload(request, engine, provider):
|
|
677 |
"input": json.loads(tool_call.function.arguments),
|
678 |
})
|
679 |
messages.append({"role": msg.role, "content": tool_calls_list})
|
680 |
-
elif tool_call_id
|
681 |
-
tool_call = tool_calls[0]
|
682 |
messages.append({"role": "user", "content": [{
|
683 |
"type": "tool_result",
|
684 |
-
"tool_use_id":
|
685 |
"content": content
|
686 |
}]})
|
687 |
elif msg.role != "system":
|
|
|
387 |
|
388 |
messages = []
|
389 |
system_prompt = None
|
390 |
+
tool_id = None
|
391 |
for msg in request.messages:
|
|
|
392 |
tool_call_id = None
|
393 |
+
tool_calls = None
|
394 |
if isinstance(msg.content, list):
|
395 |
content = []
|
396 |
for item in msg.content:
|
|
|
403 |
else:
|
404 |
content = msg.content
|
405 |
tool_calls = msg.tool_calls
|
406 |
+
tool_id = tool_calls[0].id if tool_calls else None or tool_id
|
407 |
tool_call_id = msg.tool_call_id
|
408 |
|
409 |
if tool_calls:
|
|
|
416 |
"input": json.loads(tool_call.function.arguments),
|
417 |
})
|
418 |
messages.append({"role": msg.role, "content": tool_calls_list})
|
419 |
+
elif tool_call_id:
|
|
|
420 |
messages.append({"role": "user", "content": [{
|
421 |
"type": "tool_result",
|
422 |
+
"tool_use_id": tool_id,
|
423 |
"content": content
|
424 |
}]})
|
425 |
elif msg.role != "system":
|
|
|
651 |
|
652 |
messages = []
|
653 |
system_prompt = None
|
654 |
+
tool_id = None
|
655 |
for msg in request.messages:
|
|
|
656 |
tool_call_id = None
|
657 |
+
tool_calls = None
|
658 |
if isinstance(msg.content, list):
|
659 |
content = []
|
660 |
for item in msg.content:
|
|
|
667 |
else:
|
668 |
content = msg.content
|
669 |
tool_calls = msg.tool_calls
|
670 |
+
tool_id = tool_calls[0].id if tool_calls else None or tool_id
|
671 |
tool_call_id = msg.tool_call_id
|
672 |
|
673 |
if tool_calls:
|
|
|
680 |
"input": json.loads(tool_call.function.arguments),
|
681 |
})
|
682 |
messages.append({"role": msg.role, "content": tool_calls_list})
|
683 |
+
elif tool_call_id:
|
|
|
684 |
messages.append({"role": "user", "content": [{
|
685 |
"type": "tool_result",
|
686 |
+
"tool_use_id": tool_id,
|
687 |
"content": content
|
688 |
}]})
|
689 |
elif msg.role != "system":
|