Determine whether to use tools through the configuration file tools.
Browse files- request.py +11 -3
request.py
CHANGED
@@ -149,6 +149,10 @@ async def get_gpt_payload(request, engine, provider):
|
|
149 |
if field not in miss_fields and value is not None:
|
150 |
payload[field] = value
|
151 |
|
|
|
|
|
|
|
|
|
152 |
return url, headers, payload
|
153 |
|
154 |
async def get_openrouter_payload(request, engine, provider):
|
@@ -329,11 +333,10 @@ async def get_claude_payload(request, engine, provider):
|
|
329 |
if field not in miss_fields and value is not None:
|
330 |
payload[field] = value
|
331 |
|
332 |
-
if request.tools:
|
333 |
tools = []
|
334 |
for tool in request.tools:
|
335 |
# print("tool", type(tool), tool)
|
336 |
-
|
337 |
json_tool = await gpt2claude_tools_json(tool.dict()["function"])
|
338 |
tools.append(json_tool)
|
339 |
payload["tools"] = tools
|
@@ -341,7 +344,12 @@ async def get_claude_payload(request, engine, provider):
|
|
341 |
payload["tool_choice"] = {
|
342 |
"type": "auto"
|
343 |
}
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
return url, headers, payload
|
347 |
|
|
|
149 |
if field not in miss_fields and value is not None:
|
150 |
payload[field] = value
|
151 |
|
152 |
+
if provider.get("tools") == False:
|
153 |
+
payload.pop("tools", None)
|
154 |
+
payload.pop("tool_choice", None)
|
155 |
+
|
156 |
return url, headers, payload
|
157 |
|
158 |
async def get_openrouter_payload(request, engine, provider):
|
|
|
333 |
if field not in miss_fields and value is not None:
|
334 |
payload[field] = value
|
335 |
|
336 |
+
if request.tools and provider.get("tools"):
|
337 |
tools = []
|
338 |
for tool in request.tools:
|
339 |
# print("tool", type(tool), tool)
|
|
|
340 |
json_tool = await gpt2claude_tools_json(tool.dict()["function"])
|
341 |
tools.append(json_tool)
|
342 |
payload["tools"] = tools
|
|
|
344 |
payload["tool_choice"] = {
|
345 |
"type": "auto"
|
346 |
}
|
347 |
+
|
348 |
+
if provider.get("tools") == False:
|
349 |
+
payload.pop("tools", None)
|
350 |
+
payload.pop("tool_choice", None)
|
351 |
+
|
352 |
+
# print("payload", json.dumps(payload, indent=2, ensure_ascii=False))
|
353 |
|
354 |
return url, headers, payload
|
355 |
|