-
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
25a20a8
1c27c4b
52b2bb7
00b0dfc
7ea81a9
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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() {} | ||||||||||||||||||||||||||||
|
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. With a time machine I'd make the
Suggested change
Note: This would follow the same approach as firebase-ios-sdk/FirebaseAI/Sources/Tool.swift Lines 134 to 144 in 15d89de
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// 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 {} | ||||||||||||||||||||||||||||
| 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 | ||
| } | ||
| } |
|
Member
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. Please restore this file
Contributor
Author
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. Restored.
Member
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. You didn't though. Put it back. Now.
Contributor
Author
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. Apologies. I have explicitly recreated the file to ensure it is restored. |
This file was deleted.
|
Member
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. Please restore this file
Contributor
Author
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. Restored.
Member
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. You didn't though.
Contributor
Author
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. Apologies. I have explicitly recreated the file to ensure it is restored. |
This file was deleted.
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.
s/placeId/placeID/
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.
Renamed
placeIdtoplaceIDand addedCodingKeysto handle the JSON mapping.