Skip to content

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

Notifications You must be signed in to change notification settings

ynagatomo/HeyChatGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages