Fix the bug of incorrect request body format for tool use.
Browse files- request.py +20 -18
- test/curl.py +5 -1
- 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 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
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 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
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 |
-
|
|
|
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:
|