Description
ChatGPTSwift is a Swift package for calling the official OpenAI ChatGPT API from Apple platforms. It supports iOS and tvOS 15 and later, macOS 12 and later, watchOS 8 and later, and Linux. You install it with the Swift Package Manager by adding the repository URL, or with CocoaPods, and you initialise the client with an API key from OpenAI. The package offers two request styles. The stream API returns chunks of text as an AsyncThrowingStream that you read in a for loop, and the normal API sends one request and returns the complete reply once it is ready. You can pass the model, system prompt and temperature. The README gives gpt-3.5-turbo, You're a helpful assistant and 0.5 as the defaults. The client keeps a history list of the conversation so new prompts include earlier context. Before each new prompt it counts tokens with the GPTEncoder library and trims older messages if the count goes over 4096, and the README says a future version will let you set that threshold. You can read the current history from the historyList property and clear it when needed. The source is public on GitHub.…
Highlights
- Swift client for the OpenAI ChatGPT API
- Streaming and normal request styles
- Works on iOS, macOS, watchOS, tvOS and Linux
- Conversation history with token trimming
- Installs with Swift Package Manager or CocoaPods
Ratings & Reviews
No ratings yet
Be the first to rate ChatGPTSwift.
People also visit
ChatGPTSwift FAQ
What is ChatGPTSwift?
It is a Swift package that wraps the official OpenAI ChatGPT API so you can call it from Apple platforms and Linux.
Which platforms are supported?
The README lists iOS and tvOS 15 and above, macOS 12 and above, watchOS 8 and above, and Linux.
How do I install it?
Add the package URL in Swift Package Manager, or use CocoaPods. You also need an API key from OpenAI.
How does the conversation history work?
The client includes earlier messages in each new prompt. Before sending, it counts tokens with GPTEncoder and drops older messages when the count goes over 4096.
What are the best ChatGPTSwift alternatives?
Popular alternatives to ChatGPTSwift include ChatGPT-Siri, SwiftyChat and Chatgpt. See all ChatGPTSwift alternatives
