Conversation
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i); | |
| const match = content.match(/<(think|thinking|thought)>([\s\S]*?)(?:<\/\1>|$)/i); |
qegj567-cloud/SullyOS#126