Skip to content

feat(amsg): add fallback for readReasoningContent#9

Merged
Tosd0 merged 1 commit into
mainfrom
dev
May 28, 2026
Merged

feat(amsg): add fallback for readReasoningContent#9
Tosd0 merged 1 commit into
mainfrom
dev

Conversation

@Tosd0

@Tosd0 Tosd0 commented May 28, 2026

Copy link
Copy Markdown
Owner

@Tosd0 Tosd0 merged commit 4141fe2 into main May 28, 2026
2 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism in readReasoningContent for both the instant and server packages to extract reasoning content from message.content when the native reasoning_content field is missing. It parses tags like <think>, <thinking>, and <thought> to support models like DeepSeek-R1-Distill. The review feedback suggests making the regex extraction more robust by allowing matches to the end of the string if the closing tag is missing due to a truncated LLM response.


const content = message?.content;
if (typeof content === 'string') {
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the LLM response is cut off (e.g., due to reaching max_tokens or 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.

Suggested change
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)(?:<\/\1>|$)/i);


const content = message?.content;
if (typeof content === 'string') {
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the LLM response is cut off (e.g., due to reaching max_tokens or 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.

Suggested change
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
const match = content.match(/<(think|thinking|thought)>([\s\S]*?)(?:<\/\1>|$)/i);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant