-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement Maps Grounding feature #15611
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
Draft
google-labs-jules
wants to merge
5
commits into
main
Choose a base branch
from
maps-grounding-feature-5395490507180699682
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.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25a20a8
Implement Maps Grounding feature in FirebaseAI
google-labs-jules[bot] 1c27c4b
Address review comments
google-labs-jules[bot] 52b2bb7
Restore placeholder files
google-labs-jules[bot] 00b0dfc
Rename placeId to placeID
google-labs-jules[bot] 7ea81a9
Restore placeholders from main
google-labs-jules[bot] 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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,6 +63,12 @@ public struct GoogleSearch: Sendable { | |||||||||||||||||||||||
| public init() {} | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// A tool that allows the generative model to use Google Maps data. | ||||||||||||||||||||||||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||||||||||||||||||||||||
| public struct GoogleMaps: Sendable { | ||||||||||||||||||||||||
| public init() {} | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// A helper tool that the model may use when generating responses. | ||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||
| /// A `Tool` is a piece of code that enables the system to interact with external systems to perform | ||||||||||||||||||||||||
|
|
@@ -75,15 +81,20 @@ public struct Tool: Sendable { | |||||||||||||||||||||||
| /// Specifies the Google Search configuration. | ||||||||||||||||||||||||
| let googleSearch: GoogleSearch? | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Specifies the Google Maps configuration. | ||||||||||||||||||||||||
| let googleMaps: GoogleMaps? | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let codeExecution: CodeExecution? | ||||||||||||||||||||||||
| let urlContext: URLContext? | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| init(functionDeclarations: [FunctionDeclaration]? = nil, | ||||||||||||||||||||||||
| googleSearch: GoogleSearch? = nil, | ||||||||||||||||||||||||
| googleMaps: GoogleMaps? = nil, | ||||||||||||||||||||||||
| urlContext: URLContext? = nil, | ||||||||||||||||||||||||
| codeExecution: CodeExecution? = nil) { | ||||||||||||||||||||||||
| self.functionDeclarations = functionDeclarations | ||||||||||||||||||||||||
| self.googleSearch = googleSearch | ||||||||||||||||||||||||
| self.googleMaps = googleMaps | ||||||||||||||||||||||||
| self.urlContext = urlContext | ||||||||||||||||||||||||
| self.codeExecution = codeExecution | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -131,6 +142,16 @@ public struct Tool: Sendable { | |||||||||||||||||||||||
| return self.init(googleSearch: googleSearch) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Creates a tool that allows the model to use Google Maps. | ||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||
| /// - Parameters: | ||||||||||||||||||||||||
| /// - googleMaps: An empty ``GoogleMaps`` object. | ||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||
| /// - Returns: A `Tool` configured for Google Maps. | ||||||||||||||||||||||||
| public static func googleMaps(_ googleMaps: GoogleMaps = GoogleMaps()) -> Tool { | ||||||||||||||||||||||||
| return self.init(googleMaps: googleMaps) | ||||||||||||||||||||||||
|
Comment on lines
+146
to
+152
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.
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Creates a tool that allows you to provide additional context to the models in the form of | ||||||||||||||||||||||||
| /// public web URLs. | ||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||
|
|
@@ -237,5 +258,8 @@ extension FunctionCallingConfig.Mode: Encodable {} | |||||||||||||||||||||||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||||||||||||||||||||||||
| extension GoogleSearch: Encodable {} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||||||||||||||||||||||||
| extension GoogleMaps: Encodable {} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||||||||||||||||||||||||
| extension ToolConfig: Encodable {} | ||||||||||||||||||||||||
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
32 changes: 32 additions & 0 deletions
32
FirebaseAI/Tests/Unit/Resources/unary-success-google-maps-grounding.json
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,32 @@ | ||
| { | ||
| "candidates": [ | ||
| { | ||
| "content": { | ||
| "role": "model", | ||
| "parts": [ | ||
| { | ||
| "text": "Mountain View is about 40 miles south of San Francisco." | ||
| } | ||
| ] | ||
| }, | ||
| "finishReason": "STOP", | ||
| "index": 0, | ||
| "groundingMetadata": { | ||
| "groundingChunks": [ | ||
| { | ||
| "maps": { | ||
| "uri": "https://maps.google.com/?cid=123", | ||
| "title": "Mountain View", | ||
| "placeId": "places/123456789" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "usageMetadata": { | ||
| "promptTokenCount": 10, | ||
| "candidatesTokenCount": 15, | ||
| "totalTokenCount": 25 | ||
| } | ||
| } |
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.
With a time machine I'd make the
GoogleSearchinitializerinternaland same for this one.Note: This would follow the same approach as
URLContext:firebase-ios-sdk/FirebaseAI/Sources/Tool.swift
Lines 134 to 144 in 15d89de