-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add sglang reasoning parser #7171
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @eliasyin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a reasoning parser for sglang to extract thinking steps from model responses. The overall approach is sound, but I've identified a few issues. There's a logic flaw in the parsing function that could lead to incorrect behavior with certain inputs, a critical bug that will raise an AttributeError due to incorrect attribute access, and a minor code redundancy. I have provided specific comments and code suggestions to address these points.
| if template.template_meta.response_prefix: | ||
| response = template.template_meta.response_prefix + response |
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.
The code attempts to access template.template_meta.response_prefix, but the response_prefix attribute is defined on the Template class, not on TemplateMeta. This will result in an AttributeError at runtime. You should access this attribute directly from the template object.
| if template.template_meta.response_prefix: | |
| response = template.template_meta.response_prefix + response | |
| if template.response_prefix: | |
| response = template.response_prefix + response |
| start_idx = response.find(think_start) | ||
| end_idx = response.find(think_end) | ||
|
|
||
| if start_idx != -1 and end_idx != -1: | ||
| reasoning = response[start_idx + len(think_start):end_idx].strip() | ||
| content = response[end_idx + len(think_end):].strip() | ||
| return reasoning, content | ||
| elif start_idx != -1: | ||
| # Only start tag found (incomplete) | ||
| reasoning = response[start_idx + len(think_start):].strip() | ||
| return reasoning, '' | ||
| else: | ||
| # No thinking tags found | ||
| return None, response.strip() |
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.
The current logic for finding <think> and </think> tags can lead to incorrect parsing if </think> appears before <think> in the response string. For example, in a string like </think>...<think>..., find() will locate the first </think> and the first <think>, resulting in end_idx < start_idx. This would cause incorrect extraction of reasoning and content.
To fix this, you should first find the start tag, and then search for the end tag after the start tag's position. This ensures you're parsing a correctly-formed pair of tags.
| start_idx = response.find(think_start) | |
| end_idx = response.find(think_end) | |
| if start_idx != -1 and end_idx != -1: | |
| reasoning = response[start_idx + len(think_start):end_idx].strip() | |
| content = response[end_idx + len(think_end):].strip() | |
| return reasoning, content | |
| elif start_idx != -1: | |
| # Only start tag found (incomplete) | |
| reasoning = response[start_idx + len(think_start):].strip() | |
| return reasoning, '' | |
| else: | |
| # No thinking tags found | |
| return None, response.strip() | |
| start_idx = response.find(think_start) | |
| if start_idx == -1: | |
| # No thinking tags found | |
| return None, response.strip() | |
| end_idx = response.find(think_end, start_idx) | |
| if end_idx == -1: | |
| # Only start tag found (incomplete) | |
| reasoning = response[start_idx + len(think_start):].strip() | |
| return reasoning, '' | |
| # Both tags found | |
| reasoning = response[start_idx + len(think_start):end_idx].strip() | |
| content = response[end_idx + len(think_end):].strip() | |
| return reasoning, content |
PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).