Swiftpack.co - Airgift/SwiftyGPT3 as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Airgift/SwiftyGPT3
A simple Swift package which acts as an OpenAI client for the GPT-3 API.
.package(url: "https://github.com/Airgift/SwiftyGPT3.git", from: "0.1.1")

SwiftyGPT3

A simple Swift package which acts as an OpenAI client for GPT-3 brought to you by the Airgift Crew. Supports GPT-3 Codex!

Requirements

  • iOS 10.0 or later
  • tvOS 10.0 or later
  • watchOS 3.0 or later
  • macOS 10.12 or later
  • Xcode 8.0 or later

Installation

Install this package with Swift Package Manager

https://github.com/heysaik/SwiftyGPT3.git

Usage

import SwiftyGPT3

let openai = SwiftyGPT3(apiKey: "YOUR-OPENAI-KEY")
openai.performCompletions(
    prompt: "User: Hi AI!\nAI: Hello! What can I help you with?\nUser: Can you please tell me what the weather is?",
    maxTokens: 60,
    stopSequences: ["User:"],
    engine: .davinci
) { result, _ in
    if let response = result {
        print(response)
    }
}

Customizable Parameters

Parameter Description
prompt GPT-3 completes its answers based on the prompt you give. Learn more about designing a great prompt here.
maxTokens The maximum number of tokens to generate. Requests can use up to 2048 tokens shared between prompt and completion. One token is roughly 4 characters for normal English text
temperature Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.
topP Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered.
frequencePenalty How much to penalize new tokens based on their existing frequency in the text so far. Decreases the model's likelihood to repeat the same line verbatim.
presencePenalty How much to penalize new tokens based on whether they appear in the text so far. Increases the model's likelihood to talk about new topics.
bestOf Generates multiple completions server-side, and displays only the best. Streaming only works when set to 1. Since it acts as a multiplier on the number of completions, this parameters can eat into your token quota very quickly - use caution!
stopSequenes Up to four sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
engine The engine to use for the API request. These engines provide a spectrum of capability, where davinci is the most capable and ada is the fastest.

TODO

  • ☑ Completion Endpoint
  • ☐ Classification Endpoint
  • ☐ Semantic Search Endpoint
  • ☐ Question-Answering Endpoint

Acknowledgements

GitHub

link
Stars: 12
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

Version 0.1.1
4 weeks ago

Projects using SwiftyGPT3 were failing when building for Any iOS Device in Xcode 13. The reason for this stems from using Alamofire as a dependency. As such, we switched to using the features/async-handlers branch of Alamofire for this release.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics