OpenAISwift  by adamrushy

Swift SDK for OpenAI API access

created 2 years ago
1,695 stars

Top 25.6% on sourcepulse

GitHubView on GitHub
Project Summary

This Swift library provides a community-maintained wrapper for the OpenAI HTTP API, enabling developers to integrate functionalities like text completion, chat, image generation, and moderation into their iOS, macOS, watchOS, and tvOS applications. It offers a convenient interface for accessing powerful AI models, simplifying the process of building AI-powered features.

How It Works

The library acts as a client, abstracting the complexities of direct HTTP requests to the OpenAI API. It serializes Swift objects into JSON payloads for requests and deserializes JSON responses back into Swift objects. This approach leverages Swift's strong typing and modern concurrency features (async/await) for cleaner, more robust API interactions compared to raw HTTP calls.

Quick Start & Requirements

  • Installation: Swift Package Manager (preferred): .package(url: "https://github.com/adamrushy/OpenAISwift.git", from: "1.2.0") or CocoaPods: pod 'OpenAISwift'.
  • Prerequisites: An OpenAI API key.
  • Setup: Import OpenAISwift and initialize with your API key.
  • Docs: OpenAI API Docs

Highlighted Details

  • Supports completions, chat (GPT-3.5, GPT-4), image generation (DALL-E), edits, moderation, and embeddings.
  • Offers both Swift concurrency (async/await) and completion handler variants for API calls.
  • Allows customization of API parameters like model, maxTokens, and temperature.

Maintenance & Community

  • Community-maintained library.
  • Open to contributions via Pull Requests.

Licensing & Compatibility

  • License: MIT License.
  • Compatibility: Permissive license allows for commercial use and integration into closed-source projects.

Limitations & Caveats

The library does not support streaming message content before completion for chat requests.

Health Check
Last commit

5 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
19 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.