Skip to content

Commit d7162e3

Browse files
Merge pull request #10 from EnragedAntelope/claude/auto-model-discovery-vJqQA
Handle missing opening tag in reasoning extraction
2 parents e0e69e4 + 3064c69 commit d7162e3

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

LMStudio.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ def _extract_reasoning_auto(self, text: str) -> Tuple[str, str, Optional[str]]:
368368
clean_text = re.sub(pattern, "", text, flags=re.DOTALL)
369369
return clean_text.strip(), "\n---\n".join(reasoning_parts).strip(), open_tag
370370

371+
# Fallback: Check for closing tag without opening tag (model bug/edge case)
372+
# Some models forget the opening <think> but include closing </think>
373+
for _, open_tag, close_tag in COMMON_REASONING_PATTERNS:
374+
if close_tag in text and open_tag not in text:
375+
# Split on closing tag - everything before is reasoning
376+
parts = text.split(close_tag, 1)
377+
if len(parts) == 2:
378+
reasoning = parts[0].strip()
379+
response = parts[1].strip()
380+
if reasoning and response:
381+
return response, reasoning, f"{close_tag} (missing open tag)"
382+
371383
# No pattern matched
372384
return text, "", None
373385

0 commit comments

Comments
 (0)