OpenAI  by MacPaw

Swift SDK for OpenAI's API

created 2 years ago
2,632 stars

Top 18.3% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This Swift package provides a community-driven implementation for interacting with the OpenAI public API, targeting Swift developers building applications that leverage AI capabilities. It offers comprehensive support for various OpenAI services, including chat completions, image generation, audio processing, embeddings, and the Assistants API, enabling developers to integrate advanced AI features into their iOS, macOS, and other Swift-based projects.

How It Works

The library acts as a robust wrapper around the OpenAI REST API, translating Swift objects and data structures into the JSON payloads required by the API and parsing the JSON responses back into Swift types. It utilizes Swift's Codable protocol for efficient data serialization/deserialization and supports both closure-based and Swift Concurrency (async/await) patterns for asynchronous operations. The design prioritizes compatibility with OpenAI's API specifications while offering flexibility for other OpenAI-compatible providers through configuration options.

Quick Start & Requirements

  • Install via Swift Package Manager: Add https://github.com/MacPaw/OpenAI.git to your Package.swift dependencies.
  • Requires an OpenAI API token.
  • Official Documentation: OpenAI Documentation

Highlighted Details

  • Comprehensive API coverage: Supports Chat, Images, Audio (Speech-to-Text, Text-to-Speech), Embeddings, Models, Moderations, and Assistants API.
  • Flexible initialization: Configure with API token, organization ID, and timeout.
  • Swift Concurrency and Combine support: Integrates seamlessly with modern Swift asynchronous programming paradigms.
  • Structured Output: Enables generating responses that adhere to a provided JSON schema.
  • OpenAI-compatible provider support: Can be configured to work with other providers using .relaxed parsing.

Maintenance & Community

  • Maintained by MacPaw Inc.
  • Contribution guidelines are provided, encouraging conventional commits and clear pull requests.

Licensing & Compatibility

  • MIT License: Permissive license allowing commercial use, modification, and distribution.
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

The library's primary focus is on OpenAI's API; support for other providers is secondary and may have limitations or require specific parsing configurations.

Health Check
Last commit

3 days ago

Responsiveness

Inactive

Pull Requests (30d)
8
Issues (30d)
7
Star History
211 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.