Home  >  Article  >  Technology peripherals  >  Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

WBOY
WBOYforward
2023-04-15 19:43:011969browse

As a technology blogger, Fengfeng prefers all kinds of tossing. I have previously introduced ChatGPT to connect to WeChat, DingTalk and Knowledge Planet (if you haven’t seen it, you can read the previous article ), when I was looking at open source projects recently, I discovered a ChatGPT Web UI project.

I just haven’t connected ChatGPT to the Web UI before. It’s really good to have this open source project to use. Here are the practical installation steps to share with everyone.

Installation

The official project documentation on Github provides many installation methods, including manual installation, docker deployment, and remote deployment. It is amazing when choosing a deployment method. , at first I thought of just using docker to deploy directly for simplicity, but who would have thought that after deploying on the server, the problem of Connection errored out would always occur after setting the login account and password on the website.

After reading the official issue​, I saw that many people had the same problem. According to the method provided in the issue, this problem was finally solved by modifying the dockerfile. At the same time, in order to modify the titles of some pages, I decided to fork the source code and then deploy it by repackaging the image myself.

Download source code

First we fork the source code warehouse in Github, and then clone our own warehouse, git clone https://github.com/your own github account /chatgpt-web.git,

After the download is completed, we enter the project directory and then install the dependencies. The command is as follows

cd chatgpt-web
pip install -r requirements.txt

We may have some problems during this step. , as shown below

  1. pip​ does not exist: In this case, you need to install the Python environment first, but I won’t introduce it here;
  2. ERROR: No matching distribution found for tiktoken (from -r requirements.txt (line 4)): This is a package that does not have relevant dependencies in its own pip image and needs to be replaced.
pip install <package> -i https://pypi.org/simple
  1. The official provides a list of frequently asked questions. You can Refer to a list of frequently asked questions provided by the official solution to solve the problem.

Normally speaking, all related problems can be solved. It’s amazing that we encountered the second problem here. It was solved by referring to the method of changing the image. However, the problems encountered are different in different environments. You can check it out yourself.

Source code deployment

First of all, let’s try it. Without modifying the source code, use docker to deploy on the server to see what effect it will have. After we download the source code on the server, enter the directory, and then package the image

git clone https://github.com/zhuSilence/chatgpt-web.git
cd chatgpt-web
docker build -t chatgpt-ui:ori .

Then we check the docker image through docker images, as follows

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

Next we run the chatgpt-web container through docker and execute the following command

docker run -d --name chatgpt-ui 
-e my_api_key="填入自己的 open api key" 
-e USERNAME="admin" 
-e PASSWORD="admin" 
-v ~/chatGPThistory:/app/history 
-p 7860:7860 
chatgpt-ui:ori

Then we open the browser and access it directly through ip and port. The effect is as follows. Log in first and enter the above command. The account number and password

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

# can then enter the system. However, when we try to test ChatGPT, we will find an error in the upper right corner, indicating that the link cannot be made.

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

In the official pinned issue, we can see that many friends have also encountered this problem,

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

In the end, the boss analyzed that it was because when the account and password authentication was enabled, the token obtained when accessing directly using IP was incorrect, making it unusable.

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

Modify the source code

After finding the problem, you can solve the problem. In the same issue, someone mentioned that if you want to deploy on the external network, you need to What is modified is the Dockerfile file, in which the CMD command is preceded by the following line

RUN sed -i 's/websocket.cookies.get("access-token")/websocket.cookies.get("access -token-unsecure")/' /root/.local/lib/python3.9/site-packages/gradio/routes.py

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

The reason for adding this One line is because the correct token cannot be obtained when deployed on the server, and the command in this line is to use the sed command to replace the access_token_unsecure in the routes.py script with access_token to obtain the authentication token.

Then let’s modify the Dockerfile, then rebuild a new image, start it again, and see if it can be solved.

通过 vim Dockerfile 命令修改,然后再构建一个新的镜像

vim Dockerfile
docker build -t chatgpt-ui:new .
docker images

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

可以看到,这里我们有两个镜像了,虽然名子一样,但是对应的 TAG 是不一样的,

docker run -d --name chatgpt-ui2 
-e my_api_key="填入自己的 open api key" 
-e USERNAME="admin" 
-e PASSWORD="admin" 
-v ~/chatGPThistory:/app/history 
-p 7861:7860 
chatgpt-ui:new

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

同样进行登录过后,我们会发现这次正常了,可以愉快的进行玩耍了。

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

调戏

首先我们可以在官方的 Prompt 模板中选择一个好玩的,里面包含的模板有很多。

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

比如我们可以让 ChatGPT​ 充当一个 SQL​ 终端,然后帮我们执行 SQL 语句。

Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site

怎么样是不是很神奇?还有很多有趣的模板可以选择,也可以自己设定一个符合自己工作或者学习的 Prompt​ 来进行 AI 的调戏。同时因为我们是基于源码手动进行构建镜像的,可以把一些内容换成自己的,或者自行进行一些二次开发都是可以的。

总结

前面的文章给大家接入了如何接入微信,钉钉以及知识星球,今天的文章教大家如何构建一个属于自己的 ChatGPT​ 平台,对于 ChatGPT 这种划时代的产品,在这么短的时间里面已经风靡全球了,各种互联网公司都投入大模型的研究,更有很多 AI 领域的人都开启了创业之旅,比如王慧文,李开复等。

The above is the detailed content of Based on the open source ChatGPT Web UI project, quickly build your own ChatGPT site. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete