API: Fix tool_calls placement and other response compatibility issues

This commit is contained in:
oobabooga
2026-03-05 21:25:03 -08:00
parent f06583b2b9
commit d0ac58ad31
3 changed files with 6 additions and 7 deletions
+2 -2
View File
@@ -456,11 +456,11 @@ for _ in range(10):
messages.append({
"role": "assistant",
"content": choice["message"]["content"],
"tool_calls": choice["tool_calls"],
"tool_calls": choice["message"]["tool_calls"],
})
# Execute each tool and add results to history
for tool_call in choice["tool_calls"]:
for tool_call in choice["message"]["tool_calls"]:
name = tool_call["function"]["name"]
arguments = json.loads(tool_call["function"]["arguments"])
result = execute_tool(name, arguments)
+2 -3
View File
@@ -370,8 +370,7 @@ def chat_completions_common(body: dict, is_legacy: bool = False, stream=False, p
resp_list: [{
"index": 0,
"finish_reason": stop_reason,
"message": {"role": "assistant", "content": answer},
"tool_calls": tool_calls
"message": {"role": "assistant", "content": answer, "tool_calls": tool_calls},
}],
"usage": {
"prompt_tokens": token_count,
@@ -389,7 +388,7 @@ def chat_completions_common(body: dict, is_legacy: bool = False, stream=False, p
def completions_common(body: dict, is_legacy: bool = False, stream=False, stop_event=None):
object_type = 'text_completion.chunk' if stream else 'text_completion'
object_type = 'text_completion'
created_time = int(time.time())
cmpl_id = "conv-%d" % (int(time.time() * 1000000000))
resp_list = 'data' if is_legacy else 'choices'
+2 -2
View File
@@ -359,7 +359,7 @@ async def handle_load_model(request_data: LoadModelRequest):
return JSONResponse(content="OK")
except Exception:
traceback.print_exc()
return HTTPException(status_code=400, detail="Failed to load the model.")
raise HTTPException(status_code=400, detail="Failed to load the model.")
@app.post("/v1/internal/model/unload", dependencies=check_admin_key)
@@ -380,7 +380,7 @@ async def handle_load_loras(request_data: LoadLorasRequest):
return JSONResponse(content="OK")
except Exception:
traceback.print_exc()
return HTTPException(status_code=400, detail="Failed to apply the LoRA(s).")
raise HTTPException(status_code=400, detail="Failed to apply the LoRA(s).")
@app.post("/v1/internal/lora/unload", dependencies=check_admin_key)