-
Notifications
You must be signed in to change notification settings - Fork 5
feat(amsg): add fallback for readReasoningContent #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -88,11 +88,24 @@ function readReasoningContent(llmResponse) { | |||||
| if (!llmResponse || typeof llmResponse !== 'object') return null; | ||||||
| const choices = /** @type {{ choices?: unknown }} */ (llmResponse).choices; | ||||||
| if (!Array.isArray(choices) || choices.length === 0) return null; | ||||||
| const message = /** @type {{ message?: { reasoning_content?: unknown } }} */ (choices[0])?.message; | ||||||
| const message = /** @type {{ message?: { reasoning_content?: unknown, content?: unknown } }} */ (choices[0])?.message; | ||||||
|
|
||||||
| const raw = message?.reasoning_content; | ||||||
| if (typeof raw !== 'string') return null; | ||||||
| const trimmed = raw.trim(); | ||||||
| return trimmed.length > 0 ? trimmed : null; | ||||||
| if (typeof raw === 'string') { | ||||||
| const trimmed = raw.trim(); | ||||||
| if (trimmed.length > 0) return trimmed; | ||||||
| } | ||||||
|
|
||||||
| const content = message?.content; | ||||||
| if (typeof content === 'string') { | ||||||
| const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the LLM response is cut off (e.g., due to reaching
Suggested change
|
||||||
| if (match) { | ||||||
| const trimmed = match[2].trim(); | ||||||
| if (trimmed.length > 0) return trimmed; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the LLM response is cut off (e.g., due to reaching
max_tokensor budget limits), the closing tag</think>(or</thinking>,</thought>) might be missing from the end of the content. In such cases, the current regex will fail to match, and no reasoning content will be extracted.\n\nTo make the extraction more robust, we can update the regex to allow matching until the end of the string ($) if the closing tag is absent.