Coder Social home page Coder Social logo

chatgptswift's Introduction

ChatGPTSwift API

Alt text

Access ChatGPT "Official" API from Swift. Works on all Apple platforms.

DISCLAIMERS!

This uses a leaked model with special prompt to trigger. Conversation history is stored on client. Its an unpatched bug that might be taken down in future.

Use this at your own risk, there is a possibility that OpenAI might ban your account using this approach! I don't take any responsibility.

Supported Platforms

  • iOS/tvOS 15 and above
  • macOS 12 and above
  • watchOS 8 and above

Installation

Swift Package Manager

Requirement

Register for API key from OpenAI. Initialize with api key

let api = ChatGPTAPI(apiKey: "API_KEY")

Usage

There are 2 APIs: stream and normal

Stream

The server will stream chunks of data until complete, the method AsyncThrowingStream which you can loop using For-Loop like so:

Task {
    do {
        let stream = try await api.sendMessageStream(text: "What is ChatGPT?")
        for try await line in stream {
            print(line)
        }
    } catch {
        print(error.localizedDescription)
    }
}

Normal

A normal HTTP request and response lifecycle. Server will send the complete text (it will take more time to response)

Task {
    do {
        let response = try await api.sendMessage(text: "What is ChatGPT?")
        print(response)
    } catch {
        print(error.localizedDescription)
    }
}
        

Demo Apps

You can check the demo apps for iOS and macOS from the SwiftUIChatGPT repo

chatgptswift's People

Contributors

alfianlosari avatar

Forkers

mobiledev43

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.