Skip to content

Commit 5e16453

Browse files
committed
fixed a bug in chat completions think handling
1 parent e991bc0 commit 5e16453

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

koboldcpp.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,16 +4567,18 @@ async def handle_sse_stream(self, genparams, api_format):
45674567
delta = {'role': 'assistant'}
45684568
if genparams.get('encapsulate_thinking', True):
45694569
if encap_in_thinking:
4570-
# We are already inside a thinking block. thinkpairs has already been reduced to [pair], so we just check the active one.
4571-
active_pair = thinkpairs[0]
4572-
if active_pair["end"] in tokenStr:
4573-
encap_in_thinking = False
4574-
out1, out2 = tokenStr.split(active_pair["end"], 1)
4575-
if out1:
4576-
delta['reasoning_content'] = out1
4577-
if out2:
4578-
delta['content'] = out2
4579-
else:
4570+
foundend = False
4571+
for pair in thinkpairs:
4572+
if pair["end"] in tokenStr:
4573+
encap_in_thinking = False
4574+
foundend = True
4575+
out1, out2 = tokenStr.split(pair["end"], 1)
4576+
if out1:
4577+
delta['reasoning_content'] = out1
4578+
if out2:
4579+
delta['content'] = out2
4580+
break
4581+
if not foundend:
45804582
# Still thinking
45814583
delta['reasoning_content'] = tokenStr
45824584
else:

0 commit comments

Comments
 (0)