-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Firebase AI] Add Sendable conformance to PartsRepresentable
#15199
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
andrewheard
wants to merge
4
commits into
main
Choose a base branch
from
ah/ai-partsrep-sendable
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.
+35
−8
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
88e16fb
[Firebase AI] Add `Sendable` conformance to `PartsRepresentable`
andrewheard ffdf538
Try workaround for `Sendable` on Xcode 16.2
andrewheard ebad68e
Merge branch 'main' into ah/ai-partsrep-sendable
andrewheard 9febee3
Merge remote-tracking branch 'origin/main' into ah/ai-partsrep-sendable
andrewheard 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,8 +50,8 @@ enum ImageConversionError: Error { | |
| #elseif canImport(AppKit) | ||
| /// Enables images to be representable as ``PartsRepresentable``. | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||
| extension NSImage: PartsRepresentable { | ||
| public var partsValue: [any Part] { | ||
| public extension NSImage { | ||
| var partsValue: [any Part] { | ||
| guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else { | ||
| return [ErrorPart(ImageConversionError.invalidUnderlyingImage)] | ||
| } | ||
|
|
@@ -63,13 +63,22 @@ enum ImageConversionError: Error { | |
| return [InlineDataPart(data: data, mimeType: "image/jpeg")] | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| #if swift(>=6.2) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||
| extension NSImage: PartsRepresentable {} | ||
|
Comment on lines
+68
to
+69
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. This produces the warning |
||
| #else // swift(>=6.2) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||
| extension NSImage: @unchecked @retroactive Sendable, PartsRepresentable {} | ||
| #endif | ||
|
|
||
| #endif // canImport(UIKit) | ||
|
|
||
| #if !os(watchOS) // This code does not build on watchOS. | ||
| /// Enables `CGImages` to be representable as model content. | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CGImage: PartsRepresentable { | ||
| public var partsValue: [any Part] { | ||
| public extension CGImage { | ||
| var partsValue: [any Part] { | ||
andrewheard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let output = NSMutableData() | ||
| guard let imageDestination = CGImageDestinationCreateWithData( | ||
| output, UTType.jpeg.identifier as CFString, 1, nil | ||
|
|
@@ -86,13 +95,22 @@ enum ImageConversionError: Error { | |
| return [ErrorPart(ImageConversionError.couldNotConvertToJPEG)] | ||
| } | ||
| } | ||
|
|
||
| #if swift(>=6.1) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CGImage: PartsRepresentable {} | ||
| #else // swift(>=6.1) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CGImage: @unchecked @retroactive Sendable, PartsRepresentable {} | ||
| #endif // swift(>=6.1) | ||
|
|
||
| #endif // !os(watchOS) | ||
|
|
||
| #if canImport(CoreImage) | ||
| /// Enables `CIImages` to be representable as model content. | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CIImage: PartsRepresentable { | ||
| public var partsValue: [any Part] { | ||
| public extension CIImage { | ||
| var partsValue: [any Part] { | ||
andrewheard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let context = CIContext() | ||
| let jpegData = (colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)) | ||
| .flatMap { | ||
|
|
@@ -107,4 +125,13 @@ enum ImageConversionError: Error { | |
| return [ErrorPart(ImageConversionError.couldNotConvertToJPEG)] | ||
| } | ||
| } | ||
|
|
||
| #if swift(>=6.2) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CIImage: PartsRepresentable {} | ||
| #else // swift(>=6.2) | ||
| @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) | ||
| extension CIImage: @unchecked @retroactive Sendable, PartsRepresentable {} | ||
| #endif // swift(>=6.2) | ||
|
|
||
| #endif // canImport(CoreImage) | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.