Upgrade the request body field Function, use the Tool field for function calls.
Browse files- request.py +21 -32
request.py
CHANGED
@@ -277,7 +277,8 @@ async def get_claude_payload(request, engine, provider):
|
|
277 |
messages = []
|
278 |
system_prompt = None
|
279 |
for msg in request.messages:
|
280 |
-
|
|
|
281 |
if isinstance(msg.content, list):
|
282 |
content = []
|
283 |
for item in msg.content:
|
@@ -289,37 +290,25 @@ async def get_claude_payload(request, engine, provider):
|
|
289 |
content.append(image_message)
|
290 |
else:
|
291 |
content = msg.content
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
"
|
301 |
-
"
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
)
|
311 |
-
messages.append(
|
312 |
-
{
|
313 |
-
"role": "user",
|
314 |
-
"content": [
|
315 |
-
{
|
316 |
-
"type": "tool_result",
|
317 |
-
"tool_use_id": "toolu_01RofFmKHUKsEaZvqESG5Hwz",
|
318 |
-
"content": content
|
319 |
-
}
|
320 |
-
]
|
321 |
-
}
|
322 |
-
)
|
323 |
elif msg.role != "system":
|
324 |
messages.append({"role": msg.role, "content": content})
|
325 |
elif msg.role == "system":
|
|
|
277 |
messages = []
|
278 |
system_prompt = None
|
279 |
for msg in request.messages:
|
280 |
+
tool_calls = None
|
281 |
+
tool_call_id = None
|
282 |
if isinstance(msg.content, list):
|
283 |
content = []
|
284 |
for item in msg.content:
|
|
|
290 |
content.append(image_message)
|
291 |
else:
|
292 |
content = msg.content
|
293 |
+
tool_calls = msg.tool_calls
|
294 |
+
tool_call_id = msg.tool_call_id
|
295 |
+
|
296 |
+
if tool_calls:
|
297 |
+
tool_calls_list = []
|
298 |
+
for tool_call in tool_calls:
|
299 |
+
tool_calls_list.append({
|
300 |
+
"type": "tool_use",
|
301 |
+
"id": tool_call.id,
|
302 |
+
"name": tool_call.function.name,
|
303 |
+
"input": json.loads(tool_call.function.arguments),
|
304 |
+
})
|
305 |
+
messages.append({"role": msg.role, "content": tool_calls_list})
|
306 |
+
elif tool_call_id:
|
307 |
+
messages.append({"role": "user", "content": [{
|
308 |
+
"type": "tool_result",
|
309 |
+
"tool_use_id": tool_call.id,
|
310 |
+
"content": content
|
311 |
+
}]})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
elif msg.role != "system":
|
313 |
messages.append({"role": msg.role, "content": content})
|
314 |
elif msg.role == "system":
|