Skip to content

Conversation

@eliasyin
Copy link

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Write the detail information belongs to this PR.

Experiment results

Paste your experiment result here(if needed).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 SglangEngine by adding robust parsing capabilities for Large Language Model responses. The core purpose is to enable the extraction and clear separation of a model's internal reasoning process, typically indicated by specific tags, from its direct answer. This improvement provides a more structured and transparent way to handle LLM outputs, making both the thought process and the final result readily accessible within the ChatMessage object.

Highlights

  • Reasoning Content Extraction: A new utility function, extract_reasoning_content, has been introduced in sglang_engine.py. This function is designed to parse LLM responses, specifically looking for content enclosed within <think> and </think> tags to separate the model's reasoning from its final answer.
  • SglangEngine Integration: The _create_chat_completion_response method within the SglangEngine has been updated to utilize the new extract_reasoning_content parser. This ensures that responses from 'thinking models' are processed to distinguish between the reasoning steps and the ultimate output.
  • Enhanced ChatMessage Structure: The ChatMessage object now includes a new field, reasoning_content. This allows the extracted reasoning process to be stored separately from the final content of the message, providing a more granular and informative representation of the LLM's output.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +181 to +182
if template.template_meta.response_prefix:
response = template.template_meta.response_prefix + response
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

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.

Suggested change
if template.template_meta.response_prefix:
response = template.template_meta.response_prefix + response
if template.response_prefix:
response = template.response_prefix + response

Comment on lines +42 to +55
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()
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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

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