API: Fix tool_calls placement and other response compatibility issues
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user