一个最小的iOS应用程序,允许您与OpenAI聊天GPT-3.5 / 4交谈

iOS 应用程序 – 基本聊天 GPT 3.5/4

应用图标

与OpenAI Chat GPT-3.5 / 4交互的最小iOS应用程序。

  • 目標裝置:iPhone / iPad / Mac與M1 / M2(設計為iPad)
  • 目标操作系统: iOS 16.0+, iPadOS 16.0+, macOS 13.0+
  • 构建系统: Xcode 14.3+
  • SDK: SwiftUI

更新日志

没有

抽象

这是一个最小的iOS应用程序,通过OpenAI API与OpenAI Chat GPT 3.5 / 4进行通信。 该项目的目的是展示一个非常基本的示例代码,该代码与OpenAI GPT 3.5 / 4进行通信。 该项目直接处理OpenAI API。

In order to use the OpenAI API, you need to sign up to the OpenAI website 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. In addition to that, GPT-4 is under the limited service, so you need to entry to the waiting list first. After invited to GPT-4, you will be able to use the GPT-4 models. The API Key can be used for both GPT-3.5 and GPT-4. Until then, please use GPT-3.5 models.

Features

  • Users can set their API Key in User Settings, to make conversations with OpenAI GPT.
  • Users can make any number of conversations with OpenAI GPT 3.5 or 4 and delete them.
  • In a conversation, users can send any messages to OpenAI GPT as a user role or even an assistant role and delete any message.
  • In a conversation, users can configure GPT’s behavior by changing Chat Setting such as GPT model, parameters and system role.

Usage

  1. Set your API Key in the User Setting. This will be stored in UserDefaults.
  2. Add a conversation and select it.
  3. Add a message of user or assistant and edit the content.
  4. Send the conversation to OpenAI GPT.
  5. The response from OpenAI GPT will be shown. The conversation will be stored in a file on a device.
  6. Edit any messages or delete any messages and re-send the conversation to OpenAI GPT.
  7. You will be receive different conversation this time.

Image Image

Preparation to build and run the project

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/)

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 your API Key is invalid or your credits are short, the API calls will fail.

OpenAI GPT Models

  • GPT-4 [Limited beta] : More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration.
  • GPT-3.5-turbo : Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003.

Design

Type Structure and State Machines

The app consists of simple SwiftUI Views, a View Model, Models, a Manager, and OpenAI modules.

Image

References

License

MIT License

GitHub

点击跳转