Skip to content

Commit

Permalink
add CaseIterable enums for types in use as magic numbers (ImagesQuery…
Browse files Browse the repository at this point in the history
….Size only)
  • Loading branch information
James J Kalafus committed Feb 5, 2024
1 parent 3e50aaa commit bd2f3a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Demo/DemoChat/Sources/UI/Images/ImageCreationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public struct ImageCreationView: View {

@State private var prompt: String = ""
@State private var n: Int = 1
@State private var size: String
private var sizes = ["256x256", "512x512", "1024x1024"]
@State private var size: ImagesQuery.Size

private var sizes = ImagesQuery.Size.allCases

public init(store: ImageStore) {
self.store = store
Expand All @@ -37,7 +37,7 @@ public struct ImageCreationView: View {
HStack {
Picker("Size", selection: $size) {
ForEach(sizes, id: \.self) {
Text($0)
Text($0.rawValue)
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions Sources/OpenAI/Public/Models/ImagesQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public struct ImagesQuery: Codable {
/// The number of images to generate. Must be between 1 and 10.
public let n: Int?
/// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
public let size: String?
public let size: Self.Size?
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
public let user: String?
/// The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.
public let style: String?
/// The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image. This param is only supported for dall-e-3.
public let quality: String?

public init(prompt: String, model: Model?=nil, responseFormat: Self.ResponseFormat?=nil, n: Int?, size: String?, style: String?=nil, user:String?=nil, quality:String?=nil) {
public init(prompt: String, model: Model?=nil, responseFormat: Self.ResponseFormat?=nil, n: Int?, size: Self.Size?, style: String?=nil, user:String?=nil, quality:String?=nil) {
self.style = style
self.prompt = prompt
self.n = n
Expand All @@ -55,4 +55,13 @@ public struct ImagesQuery: Codable {
case responseFormat = "response_format"
case quality
}

public enum Size: String, Codable, CaseIterable {
case _256 = "256x256"
case _512 = "512x512"
case _1024 = "1024x1024"
//case _1792_1024 = "1792x1024" // for dall-e-3 models
//case _1024_1792 = "1024x1792" // for dall-e-3 models

}
}

0 comments on commit bd2f3a5

Please sign in to comment.