GithubHelp home page GithubHelp logo

nivritgupta / heychatgpt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ynagatomo/heychatgpt

0.0 0.0 0.0 1.33 MB

A minimal iOS app that interacts with ChatGPT by your voice.

Swift 100.00%

heychatgpt's Introduction

iOS app - Hey ChatGPT

AppIcon

A minimal iOS app that interacts with ChatGPT. You can use your voice to ask questions and listen to ChatGPT's responses.

  • Target devices: iPhone / iPad / Mac with M1/M2 (Designed for iPad)
  • Target OS: iOS 16.0+, iPadOS 16.0+, macOS 13.0+
  • Build system: Xcode 14.3+
  • SDK: SwiftUI, AVFoundation, Speech
  • Swift Packages: OpenAISwift (OpenAI API Client Library in Swift)

You can probably use Xcode 14.0+. However, it has not been tested.

Change Log

none

Abstract

This is a minimal iOS app that communicates with ChatGPT using OpenAI API. The purpose of this project is showing a very basic sample code which uses the OpenAISwift Library. The library abstracts and simplifies communication with OpenAI servers using the OpenAI API.

Users can receive answers to their questions from the OpenAI server. Using the iOS SDK's speech recognition and text-to-speech, users can speak their questions and listen to the answers.

In order to use the OpenAI API, you need to sign up to the service and get the API key. First you are given free credits. When it is used up, it is necessary to subscribe to a paid service.

Features

  • Users can input questions by voice.
  • Users can get answers for the questions from ChatGPT, OpenAI's language AI.
  • Users can listen answers by voice.
  • Users can see their interaction history.
  • Language: This project supports English (en-US) for voice-recognition and speech synthesis. You can switch to other language modifying the code.

  • OpenAI LLM: This project uses the text-davinci-003 GPT-3 model by default. You can switch to other models such as text-curie-001, text-babbage-001, or text-ada-001 (fastest one), modifying the code.

Usage

  1. Ask questions by voice.
  2. Send the questions to OpenAI ChatGPT.
  3. View or hear the answers from OpenAI ChatGPT.

Image

Preparation to build and run the project

Import the OpenAISwift Library

Import the adamrushy/OpenAISwift Swift Package to the project. URL: https://github.com/adamrushy/OpenAISwift

Get the OpenAI API Key

The API Key for OpenAI API is required. You need to sign up to OpenAI site (https://openai.com/api/) and get the key. You can get the key at the account management page. (https://platform.openai.com/account/)

Add the API key file to the project

Add APIKey.swift file to the project and define the key you got as below.

// APIKey.swift
enum OpenAIAPIKey {
    static let key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

Check your credits

To use the OpenAI API, you need credits. You will get some free credits when you sign up. After using it, you need to purchase a paid subscription. It is reasonable because the computational cost of LLM is very high.

If there are no valid credits, the OpenAISwift API will return error 1.: The operation could't be completed. (OpenAISwift.OpenAIError error 1)

Considerations

Large Language Models

The project uses the GPT-3 LLM, text-davinci-003, by default. You can switch to another model specifying the model when calling the OpenAISwift API;

func sendCompletion(with prompt: String, model: OpenAIModelType = .gpt3(.davinci), maxTokens: Int = 16) async throws -> OpenAI

Image (c)OpenAI (https://platform.openai.com/docs/models/)

Supported Language for voice recognition and speech synthesis

The project supports English (en-US) by default. You can switch to other ones to specify it when calling APIs.

  • SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
  • AVSpeechSynthesisVoice(language: "en-US") // BCP47 language code

Design

Type Structure and State Machines

The app consists of simple SwiftUI Views, a View Model, Managers.

Image

References

License

MIT License

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.