Skip to content

Commit

Permalink
Add support for non-streaming APIs on macOS 11 (google-gemini#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Jan 9, 2024
1 parent fead303 commit 928726d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
name: "generative-ai-swift",
platforms: [
.iOS(.v15),
.macOS(.v12),
.macOS(.v11),
.macCatalyst(.v15),
],
products: [
Expand Down
2 changes: 2 additions & 0 deletions Sources/GoogleAI/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class Chat {
}

/// See ``sendMessageStream(_:)-4abs3``.
@available(macOS 12.0, *)
public func sendMessageStream(_ parts: PartsRepresentable...)
-> AsyncThrowingStream<GenerateContentResponse, Error> {
return sendMessageStream([ModelContent(parts: parts)])
Expand All @@ -74,6 +75,7 @@ public class Chat {
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
/// - Parameter content: The new content to send as a single chat message.
/// - Returns: A stream containing the model's response or an error if an error occurred.
@available(macOS 12.0, *)
public func sendMessageStream(_ content: [ModelContent])
-> AsyncThrowingStream<GenerateContentResponse, Error> {
return AsyncThrowingStream { continuation in
Expand Down
1 change: 1 addition & 0 deletions Sources/GoogleAI/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct GenerativeAIService {
return try parseResponse(T.Response.self, from: data)
}

@available(macOS 12.0, *)
func loadRequestStream<T: GenerativeAIRequest>(request: T)
-> AsyncThrowingStream<T.Response, Error> {
return AsyncThrowingStream { continuation in
Expand Down
2 changes: 2 additions & 0 deletions Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public final class GenerativeModel {
/// for conforming types).
/// - Returns: A stream wrapping content generated by the model or a ``GenerateContentError``
/// error if an error occurred.
@available(macOS 12.0, *)
public func generateContentStream(_ parts: PartsRepresentable...)
-> AsyncThrowingStream<GenerateContentResponse, Error> {
return generateContentStream([ModelContent(parts: parts)])
Expand All @@ -148,6 +149,7 @@ public final class GenerativeModel {
/// - Parameter content: The input(s) given to the model as a prompt.
/// - Returns: A stream wrapping content generated by the model or a ``GenerateContentError``
/// error if an error occurred.
@available(macOS 12.0, *)
public func generateContentStream(_ content: [ModelContent])
-> AsyncThrowingStream<GenerateContentResponse, Error> {
let generateContentRequest = GenerateContentRequest(model: modelResourceName,
Expand Down

0 comments on commit 928726d

Please sign in to comment.