From 0e42575c57b374e2b652b15cc2e03daec3170bc6 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 5 Aug 2025 15:36:20 -0700 Subject: [PATCH] Fix thinking block parsing for GPT-OSS under llama.cpp --- modules/html_generator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index 8777acf7..79237f7f 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -146,19 +146,23 @@ def extract_thinking_block(string): alt_end_pos = string.find(ALT_END) alt_content_pos = string.find(ALT_CONTENT_START) - # Check if start tag or end tag is found if alt_start_pos != -1 or alt_end_pos != -1: if alt_start_pos == -1: thought_start = 0 else: thought_start = alt_start_pos + len(ALT_START) + # If no explicit end tag but content start exists, use content start as end if alt_end_pos == -1: - thought_end = len(string) - content_start = len(string) + if alt_content_pos != -1: + thought_end = alt_content_pos + content_start = alt_content_pos + len(ALT_CONTENT_START) + else: + thought_end = len(string) + content_start = len(string) else: thought_end = alt_end_pos - content_start = alt_content_pos + len(ALT_CONTENT_START) if alt_content_pos != -1 else len(string) + content_start = alt_content_pos + len(ALT_CONTENT_START) if alt_content_pos != -1 else alt_end_pos + len(ALT_END) thinking_content = string[thought_start:thought_end] remaining_content = string[content_start:]