-
Notifications
You must be signed in to change notification settings - Fork 681
fix(go/plugins/googlegenai): fixed tool thought signature #4798
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?
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1008,21 +1008,22 @@ func toGeminiPart(p *ai.Part) (*genai.Part, error) { | |||||||||
| } | ||||||||||
| } | ||||||||||
| fc := genai.NewPartFromFunctionCall(toolReq.Name, input) | ||||||||||
| // Restore ThoughtSignature if present in metadata | ||||||||||
| // Restore ThoughtSignature if present in metadata. | ||||||||||
| // Handle both []byte (original) and string (after JSON clone roundtrip | ||||||||||
| // which base64-encodes []byte values). | ||||||||||
| if p.Metadata != nil { | ||||||||||
| if sig, ok := p.Metadata["signature"].([]byte); ok { | ||||||||||
| fc.ThoughtSignature = sig | ||||||||||
| } | ||||||||||
| fc.ThoughtSignature = metadataSignature(p.Metadata) | ||||||||||
| } | ||||||||||
| return fc, nil | ||||||||||
| default: | ||||||||||
| return nil, fmt.Errorf("unknown part in the request: %q", p.Kind) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Restore ThoughtSignature if present in metadata. | ||||||||||
| // Handle both []byte (original) and string (after JSON clone roundtrip | ||||||||||
| // which base64-encodes []byte values). | ||||||||||
|
Comment on lines
+1022
to
+1024
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. This is a duplicate of the comment above (lines 1011-1013). To improve maintainability, it's best to avoid duplicating comments. A single-line comment would be sufficient here, as the details are in the
Suggested change
|
||||||||||
| if p.Metadata != nil { | ||||||||||
| if sig, ok := p.Metadata["signature"].([]byte); ok { | ||||||||||
| gp.ThoughtSignature = sig | ||||||||||
| } | ||||||||||
| gp.ThoughtSignature = metadataSignature(p.Metadata) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return gp, nil | ||||||||||
|
|
@@ -1033,6 +1034,23 @@ func toGeminiPart(p *ai.Part) (*genai.Part, error) { | |||||||||
| // - Start with a letter or an underscore | ||||||||||
| // - Must be alphanumeric and can include underscores, dots or dashes | ||||||||||
| // - Maximum length of 64 chars | ||||||||||
| // metadataSignature extracts the thought signature from part metadata. | ||||||||||
| // It handles both []byte (original value) and string (base64-encoded | ||||||||||
| // after a JSON clone roundtrip). | ||||||||||
| func metadataSignature(metadata map[string]any) []byte { | ||||||||||
| switch sig := metadata["signature"].(type) { | ||||||||||
| case []byte: | ||||||||||
| return sig | ||||||||||
| case string: | ||||||||||
| decoded, err := base64.StdEncoding.DecodeString(sig) | ||||||||||
| if err != nil { | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
| return decoded | ||||||||||
| } | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
Comment on lines
+1037
to
+1053
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. |
||||||||||
| func validToolName(n string) bool { | ||||||||||
| re := regexp.MustCompile(toolNameRegex) | ||||||||||
|
|
||||||||||
|
|
||||||||||
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.
This detailed comment is duplicated below (lines 1022-1024). Since the new
metadataSignaturefunction is well-commented, you can simplify the comments at the call sites to a single line to avoid repetition.