From 5e16453f0c8ed636d929dac2096c53c5c6a9feba Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:16:34 +0800 Subject: [PATCH] fixed a bug in chat completions think handling --- koboldcpp.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index db7effbcb..dfd503dd4 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -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: