SwiftOpenAI  by jamesrochabrun

Swift package for interacting with OpenAI's API, plus Azure, AIProxy, and Assistants stream APIs

created 1 year ago
563 stars

Top 58.0% on sourcepulse

GitHubView on GitHub
Project Summary

SwiftOpenAI is a comprehensive Swift package for interacting with OpenAI's API, designed for developers building AI-powered applications on Apple platforms. It provides a robust and idiomatic Swift interface to a wide array of OpenAI functionalities, including chat completions, image generation, embeddings, fine-tuning, and the newer Assistants API.

How It Works

The package leverages Swift's strong typing and modern concurrency features (async/await) to offer a safe and efficient way to integrate with OpenAI. It abstracts away the complexities of HTTP requests and JSON serialization, providing strongly-typed models for parameters and responses. This approach enhances developer productivity and reduces the likelihood of runtime errors.

Quick Start & Requirements

  • Installation: Swift Package Manager (Xcode: File -> Add Package Dependency).
  • Requirements: Swift 5.5+, Xcode 13+.
  • API Key: Requires an OpenAI API key. For secure handling, it supports integration with AIProxy, which acts as a backend proxy for OpenAI requests, protecting your API key.

Highlighted Details

  • Comprehensive API Coverage: Supports numerous OpenAI endpoints including Chat, Audio (Speech, Translations, Transcriptions), Images (Create, Edit, Variations), Embeddings, Fine-tuning, Batch, Files, Models, Moderations, and the Assistants API (Beta).
  • Provider Compatibility: Works with OpenAI-compatible services like Azure OpenAI, AIProxy, Gemini, Ollama, Groq, OpenRouter, and DeepSeek by allowing custom base URLs and configurations.
  • Structured Outputs & Function Calling: Full support for structured outputs and function calling, enabling models to generate JSON or call predefined functions with strict schema adherence.
  • Vision API: Integrates with the Vision API via the chat completions endpoint for image input analysis.
  • Streaming Support: Offers streaming capabilities for chat completions and Assistants API events, allowing for real-time responses.

Maintenance & Community

The project is actively maintained by jamesrochabrun and welcomes community contributions via pull requests.

Licensing & Compatibility

The repository's license is not explicitly stated in the provided README, which may require clarification for commercial use or closed-source linking.

Limitations & Caveats

The README mentions that Assistants API support is for Beta 2, with a note to check the jroch-supported-branch-for-assistants-v1 branch or v2.3 release for V1 compatibility. Some advanced features like Pydantic models for structured outputs are not supported, requiring manual schema creation.

Feedback? Help us improve.