/OpenMagicAI

Swift library for accesing to OpenAI HTTP API

Primary LanguageSwiftMIT LicenseMIT

Swift Platforms CHAT GPT-4 CHAT GPT-3.5 CHAT GPT-3 Swift Package Manager Async Await Combine

OpenMagicAI: A Non-official OpenAI iOS library

This is a non-official iOS library of OpenAI.

OpenMagicAI is a friendly Swift library for accesing to OpenAI API. OpenAI api official docs reference.

Chat GPT-4 model support ❤️ (Limited beta) Join the waitlist

Example usage

There's a sample app here using the methods of OpenMagicAI library.

Chat Create Image List Models

Installation

Swift Package Manager (SPM)

SPM is a tool for managing the distribution of Swift code.

dependencies: [ 
  .package(url: "https://github.com/asyncios/OpenMagicAI.git", .upToNextMajor(from: "1.3.0"))
 ]

Usage

Set your API Key, if you don't have one create it here

let openMagicAI = OpenMagicAI(apiKey: "APIKEY")

Chat

openMagicAI.chat.createChatCompletion(
    messages: [.init(role: .user, content: "Give me some movie options for tonight")]
) { result in
       debugPrint(result)
}

// GPT-4 model
openMagicAI.chat.createChatCompletion(
    model: .gpt4,
    messages: [.init(role: .user, content: "Give me some movie options for tonight")]
) { result in
       debugPrint(result)
}

Closure usage

openMagicAI.images.createImage(prompt: "dog in a park") { result in
   debugPrint(result)
}

Async Await usage

Task {
  let result = try await openMagicAI.images.createImage("dog in a park")
  debugPrint(result)
}

Combine usage

openMagicAI.images.createImage(prompt: "dog in a park").sink { _ in
} receiveValue: { value in
  debugPrint(value)
}.store(in: &cancellables)

Endpoints available

Licenses

All source code is licensed under the MIT License.