- In project directory run
flutter create .
to create the platform folders and other necessary files. - Create a
consts.dart
file with the following contents:
const String appKey = "Chat App Key";
const String userId = "Main User ID";
const String agoraToken = "Main User Token";
const String userId2 = "Second User ID";
const String agoraToken2 = "Second User Token";
const String openAIToken = "Your Token";
- Run the application:
flutter run
- Create an account on Agora.io
- Create a project
- Scroll down to
Chat
and clickEnable/Configure
- Click the toggle button and copy paste the AppKey.
- On the left side under
Operation Management
selectUser
and create 2 users. (Remember the User IDs) - Go back to
Application Information
under theBasic Information
tab and enter the User IDs for each user in theChat User Temp Token
field, and clickGenerate
. Bring the tokens and User IDs to theconsts.dart
file.
- Create an account on OpenAI
- Top right corner click on your image and select "View API Keys"
- Create a new Secret Key and copy paste it into the
consts.dart
file.
The app is a simple demo integrating Agora Chat with ChatGPT. The app has 2 users, and each user can send messages to the other user.
If the users are feeling a bit lazy they can just have ChatGPT generate the response for them. The response options are either a happy response or an angry response. Once a user clicks on either of those options a request is sent to OpenAI with the following prompt: "Give me an angry response to the message: " + the last message that was sent.
Once OpenAI responds with a message, that message is filled into the TextField
and the user can choose to regenerate a message in a different tone, or they can send that message.