-
-
Notifications
You must be signed in to change notification settings - Fork 671
feature: Improves Amp client compatibility #605
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
Ensures compatibility with the Amp client by suppressing "thinking" blocks when "tool_use" blocks are also present in the response. The Amp client has issues rendering both types of blocks simultaneously. This change filters out "thinking" blocks in such cases, preventing rendering problems.
Summary of ChangesHello @soilSpoon, 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 enhances compatibility with the Amp client by introducing a mechanism to dynamically adjust API responses. It specifically addresses a rendering conflict where the Amp client struggles with simultaneous 'thinking' and 'tool_use' blocks. The change ensures a smoother user experience by filtering out 'thinking' blocks when 'tool_use' blocks are present, preventing display issues. 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 adds a compatibility fix for the Amp client by removing 'thinking' blocks from responses that also contain 'tool_use' blocks. The overall logic is correct and addresses the issue described. I've added a couple of comments to improve code clarity and remove redundancy. Specifically, I've pointed out duplicated comments and a redundant conditional check that can be simplified.
| // 1. Amp Compatibility: Suppress thinking blocks if tool use is detected | ||
| // The Amp client struggles when both thinking and tool_use blocks are present |
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 filtered.Exists() { | ||
| originalCount := gjson.GetBytes(data, "content.#").Int() | ||
| filteredCount := filtered.Get("#").Int() | ||
|
|
||
| if originalCount > filteredCount { | ||
| var err error | ||
| data, err = sjson.SetBytes(data, "content", filtered.Value()) | ||
| if err != nil { | ||
| log.Warnf("Amp ResponseRewriter: failed to suppress thinking blocks: %v", err) | ||
| } else { | ||
| log.Debugf("Amp ResponseRewriter: Suppressed %d thinking blocks due to tool usage", originalCount-filteredCount) | ||
| // Log the result for verification | ||
| log.Debugf("Amp ResponseRewriter: Resulting content: %s", gjson.GetBytes(data, "content").String()) | ||
| } | ||
| } | ||
| } |
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 check if filtered.Exists() is redundant. The outer if on line 78 already ensures that the content field exists. If content exists, gjson.GetBytes(data, content.#(type!="thinking")#) will always return a result where .Exists() is true (even if it's an empty JSON array []). You can simplify the code by removing this conditional block and un-indenting its contents.
originalCount := gjson.GetBytes(data, "content.#").Int()
filteredCount := filtered.Get("#").Int()
if originalCount > filteredCount {
var err error
data, err = sjson.SetBytes(data, "content", filtered.Value())
if err != nil {
log.Warnf("Amp ResponseRewriter: failed to suppress thinking blocks: %v", err)
} else {
log.Debugf("Amp ResponseRewriter: Suppressed %d thinking blocks due to tool usage", originalCount-filteredCount)
// Log the result for verification
log.Debugf("Amp ResponseRewriter: Resulting content: %s", gjson.GetBytes(data, "content").String())
}
}
Ensures compatibility with the Amp client by suppressing
"thinking" blocks when "tool_use" blocks are also present in
the response.
The Amp client has issues rendering both types of blocks
simultaneously. This change filters out "thinking" blocks in
such cases, preventing rendering problems.