fixed reasoning when non streaming

This commit is contained in:
Concedo 2026-06-28 12:35:03 +08:00
parent 9c5cdcc256
commit 0c163a9b4c
2 changed files with 27 additions and 22 deletions

View file

@ -7181,6 +7181,7 @@ Current version indicated by LITEVER below.
else if (dch.message) {
synchro_polled_response = dch.message.content;
let reasoningtxt = "";
let has_called_tools = (dch.message.tool_calls && dch.message.tool_calls.length>0);
if(dch.message.reasoning_content!=null && dch.message.reasoning_content!="") //vllm compat
{
reasoningtxt = dch.message.reasoning_content;
@ -7191,17 +7192,17 @@ Current version indicated by LITEVER below.
}
if(reasoningtxt!="")
{
if(dch.message.content==null)
if(dch.message.content==null && !has_called_tools)
{
synchro_polled_response = reasoningtxt;
}
else
{
synchro_polled_response = `${localsettings.start_thinking_tag}${reasoningtxt}${localsettings.stop_thinking_tag}${dch.message.content}`;
synchro_polled_response = `${localsettings.start_thinking_tag}${reasoningtxt}${localsettings.stop_thinking_tag}${dch.message.content?dch.message.content:''}`;
}
}
if(dch.message.tool_calls && dch.message.tool_calls.length>0)
if(has_called_tools)
{
synchro_polled_resptoolcalls = dch.message.tool_calls;
if(!synchro_polled_response)
@ -19875,6 +19876,10 @@ Current version indicated by LITEVER below.
function prepare_submit_generation() //wrap websearch into this
{
if(is_corpo_ui() && corpo_editing_turn != -1)
{
corpo_edit_chunk_save();
}
let senttext = document.getElementById("input_text").value;
document.getElementById("input_text").value = "";
PerformWebsearch(senttext,(res)=>{

View file

@ -5205,6 +5205,25 @@ class KcppServerRequestHandler(http.server.SimpleHTTPRequestHandler):
global last_non_horde_req_time
last_non_horde_req_time = time.time()
#handle potential think tags, but only chat completions will return them. the others just drop them
reasoningtxt = ""
if api_format==4 or api_format==8 or api_format==9: #chat completions, responses and anthropic messages, but only chat has reasoning returned
if recvtxt:
for pair in thinkformats:
starter = pair['start']
ender = pair['end']
start_idx = recvtxt.find(starter)
end_idx = recvtxt.find(ender, start_idx + len(starter))
if start_idx != -1 and end_idx != -1 and start_idx < end_idx:
reasoningtxt = recvtxt[start_idx + len(starter):end_idx]
recvtxt = recvtxt[:start_idx] + recvtxt[end_idx + len(ender):]
break
elif starter not in recvtxt and ender in recvtxt:
parts = recvtxt.split(ender, 1)
reasoningtxt = parts[0]
recvtxt = parts[1]
break
utfprint("\nOutput: " + recvtxt,1)
#tool calls resolution
@ -5237,25 +5256,6 @@ class KcppServerRequestHandler(http.server.SimpleHTTPRequestHandler):
modelNameToReturn = friendlymodelname
if autoswapmode and textName is not None:
modelNameToReturn = textName
#handle potential think tags, but only chat completions will return them. the others just drop them
reasoningtxt = ""
if api_format==4 or api_format==8 or api_format==9: #chat completions, responses and anthropic messages, but only chat has reasoning returned
if recvtxt:
for pair in thinkformats:
starter = pair['start']
ender = pair['end']
start_idx = recvtxt.find(starter)
end_idx = recvtxt.find(ender, start_idx + len(starter))
if start_idx != -1 and end_idx != -1 and start_idx < end_idx:
reasoningtxt = recvtxt[start_idx + len(starter):end_idx]
recvtxt = recvtxt[:start_idx] + recvtxt[end_idx + len(ender):]
break
elif starter not in recvtxt and ender in recvtxt:
parts = recvtxt.split(ender, 1)
reasoningtxt = parts[0]
recvtxt = parts[1]
break
if api_format == 1:
res = {"data": {"seqs": [recvtxt]}}
elif api_format == 3: