yym68686 commited on
Commit
809165c
·
1 Parent(s): 0140d23

Upgrade the request body field Function, use the Tool field for function calls.

Browse files
Files changed (1) hide show
  1. 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
- name = None
 
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
- name = msg.name
293
- arguments = msg.arguments
294
- if arguments:
295
- arguments = json.loads(arguments)
296
- if name:
297
- # messages.append({"role": "assistant", "name": name, "content": content})
298
- messages.append(
299
- {
300
- "role": "assistant",
301
- "content": [
302
- {
303
- "type": "tool_use",
304
- "id": "toolu_01RofFmKHUKsEaZvqESG5Hwz",
305
- "name": name,
306
- "input": arguments,
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":