Skip to content

Latest commit

 

History

History
94 lines (65 loc) · 2.52 KB

README.md

File metadata and controls

94 lines (65 loc) · 2.52 KB

OpenAI

This package lets you quickly and easily access a variety of OpenAI API endpoints. It supports completions and chat streaming.

What's Implemented:

Installation

The module name of the package is OpenAI. Choose one of the instructions below to install and add the following import statement to your source code.

import OpenAI

From Xcode menu: File > Swift Packages > Add Package Dependency

https://github.com/Recouse/OpenAI

In your Package.swift file, first add the following to the package dependencies:

.package(url: "https://github.com/Recouse/OpenAI.git"),

And then, include "OpenAI" as a dependency for your target:

.target(name: "<target>", dependencies: [
    .product(name: "OpenAI", package: "OpenAI"),
]),

Usage

import OpenAI

...

let client = OpenAI(apiKey: "*YOUR API KEY*")

let chat = try await client.chat.completions(model: .gpt3_5_turbo, messages: [
    .user("Say This is a test.")
])

// Using streaming

let chat = client.chat.completionsStream(model: .gpt3_5_turbo, messages: [
    .user("Say This is a test in 5 different styles.")
])

for try await chunk in chat {
    print(chunk.choices.first?.delta.content)
}

Compatibility

  • macOS 10.15+
  • iOS 13.0+
  • tvOS 13.0+
  • watchOS 6.0+
  • visionOS 1.0+

Dependencies

Contributing

Contributions to are always welcomed! If you'd like to contribute, please fork this repository and submit a pull request with your changes.

License

OpenAI is released under the MIT license. See LICENSE for more information.