Swiftpack.co - asyncios/OpenMagicAI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by asyncios.
asyncios/OpenMagicAI 1.3.1
Swift library for accesing to OpenAI HTTP API
⭐️ 5
🕓 1 year ago
.package(url: "https://github.com/asyncios/OpenMagicAI.git", from: "1.3.1")

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 :heart: (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.

GitHub

link
Stars: 5
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.1
1 year ago

Changes:

  • Accept string or array on completion and embedding endpoints
  • Update sample app
  • Update unit tests

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics