yym68686 commited on
Commit
69fd3e6
·
1 Parent(s): a11cc62

Fix the bug of incorrect request body format for tool use.

Browse files
Files changed (3) hide show
  1. request.py +20 -18
  2. test/curl.py +5 -1
  3. utils.py +1 -1
request.py CHANGED
@@ -406,15 +406,16 @@ async def get_vertex_claude_payload(request, engine, provider):
406
 
407
  if tool_calls:
408
  tool_calls_list = []
409
- for tool_call in tool_calls:
410
- tool_calls_list.append({
411
- "type": "tool_use",
412
- "id": tool_call.id,
413
- "name": tool_call.function.name,
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
  messages.append({"role": "user", "content": [{
419
  "type": "tool_result",
420
  "tool_use_id": tool_call.id,
@@ -668,15 +669,16 @@ async def get_claude_payload(request, engine, provider):
668
 
669
  if tool_calls:
670
  tool_calls_list = []
671
- for tool_call in tool_calls:
672
- tool_calls_list.append({
673
- "type": "tool_use",
674
- "id": tool_call.id,
675
- "name": tool_call.function.name,
676
- "input": json.loads(tool_call.function.arguments),
677
- })
678
- messages.append({"role": msg.role, "content": tool_calls_list})
679
- elif tool_call_id:
 
680
  messages.append({"role": "user", "content": [{
681
  "type": "tool_result",
682
  "tool_use_id": tool_call.id,
 
406
 
407
  if tool_calls:
408
  tool_calls_list = []
409
+ tool_call = tool_calls[0]
410
+ tool_calls_list.append({
411
+ "type": "tool_use",
412
+ "id": tool_call.id,
413
+ "name": tool_call.function.name,
414
+ "input": json.loads(tool_call.function.arguments),
415
+ })
416
+ messages.append({"role": msg.role, "content": tool_calls_list})
417
+ elif tool_call_id and tool_calls:
418
+ tool_call = tool_calls[0]
419
  messages.append({"role": "user", "content": [{
420
  "type": "tool_result",
421
  "tool_use_id": tool_call.id,
 
669
 
670
  if tool_calls:
671
  tool_calls_list = []
672
+ tool_call = tool_calls[0]
673
+ tool_calls_list.append({
674
+ "type": "tool_use",
675
+ "id": tool_call.id,
676
+ "name": tool_call.function.name,
677
+ "input": json.loads(tool_call.function.arguments),
678
+ })
679
+ messages.append({"role": msg.role, "content": tool_calls_list})
680
+ elif tool_call_id and tool_calls:
681
+ tool_call = tool_calls[0]
682
  messages.append({"role": "user", "content": [{
683
  "type": "tool_result",
684
  "tool_use_id": tool_call.id,
test/curl.py CHANGED
@@ -6,8 +6,12 @@ from main import load_config
6
 
7
  provider_name = "linuxdoi"
8
  model = "claude-3-5-sonnet"
 
 
 
9
 
10
- config, api_keys_db, api_list = load_config()
 
11
  providers = config["providers"]
12
  provider_config = None
13
  for provider in providers:
 
6
 
7
  provider_name = "linuxdoi"
8
  model = "claude-3-5-sonnet"
9
+ import asyncio
10
+ config, api_keys_db, api_list = asyncio.run(load_config())
11
+ import json
12
 
13
+ print(json.dumps(api_keys_db, indent=2))
14
+ exit(0)
15
  providers = config["providers"]
16
  provider_config = None
17
  for provider in providers:
utils.py CHANGED
@@ -22,7 +22,7 @@ def update_config(config_data):
22
  return config_data, api_keys_db, api_list
23
 
24
  # 读取YAML配置文件
25
- async def load_config(app):
26
  import yaml
27
  try:
28
  with open('./api.yaml', 'r') as f:
 
22
  return config_data, api_keys_db, api_list
23
 
24
  # 读取YAML配置文件
25
+ async def load_config(app=None):
26
  import yaml
27
  try:
28
  with open('./api.yaml', 'r') as f: