fixed a bug in chat completions think handling

This commit is contained in:
Concedo
2026-04-07 00:16:34 +08:00
parent e991bc044e
commit 5e16453f0c
+12 -10
View File
@@ -4567,16 +4567,18 @@ class KcppServerRequestHandler(http.server.SimpleHTTPRequestHandler):
delta = {'role': 'assistant'}
if genparams.get('encapsulate_thinking', True):
if encap_in_thinking:
# We are already inside a thinking block. thinkpairs has already been reduced to [pair], so we just check the active one.
active_pair = thinkpairs[0]
if active_pair["end"] in tokenStr:
encap_in_thinking = False
out1, out2 = tokenStr.split(active_pair["end"], 1)
if out1:
delta['reasoning_content'] = out1
if out2:
delta['content'] = out2
else:
foundend = False
for pair in thinkpairs:
if pair["end"] in tokenStr:
encap_in_thinking = False
foundend = True
out1, out2 = tokenStr.split(pair["end"], 1)
if out1:
delta['reasoning_content'] = out1
if out2:
delta['content'] = out2
break
if not foundend:
# Still thinking
delta['reasoning_content'] = tokenStr
else: