-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,32 @@ func (rw *ResponseRewriter) Flush() { | |
| var modelFieldPaths = []string{"model", "modelVersion", "response.modelVersion", "message.model"} | ||
|
|
||
| // rewriteModelInResponse replaces all occurrences of the mapped model with the original model in JSON | ||
| // It also suppresses "thinking" blocks if "tool_use" is present to ensure Amp client compatibility | ||
| func (rw *ResponseRewriter) rewriteModelInResponse(data []byte) []byte { | ||
| // 1. Amp Compatibility: Suppress thinking blocks if tool use is detected | ||
| // The Amp client struggles when both thinking and tool_use blocks are present | ||
| // 1. Amp Compatibility: Suppress thinking blocks if tool use is detected | ||
| // The Amp client struggles when both thinking and tool_use blocks are present | ||
| if gjson.GetBytes(data, `content.#(type=="tool_use")`).Exists() { | ||
| filtered := gjson.GetBytes(data, `content.#(type!="thinking")#`) | ||
| 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()) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+80
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check 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())
}
} |
||
| } | ||
|
|
||
| if rw.originalModel == "" { | ||
| return data | ||
| } | ||
|
|
||
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.
These comments are duplicates of the ones on lines 74-75. They can be removed for conciseness.