ChatGPTSwift  by alfianlosari

Swift SDK for accessing the ChatGPT API

created 2 years ago
696 stars

Top 49.9% on sourcepulse

GitHubView on GitHub
Project Summary

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

  • Installation: Swift Package Manager (https://github.com/alfianlosari/ChatGPTSwift.git) or Cocoapods (pod 'ChatGPTSwift', '~> 1.3.1').
  • Requirements: OpenAI API key, iOS/tvOS 15+, macOS 12+, watchOS 8+.
  • Demo Apps: Available in the SwiftUIChatGPT repo.

Highlighted Details

  • Supports streaming responses for real-time interaction.
  • Manages conversation history and token limits automatically.
  • Allows customization of model, system prompt, and temperature.
  • Includes a separate 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.

Health Check
Last commit

7 months ago

Responsiveness

1 day

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

Explore Similar Projects

Feedback? Help us improve.