Skip to content

JacksonJang/OpenAI

Repository files navigation

OpenAI

Version License

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate OpenAI into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'OpenAI'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate OpenAI into your Xcode project using Carthage, specify it in your Cartfile:

github "JacksonJang/OpenAI"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding OpenAI as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/JacksonJang/OpenAI.git", .upToNextMajor(from: "1.0.0"))
]

Usage

Only 3 steps needed to use OpenAI:

1️⃣ Import OpenAI in proper place.

import OpenAI

2️⃣ API token must be set. If you don't have the token, you can create new secret key through below link. https://beta.openai.com/account/api-keys

Using code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    OpenAI.setToken("YOU-NEED-SET-SECRET-KEY")
        
    return true
}

3️⃣ You can choose to use OpenAPI method (More features will be added..)

Using code:

OpenAI.makeImage(text: String,  count: Int, size: ImageSize,
               completion:@escaping (Result<ResponseImageModel, Errors>) -> Void)

Example

Generate Image

OpenAI.makeImage(text: "bird", count: 2, size: ._256x256, completion: { result in
          switch result {
          case .success(let model):
              let dic = model.data

              dic.forEach{
                  print("generated url : \($0.url)")
              }
          case .failure(let error):
              print("error : \(error.localizedDescription)")
          }
      })
}

Preview

Generate Image

Contribute

Contributions for bug fixing or improvements are welcomed. Feel free to submit a pull request. If you have any questions, feature suggestions or bug reports, please send me an email to hyo961015@naver.com.

References

License

OpenAI is available under the MIT license. See the LICENSE file for more info.