Fix/reasoning close only#10
Conversation
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
PR SummaryWhat Changed
Key Changes by Area
Files Changed
Review Focus Areas
Architecture
|
| additionalReasoning, finalContent := extractFromTags(cleanedContent) | ||
| if additionalReasoning != "" { | ||
| if reasoning != "" { | ||
| reasoning = reasoning + "\n\n" + additionalReasoning | ||
| } else { | ||
| reasoning = additionalReasoning | ||
| } | ||
| } | ||
| cleanedContent = finalContent |
There was a problem hiding this comment.
With WithThinkingForcedOpen(), the post-close remainder is reparsed by extractFromTags, which treats closing-only tags as reasoning blocks. This incorrectly reclassifies normal response content as reasoning when the remainder contains a stray closing tag, and removes that content from cleanedContent. Concrete failing case: "Reasoning</think>content</thinking>more" currently returns reasoning "Reasoning\n\ncontent" instead of "Reasoning", matching the failing test in pkg/reasoning/reasoning_test.go (should find earliest closing tag).
Suggested fix
if strings.Contains(cleanedContent, "<thinking>") ||
strings.Contains(cleanedContent, "<think>") ||
strings.Contains(cleanedContent, "<|START_THINKING|>") ||
strings.Contains(cleanedContent, "<|inner_prefix|>") ||
strings.Contains(cleanedContent, "<seed:think>") ||
strings.Contains(cleanedContent, "[THINK]") {
additionalReasoning, finalContent := extractFromTags(cleanedContent)
if additionalReasoning != "" {
if reasoning != "" {
reasoning = reasoning + "\n\n" + additionalReasoning
} else {
reasoning = additionalReasoning
}
}
cleanedContent = finalContent
}Prompt for AI assistance
Copy the prompt below and paste it into ChatGPT, Claude, or any LLM:
You are an expert bash developer with deep knowledge of security, performance, and best practices.
### Context
File: pkg/reasoning/reasoning.go
Lines: 102-110
Issue Type: functional-medium
Severity: medium
Issue Description:
With `WithThinkingForcedOpen()`, the post-close remainder is reparsed by `extractFromTags`, which treats closing-only tags as reasoning blocks. This incorrectly reclassifies normal response content as reasoning when the remainder contains a stray closing tag, and removes that content from `cleanedContent`. Concrete failing case: `"Reasoning</think>content</thinking>more"` currently returns reasoning `"Reasoning\n\ncontent"` instead of `"Reasoning"`, matching the failing test in `pkg/reasoning/reasoning_test.go` (`should find earliest closing tag`).
Current Code:
additionalReasoning, finalContent := extractFromTags(cleanedContent)
if additionalReasoning != "" {
if reasoning != "" {
reasoning = reasoning + "\n\n" + additionalReasoning
} else {
reasoning = additionalReasoning
}
}
cleanedContent = finalContent
---
### Instructions
1. Fix the issue described above
2. Maintain the exact indentation and code style from the original
3. Follow bash best practices and language-specific idioms
4. Ensure the fix addresses the root cause, not just the symptoms
5. Add brief inline comments explaining the fix if needed
### Constraints
- Do not change functionality beyond fixing the identified issue
- Preserve existing variable names and function signatures unless they are part of the problem
- Ensure the fix is production-ready
---
License Compliance Scan
Weak copyleft licenses found - verify compatibility Some packages have unknown licenses - manual review required Medium Risk Licenses - 4 packagesMPL-2.0 (4 packages):
Unknown Licenses - 67 packages
...and 47 more Powered by Codity.ai · Docs |
Description
This PR fixes #
Notes for Reviewers
Signed commits