2

Deploy ChatGPT Next Web to Azure App Service with Individual Account Login in 3...

 11 months ago
source link: https://edi.wang/post/2023/5/18/deploy-chatgpt-next-web-to-azure-app-service-with-individual-account-login-in-3-minutes
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Deploy ChatGPT Next Web to Azure App Service with Individual Account Login in 3 minutes

Original

Edi Wang

5/18/2023, 8:09:52 AM

148 Reads


Background


ChatGPT Next Web is a popular ChatGPT web UI project. It requires only your Open API key to deploy a web site that can be deployed to your own server, then you can have the same chat experience without going to the official Open AI website. This is typically used to work around some network or regional restrictions. 

However, the official repo of ChatGPT Next Web did not provide a one-click install for Azure, and the developer is not planning to provide a built-in login feature to limit access to the website. I would like to solve both issues by Azure, my goal is:

  1. Deploy ChatGPT Next Web to Azure without creating a VM
  2. Add access control that requires individual account to login to use ChatGPT without modifying any code
  3. Complete these tasks in 3 minutes

Let's see how to do this.

Create Azure App Service


The official ChatGPT Next Web provides a Docker image. This is how I can run it on Azure without VM. Azure has many PaaS ways to deploy Docker containers:

  1. Azure App Service
  2. Azure Container Instance
  3. Azure Container App

I choose App Service because it has built in Authentication features that I will use in the next step.

Go to Azure Portal, create a new Web App, select Docker Container + Linux in instance details.

img-20954142-e8b7-4fe2-a5bf-948aac4de76b.png

For pricing plans, as I tested, Basic SKUs are enough for a few users, you can choose a higher SKU if you have a lot more end users.

In Docker step, use single container from public Docker Hub, named: yidadaa/chatgpt-next-web

img-50a0098e-8938-4823-a58d-dabf41e880d6.png

Configure other steps as you like, and finish creating the web app.

Configure Environment Variables


After creating the Web App, we need to configure two environment variables for the Docker container before running the application.

Go to Configuration blade, and add two settings:

  1. OPENAI_API_KEY: Use your own key bought from Open API official website, usually start with "sk-"
  2. PORT: 443
img-f47a367a-67b8-48a6-8bf0-ced9b132a3ca.png

I would also suggest turn on HTTP2 in general settings for better performance.

img-9464118a-e9c4-4ba1-9cc0-7cb1243663ba.png

By now, your ChatGPT web UI is ready to run. You can access the page by default domain, or bind your custom domian.

img-ec87115e-6894-4819-aa91-51e6f41a50f8.png
img-084e6838-a9f0-4966-8a89-2f512c6b2349.png

Enable Authentication


By default, your website is publicly accessible from anywhere on the Internet. This can blow up your credit card. We need to enable authentication that asks users to login before using the application.

Although the original ChatGPT Next Web project did not have such features, it is extremely easy to add login providers on Azure without writing any code.

Go to Authentication blade, click "Add identity provider"

img-04e21e9a-9eeb-43b6-a754-bed68cb42c1e.png

You can add any of the listed providers. I am using Microsoft for example. 

img-24b79992-90b5-424f-b0ab-45f66444f4d3.png

For Microsoft provider, by default, all accounts in the given Azure AD will have access. To limit accounts to only selected people, see my previous blog post How to Allow Only Selected Users to Access an Application in Azure AD

After completing this step. Users will be asked to login before opening ChatGPT web UI. 

Conclusion


Azure App Service is a wonderful PaaS service. It can run Docker based applications and add individual account login flow to the application without modifing code. All steps are just a few mouse clicks that can be finished in a few minutes.


This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK