Skip to content
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

Added Image Generation support #221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/GoogleAI/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public enum FinishReason: String {
/// NOTE: When streaming, the Candidate.content will be empty if content filters blocked the
/// output.
case safety = "SAFETY"

/// The token generation was stopped because the response was flagged for image safety reasons.
case imageSafety = "IMAGE_SAFETY"

/// The token generation was stopped because the response was flagged for unauthorized citations.
case recitation = "RECITATION"
Expand Down
11 changes: 10 additions & 1 deletion Sources/GoogleAI/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public struct GenerationConfig {
/// this is limited to `application/json`.
public let responseSchema: Schema?

/// Array of output response modalities
///
/// Supported modalities:
/// - `text`: Text output
/// - `image`: Image output
public let responseModalities: [String]?

/// Creates a new `GenerationConfig` value.
///
/// - Parameters:
Expand All @@ -87,10 +94,11 @@ public struct GenerationConfig {
/// - stopSequences: See ``stopSequences``.
/// - responseMIMEType: See ``responseMIMEType``.
/// - responseSchema: See ``responseSchema``.
/// - responseModalities: See ``responseModalities``.
public init(temperature: Float? = nil, topP: Float? = nil, topK: Int? = nil,
candidateCount: Int? = nil, maxOutputTokens: Int? = nil,
stopSequences: [String]? = nil, responseMIMEType: String? = nil,
responseSchema: Schema? = nil) {
responseSchema: Schema? = nil, responseModalities: [String]? = nil) {
// Explicit init because otherwise if we re-arrange the above variables it changes the API
// surface.
self.temperature = temperature
Expand All @@ -101,6 +109,7 @@ public struct GenerationConfig {
self.stopSequences = stopSequences
self.responseMIMEType = responseMIMEType
self.responseSchema = responseSchema
self.responseModalities = responseModalities
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension ModelContent.Part: Codable {
}

enum InlineDataKeys: String, CodingKey {
case mimeType = "mime_type"
case mimeType
case bytes = "data"
}

Expand Down