Swift SDK for accessing the ChatGPT API
Top 49.9% on sourcepulse
This library provides a Swift-native interface for interacting with the OpenAI ChatGPT API, enabling developers to integrate conversational AI capabilities into Apple platform applications. It supports streaming and non-streaming responses, conversation history management, and customizable API parameters, simplifying the process of building AI-powered features for iOS, macOS, tvOS, and watchOS.
How It Works
The library leverages standard Swift concurrency (async/await
) for API calls. It offers two primary methods: sendMessageStream
for real-time, chunked responses via AsyncThrowingStream
, and sendMessage
for a single, complete response. Conversation history is managed internally, with automatic token count management (defaulting to 4096 tokens) using the GPTEncoder
library to prevent exceeding API limits.
Quick Start & Requirements
https://github.com/alfianlosari/ChatGPTSwift.git
) or Cocoapods (pod 'ChatGPTSwift', '~> 1.3.1'
).Highlighted Details
GPTEncoder
library for tokenization.Maintenance & Community
The project is maintained by alfianlosari. Further community or roadmap information is not detailed in the README.
Licensing & Compatibility
The README does not explicitly state a license. Compatibility for commercial use or closed-source linking is not specified.
Limitations & Caveats
The default token limit for conversation history is fixed at 4096, with plans to allow user-specified thresholds in the future. The absence of an explicit license may pose a risk for commercial adoption.
7 months ago
1 day