OpenAI Swift package

James Rochabrun
2 min readOct 25, 2023
Open Source Swift package for OpenAI endpoints https://github.com/jamesrochabrun/SwiftOpenAI

Since ChatGPT came out, I’ve been wanting to spend some time playing around with OpenAI APIs. Finally, I found some free time to do just that. While attempting to integrate some of the functionality into a few projects, I thought it would be nice to create a library that supports all available endpoints. I know there are a few built-in open-source repos already, but I’m not sure if they are updated or if they support all the current endpoints. So, I went ahead and created one based on the latest OpenAI documentation.

Note: To use this library, you MUST have an OpenAI API key.

This library is available through Swift Package Manager, you can add it to your project using this link, and as I mentioned, it encompasses all the currently available OpenAI endpoints and functionalities.

This library supports:

Translation and transcription APIs.

Chat completion and streamed chat completion.

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.

List fine-tuning jobs, create a new fine-tuning job, retrieve a fine-tuning job based on job ID, cancel a fine-tuning job based on job ID, and list fine-tuning job events of a fine-tuning job.

List files, upload a new file, delete a file, retrieve a file, and access the content of an existing file.

Create a new image, edit an image using a prompt or a mask, and generate variants of an image.

List models, retrieve a model, and delete a fine-tuned model.

Classify whether text violates OpenAI’s Content Policy.

This library is open source so feel free to collaborate, follow the example projects for more details.

For more details about OpenAI check its documentation.

--

--