How to Build an Azure OpenAI Chat App Using Power Apps Code Apps and React

Power Apps recently released a preview feature called “Code Apps” that enables building web applications, so I decided to create an actual app to try it out.

スポンサーリンク

Code Apps (Preview)

Code Apps is a new application format that allows you to host full-code web applications built with React and other frameworks on the Power Platform, while integrating them with Power Platform’s authentication, connectors, and management capabilities for distribution.
While the Power Apps Component Framework creates components that run within Power Apps canvas or model-driven apps, Code Apps enables building complete web applications from the ground up.

In this article, I’ll walk through creating a Code Apps application and building a web app that runs on Power Apps.

Prerequisites

There are three prerequisites:

  • Install the latest version of Power Platform CLI
  • Enable Code Apps in the environment where you’ll upload the app
  • Note down the GUID of the environment where you’ll upload the app

Install the Latest Version of Power Platform CLI

First, install the latest version of Power Platform CLI (PAC) in your development environment. *Note: Older versions don’t support the [pac code] command.

Enable Code Apps in the Target Environment

Next, enable Code Apps on the Power Platform side.

From the Power Platform admin center, click [Settings] for the target environment.
Navigate to [Features].
Enable [Power Apps code apps] and save.

Note Down the Environment GUID

Finally, note down the GUID of the environment where you’ll upload the app.

That completes the prerequisites.

Building the App

Launch the Sample App

First, let’s follow the official reference guide to launch the sample app provided by Microsoft locally.

Start by cloning the sample project from GitHub. *Note: URL is current as of the time of writing.

git clone https://github.com/microsoft/PowerAppsCodeApps.git
Next, install the required packages using npm install.
Create an authentication profile for the target environment using the pac auth command. Use the environment GUID you noted down during the prerequisites.

pac auth create --environment [Environment GUID]
If you see the following message, authentication was successful.
Next, initialize using pac code init. The “Hello World” portion sets the app name.

pac code init --displayName '[App Name]'
Then, launch locally with the following command.

npm run dev | pac code run
Once it launches successfully, access localhost:3000.
The web app is running!

Building a Chat App with Azure OpenAI (AOAI)

Let’s take it a step further by customizing the sample app to create a chat application.

Edit App.tsx in the project and save. *The code is available here. Note: This code has not been tested.
Launch the app again, and you’ll have a web application that enables conversations with Azure OpenAI. Since I’ve implemented SSE (Server-Sent Events) support, you can now have these types of real-time conversations that weren’t possible in canvas apps.

Upload the App to Power Platform

Finally, let’s upload the created app to Power Apps.

Use the pac code push command to push the app to your environment.

npm run build | pac code push

The app you created will now appear in the app list!
When launched, you can interact with your custom web app directly within the Power Apps interface.

This exciting new feature, “Code Apps,” is likely to become the standard approach for internal applications where users have paid licenses, rather than using Azure Web Apps.

スポンサーリンク

Support This Website

Thank you for visiting! It's because of readers like you that I continue to write and maintain this blog.

If you found this content helpful, consider buying me a coffee to support my work.

Ippu

Power Platform Engineer. Recently, I've also been working with generative AI, Azure, C#, and Python coding. I spent about 5 years developing in C# and C++, then worked in various service industries including hair & makeup, cafes, and retail.
I returned to IT in 2020 and now focus on designing and developing with Power Platform.
My cat's name is "Kotsubu," which means "small grain size" in Japanese.

Ippuをフォローする
Code Apps
スポンサーリンク
スポンサーリンク
スポンサーリンク
The Work Diaries

コメント

Copied title and URL