-
Notifications
You must be signed in to change notification settings - Fork 610
feat(go/plugins/googlegenai): add multi-part tools support #3975
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
Open
hugoaguirre
wants to merge
9
commits into
main
Choose a base branch
from
haguirre/gemini_multipart_tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−15
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
27ad716
feat(go/plugins/googlegenai): add multi-part tools support
hugoaguirre 57b678b
fix multi-part issues
hugoaguirre a1c141e
fmt
hugoaguirre d59c370
remove code from ai/generate
hugoaguirre 9910d0a
update sample and GoogleAI live tests
hugoaguirre 9521303
Merge branch 'main' into haguirre/gemini_multipart_tools
hugoaguirre af663bb
create a new sample
hugoaguirre cf89fc7
Merge branch 'main' into haguirre/gemini_multipart_tools
hugoaguirre f0eaa03
fix formatter test case
hugoaguirre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/firebase/genkit/go/ai" | ||
| "github.com/firebase/genkit/go/genkit" | ||
| "github.com/firebase/genkit/go/plugins/googlegenai" | ||
| "google.golang.org/genai" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := context.Background() | ||
|
|
||
| g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{})) | ||
|
|
||
| // Define a multipart tool. | ||
| // This simulates a tool that takes a screenshot | ||
| screenshot := genkit.DefineMultipartTool(g, "screenshot", "Takes a screenshot", | ||
| func(ctx *ai.ToolContext, input any) (*ai.MultipartToolResponse, error) { | ||
| rectangle := "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHIAAABUAQMAAABk5vEVAAAABlBMVEX///8AAABVwtN+" + | ||
| "AAAAI0lEQVR4nGNgGHaA/z8UHIDwOWASDqP8Uf7w56On/1FAQwAAVM0exw1hqwkAAAAASUVORK5CYII=" | ||
| return &ai.MultipartToolResponse{ | ||
| Output: map[string]any{"success": true}, | ||
| Content: []*ai.Part{ | ||
| ai.NewMediaPart("image/png", rectangle), | ||
| }, | ||
| }, nil | ||
| }, | ||
| ) | ||
|
|
||
| // Define a simple flow that uses the multipart tool | ||
| genkit.DefineStreamingFlow(g, "cardFlow", func(ctx context.Context, input any, cb ai.ModelStreamCallback) (string, error) { | ||
| resp, err := genkit.Generate(ctx, g, | ||
| ai.WithModelName("googleai/gemini-3-pro-preview"), | ||
| ai.WithConfig(&genai.GenerateContentConfig{ | ||
| Temperature: genai.Ptr[float32](1.0), | ||
| ThinkingConfig: &genai.ThinkingConfig{ | ||
| ThinkingLevel: genai.ThinkingLevelHigh, | ||
| }, | ||
| }), | ||
| ai.WithTools(screenshot), | ||
| ai.WithStreaming(cb), | ||
| ai.WithPrompt("Tell me what I'm seeing in the screen"), | ||
| ) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return resp.Text(), nil | ||
| }) | ||
|
|
||
| <-ctx.Done() | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@apascal07 Wanted to ask, is #3902 related to this signature handling for tool calls? or is it something else?
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.
It's for reasoning, it's a token that the model returns that must be propagated to subsequent calls in the conversation otherwise it will error.