liu.yuqiang
commited on
Commit
·
d4e8083
1
Parent(s):
55a7012
Edit application file
Browse files- README.md +11 -360
- api_key.txt +0 -1
README.md
CHANGED
@@ -1,362 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
---
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-

|
14 |
-
|
15 |
-
|
16 |
-
## 重大更新 🎉🎉🎉
|
17 |
-
|
18 |
-
- 像官方ChatGPT那样实时回复
|
19 |
-
- 无限长度对话
|
20 |
-
- 从互联网搜索结果
|
21 |
-
- 改进的保存/加载功能
|
22 |
-
- 从Prompt模板中选择预设
|
23 |
-
- 将大段代码显示在代码块中
|
24 |
-
- 渲染输出中的LaTex公式
|
25 |
-
|
26 |
-
## 目录
|
27 |
-
|[功能](#功能)|[使用技巧](#使用技巧)|[安装方式](#安装方式)|[疑难杂症解决](#疑难杂症解决)|
|
28 |
-
| ---- | ---- | ---- | ---- |
|
29 |
-
|
30 |
-
|
31 |
-
## 功能
|
32 |
-
- [x] 像官方客户端那样支持实时显示回答!
|
33 |
-
- [x] 重试对话,让ChatGPT再回答一次。
|
34 |
-
- [x] 优化Tokens,减少Tokens占用,以支持更长的对话。
|
35 |
-
- [x] 设置System Prompt,有效地设定前置条件
|
36 |
-
- [x] 保存/加载对话历史记录
|
37 |
-
- [x] 在图形界面中添加API key
|
38 |
-
- [x] System Prompt模板功能,从预置的Prompt库中选择System Prompt
|
39 |
-
- [x] 实时显示Tokens用量
|
40 |
-
|
41 |
-
## 使用技巧
|
42 |
-
|
43 |
-
- 使用System Prompt可以很有效地设定前提条件
|
44 |
-
- 对于长对话,可以使用“优化Tokens”按钮减少Tokens占用。
|
45 |
-
- 如果部署到服务器,将程序最后一句改成`demo.launch(server_name="0.0.0.0", server_port=99999)`。其中`99999`是端口号,应该是1000-65535任意可用端口,请自行更改为实际端口号。
|
46 |
-
- 如果需要获取公共链接,将程序最后一句改成`demo.launch(share=True)`。注意程序必须在运行,才能通过公共链接访问
|
47 |
-
- 使用Prompt模板功能时,请先选择模板文件(`.csv`),然后点击载入按钮,然后就可以从下拉菜单中选择想要的prompt了,点击应用填入System Prmpt
|
48 |
-
- 输入框支持换行,按`shift enter`即可
|
49 |
-
- 在Hugging Face上使用时,建议在右上角**复制Space**再使用,这样能大大减少排队时间,App反应也会更加迅速。
|
50 |
-
<img width="300" alt="image" src="https://user-images.githubusercontent.com/51039745/223447310-e098a1f2-0dcf-48d6-bcc5-49472dd7ca0d.png">
|
51 |
-
|
52 |
-
## 安装方式
|
53 |
-
|
54 |
-
### 本地部署
|
55 |
-
|
56 |
-
1. **下载本项目**
|
57 |
-
|
58 |
-
```shell
|
59 |
-
git clone https://github.com/GaiZhenbiao/ChuanhuChatGPT.git
|
60 |
-
cd ChuanhuChatGPT
|
61 |
-
```
|
62 |
-
或者,点击网页右上角的 `Download ZIP`,下载并解压完成后进入文件夹,进入`终端`或`命令提示符`。
|
63 |
-
|
64 |
-
<img width="200" alt="downloadZIP" src="https://user-images.githubusercontent.com/23137268/223696317-b89d2c71-c74d-4c6d-8060-a21406cfb8c8.png">
|
65 |
-
|
66 |
-
2. **填写API密钥**
|
67 |
-
|
68 |
-
以下3种方法任选其一:
|
69 |
-
|
70 |
-
<details><summary>1. 在图形界面中填写你的API密钥</summary>
|
71 |
-
|
72 |
-
这样设置的密钥会在页面刷新后被清除。
|
73 |
-
|
74 |
-
<img width="760" alt="image" src="https://user-images.githubusercontent.com/51039745/222873756-3858bb82-30b9-49bc-9019-36e378ee624d.png"></details>
|
75 |
-
<details><summary>2. 在直接代码中填入你的 OpenAI API 密钥</summary>
|
76 |
-
|
77 |
-
这样设置的密钥会成为默认密钥。在这里还可以选择是否在UI中隐藏密钥输入框。
|
78 |
-
|
79 |
-
<img width="525" alt="image" src="https://user-images.githubusercontent.com/51039745/223440375-d472de4b-aa7f-4eae-9170-6dc2ed9f5480.png"></details>
|
80 |
-
|
81 |
-
<details><summary>3. 在文件中设定默认密钥、用户名密码</summary>
|
82 |
-
|
83 |
-
这样设置的密钥可以在拉取项目更新之后保留。
|
84 |
-
|
85 |
-
在项目文件夹中新建这两个文件:`api_key.txt` 和 `auth.json`。
|
86 |
-
|
87 |
-
在`api_key.txt`中填写你的API-Key,注意不要填写任何无关内容。
|
88 |
-
|
89 |
-
在`auth.json`中填写你的用户名和密码。
|
90 |
-
|
91 |
-
```
|
92 |
-
{
|
93 |
-
"username": "用户名",
|
94 |
-
"password": "密码"
|
95 |
-
}
|
96 |
-
```
|
97 |
-
|
98 |
-
</details>
|
99 |
-
|
100 |
-
3. **安装依赖**
|
101 |
-
|
102 |
-
```shell
|
103 |
-
pip install -r requirements.txt
|
104 |
-
```
|
105 |
-
|
106 |
-
如果报错,试试
|
107 |
-
|
108 |
-
```shell
|
109 |
-
pip3 install -r requirements.txt
|
110 |
-
```
|
111 |
-
|
112 |
-
如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
|
113 |
-
|
114 |
-
如果下载慢,建议[配置清华源](https://mirrors.tuna.tsinghua.edu.cn/help/pypi/),或者科学上网。
|
115 |
-
|
116 |
-
4. **启动**
|
117 |
-
|
118 |
-
```shell
|
119 |
-
python ChuanhuChatbot.py
|
120 |
-
```
|
121 |
-
|
122 |
-
如果报错,试试
|
123 |
-
|
124 |
-
```shell
|
125 |
-
python3 ChuanhuChatbot.py
|
126 |
-
```
|
127 |
-
|
128 |
-
如果还是不行,请先[安装Python](https://www.runoob.com/python/python-install.html)。
|
129 |
-
<br />
|
130 |
-
|
131 |
-
如果一切顺利,现在,你应该已经可以在浏览器地址栏中输入 [`http://localhost:7860`](http://localhost:7860) 查看并使用 ChuanhuChatGPT 了。
|
132 |
-
|
133 |
-
**如果你在安装过程中碰到了问题,请先查看[疑难杂症解决](#疑难杂症解决)部分。**
|
134 |
-
|
135 |
-
<details><summary><h3>或者,使用Docker 运行</h3></summary>
|
136 |
-
|
137 |
-
#### 拉取镜像
|
138 |
-
|
139 |
-
```shell
|
140 |
-
docker pull tuchuanhuhuhu/chuanhuchatgpt:latest
|
141 |
-
```
|
142 |
-
|
143 |
-
#### 运行
|
144 |
-
|
145 |
-
```shell
|
146 |
-
docker run -d --name chatgpt \
|
147 |
-
-e my_api_key="替换成API" \
|
148 |
-
-e USERNAME="替换成用户名" \
|
149 |
-
-e PASSWORD="替换成密码" \
|
150 |
-
-v ~/chatGPThistory:/app/history \
|
151 |
-
-p 7860:7860 \
|
152 |
-
tuchuanhuhuhu/chuanhuchatgpt:latest
|
153 |
-
```
|
154 |
-
|
155 |
-
注:`USERNAME` 和 `PASSWORD` 两行可省略。若省略则不会启用认证。
|
156 |
-
|
157 |
-
#### 查看运行状态
|
158 |
-
```shell
|
159 |
-
docker logs chatgpt
|
160 |
-
```
|
161 |
-
|
162 |
-
#### 也可修改脚本后手动构建镜像
|
163 |
-
|
164 |
-
```shell
|
165 |
-
docker build -t chuanhuchatgpt:latest .
|
166 |
-
```
|
167 |
-
</details>
|
168 |
-
|
169 |
-
|
170 |
-
### 远程部署
|
171 |
-
|
172 |
-
<details><summary>如果需要在公网服务器部署本项目,请阅读本部分</summary>
|
173 |
-
|
174 |
-
### 部署到公网服务器
|
175 |
-
|
176 |
-
将最后一句修改为
|
177 |
-
|
178 |
-
```
|
179 |
-
demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
|
180 |
-
```
|
181 |
-
### 用账号密码保护页面
|
182 |
-
|
183 |
-
将最后一句修改为
|
184 |
-
|
185 |
-
```
|
186 |
-
demo.queue().launch(server_name="0.0.0.0", server_port=7860,auth=("在这里填写用户名", "在这里填写密码")) # 可设置用户名与密码
|
187 |
-
```
|
188 |
-
|
189 |
-
### 配置 Nginx 反向代理
|
190 |
-
|
191 |
-
注意:配置反向代理不是必须的。如果需要使用域名,则需要配置 Nginx 反向代理。
|
192 |
-
|
193 |
-
又及:目前配置认证后,Nginx 必须配置 SSL,否则会出现 [Cookie 不匹配问题](https://github.com/GaiZhenbiao/ChuanhuChatGPT/issues/89)。
|
194 |
-
|
195 |
-
添加独立配置文件:
|
196 |
-
```nginx
|
197 |
-
server {
|
198 |
-
listen 80;
|
199 |
-
server_name /域名/; # 请填入你设定的域名
|
200 |
-
access_log off;
|
201 |
-
error_log off;
|
202 |
-
location / {
|
203 |
-
proxy_pass http://127.0.0.1:7860; # 注意端口号
|
204 |
-
proxy_redirect off;
|
205 |
-
proxy_set_header Host $host;
|
206 |
-
proxy_set_header X-Real-IP $remote_addr;
|
207 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
208 |
-
proxy_set_header Upgrade $http_upgrade; # Websocket配置
|
209 |
-
proxy_set_header Connection $connection_upgrade; #Websocket配置
|
210 |
-
proxy_max_temp_file_size 0;
|
211 |
-
client_max_body_size 10m;
|
212 |
-
client_body_buffer_size 128k;
|
213 |
-
proxy_connect_timeout 90;
|
214 |
-
proxy_send_timeout 90;
|
215 |
-
proxy_read_timeout 90;
|
216 |
-
proxy_buffer_size 4k;
|
217 |
-
proxy_buffers 4 32k;
|
218 |
-
proxy_busy_buffers_size 64k;
|
219 |
-
proxy_temp_file_write_size 64k;
|
220 |
-
}
|
221 |
-
}
|
222 |
-
```
|
223 |
-
|
224 |
-
修改`nginx.conf`配置文件(通常在`/etc/nginx/nginx.conf`),向http部分添加如下配置:
|
225 |
-
(这一步是为了配置websocket连接,如之前配置过可忽略)
|
226 |
-
```nginx
|
227 |
-
map $http_upgrade $connection_upgrade {
|
228 |
-
default upgrade;
|
229 |
-
'' close;
|
230 |
-
}
|
231 |
-
```
|
232 |
-
|
233 |
-
为了同时配置域名访问和身份认证,需要配置SSL的证书,可以参考[这篇博客](https://www.gzblog.tech/2020/12/25/how-to-config-hexo/#%E9%85%8D%E7%BD%AEHTTPS)一键配置
|
234 |
-
|
235 |
-
</details>
|
236 |
-
|
237 |
-
## 疑难杂症解决
|
238 |
-
|
239 |
-
首先,请尝试拉取本项目的最新更改,使用最新的代码重试。
|
240 |
-
|
241 |
-
点击网页上的 `Download ZIP` 下载最新代码,或
|
242 |
-
```shell
|
243 |
-
git pull https://github.com/GaiZhenbiao/ChuanhuChatGPT.git main -f
|
244 |
-
```
|
245 |
-
|
246 |
-
如果还有问题,可以再尝试重装 gradio:
|
247 |
-
|
248 |
-
```
|
249 |
-
pip install gradio --upgrade --force-reinstall
|
250 |
-
```
|
251 |
-
|
252 |
-
很多时候,这样就可以解决问题。
|
253 |
-
|
254 |
-
<details><summary><h3><code>No module named '_bz2'</code></h3></summary>
|
255 |
-
|
256 |
-
> 部署在CentOS7.6,Python3.11.0上,最后报错ModuleNotFoundError: No module named '_bz2'
|
257 |
-
|
258 |
-
安装python前先下载 `bzip` 编译环境
|
259 |
-
|
260 |
-
```
|
261 |
-
sudo yum install bzip2-devel
|
262 |
-
```
|
263 |
-
</details>
|
264 |
-
|
265 |
-
<details><summary><h3><code>openai.error.APIConnectionError</code></h3></summary>
|
266 |
-
|
267 |
-
> 如果有人也出现了`openai.error.APIConnectionError`提示的报错,那可能是`urllib3`的版本导致的。`urllib3`版本大于`1.25.11`,就会出现这个问题。
|
268 |
-
>
|
269 |
-
> 解决方案是卸载`urllib3`然后重装至`1.25.11`版本再重新运行一遍就可以
|
270 |
-
|
271 |
-
参见:[#5](https://github.com/GaiZhenbiao/ChuanhuChatGPT/issues/5)
|
272 |
-
|
273 |
-
在终端或命令提示符中卸载`urllib3`
|
274 |
-
|
275 |
-
```
|
276 |
-
pip uninstall urllib3
|
277 |
-
```
|
278 |
-
|
279 |
-
然后,通过使用指定版本号的`pip install`命令来安装所需的版本:
|
280 |
-
|
281 |
-
```
|
282 |
-
pip install urllib3==1.25.11
|
283 |
-
```
|
284 |
-
|
285 |
-
参考自:
|
286 |
-
[解决OpenAI API 挂了代理还是连接不上的问题](https://zhuanlan.zhihu.com/p/611080662)
|
287 |
-
</details>
|
288 |
-
|
289 |
-
<details><summary><h3>在 Python 文件里 设定 API Key 之后验证失败</h3></summary>
|
290 |
-
|
291 |
-
> 在ChuanhuChatbot.py中设置APIkey后验证出错,提示“发生了未知错误Orz”
|
292 |
-
|
293 |
-
参见:[#26](https://github.com/GaiZhenbiao/ChuanhuChatGPT/issues/26)
|
294 |
-
</details>
|
295 |
-
|
296 |
-
<details><summary><h3>一直等待/SSL Error</h3></summary>
|
297 |
-
|
298 |
-
> 更新脚本文件后,SSLError [#49](https://github.com/GaiZhenbiao/ChuanhuChatGPT/issues/49)
|
299 |
-
>
|
300 |
-
> 跑起来之后,输入问题好像就没反应了,也没报错 [#25](https://github.com/GaiZhenbiao/ChuanhuChatGPT/issues/25)
|
301 |
-
>
|
302 |
-
> ```
|
303 |
-
> requests.exceptions.SSLError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))
|
304 |
-
> ```
|
305 |
-
|
306 |
-
请将`openai.com`加入你使用的代理App的代理规则。注意不要将`127.0.0.1`加入代理,否则会有下一个错误。
|
307 |
-
|
308 |
-
例如,在Clash配置文件中,加入:
|
309 |
-
|
310 |
-
```
|
311 |
-
rule-providers:
|
312 |
-
private:
|
313 |
-
type: http
|
314 |
-
behavior: domain
|
315 |
-
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
|
316 |
-
path: ./ruleset/ads.yaml
|
317 |
-
interval: 86400
|
318 |
-
|
319 |
-
rules:
|
320 |
-
- RULE-SET,private,DIRECT
|
321 |
-
- DOMAIN-SUFFIX,openai.com,你的代理规则
|
322 |
-
```
|
323 |
-
|
324 |
-
Surge:
|
325 |
-
|
326 |
-
```
|
327 |
-
[Rule]
|
328 |
-
DOMAIN-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/surge-rules@release/private.txt,DIRECT
|
329 |
-
DOMAIN-SUFFIX,openai.com,你的代理规则
|
330 |
-
```
|
331 |
-
</details>
|
332 |
-
|
333 |
-
<details><summary><h3>网页提示错误 Something went wrong</h3></summary>
|
334 |
-
|
335 |
-
> ```
|
336 |
-
> Something went wrong
|
337 |
-
> Expecting value: 1ine 1 column 1 (char o)
|
338 |
-
> ```
|
339 |
-
|
340 |
-
出现这个错误的原因是`127.0.0.1`被代理了,导致网页无法和后端通信。请设置代理软件,将`127.0.0.1`加入直连。
|
341 |
-
</details>
|
342 |
-
|
343 |
-
<details><summary><h3><code>No matching distribution found for openai>=0.27.0</code></h3></summary>
|
344 |
-
|
345 |
-
`openai`这个依赖已经被移除了。请尝试下载最新版脚本。
|
346 |
-
</details>
|
347 |
-
|
348 |
-
## Starchart
|
349 |
-
|
350 |
-
[](https://star-history.com/#GaiZhenbiao/ChuanhuChatGPT&Date)
|
351 |
-
|
352 |
-
## Contributors
|
353 |
-
|
354 |
-
<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/graphs/contributors">
|
355 |
-
<img src="https://contrib.rocks/image?repo=GaiZhenbiao/ChuanhuChatGPT" />
|
356 |
-
</a>
|
357 |
-
|
358 |
-
## 捐款
|
359 |
-
|
360 |
-
🐯请作者喝可乐~
|
361 |
-
|
362 |
-
<img width="350" alt="image" src="https://user-images.githubusercontent.com/51039745/223626874-f471e5f5-8a06-43d5-aa31-9d2575b6f631.JPG">
|
|
|
1 |
+
---
|
2 |
+
title: Chat
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.21.0
|
8 |
+
app_file: ChuanhuChatbot.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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