Code Monkey home page Code Monkey logo

chatgpt-html's Introduction

chatgpt-html

使用acheong08对接官方ChatGPT接口,实现简单HTML网页版在线聊天

该版本基于ChatGPT网页端代理开发(免费),想使用ChatGPT API KEY(付费)的请访问chatgpt-web

注意

使用该项目的前提是你的服务器IP没有被BAN,由于我自己的服务器IP已BAN,无法测试项目是否可用,请自行尝试

特性

  • 文件结构简单,主要面向小白用户
  • 功能不多,但核心的连续对话、多用户会话隔离、markdown格式输出都具备

部署

使用Docker Compose

以下所有文件放同一目录

  • 新建config.json文件,粘贴以下代码并保存
{
        "__comment01__": "邮箱、session_token和access_token三选一",
        "__comment02__": "邮箱认证(暂仅支持普通方式注册的账号,不支持谷歌或微软快捷登录)",
        "email": "",
        "password": "",
        "__comment03__": "session_token认证(不受账号注册方式影响)",
        "session_token": "",
        "__comment04__": "access_token认证(不受账号注册方式影响)",
        "access_token": "",
        
        "__comment05__": "以下为选填字段",
        "__comment06__": "通过代理连接代理端(作者服务器被墙过,代理好像只能用无密码认证的socks5或者http,请自行测试)",
        "proxy": "",
        "__comment07__": "使用付费openai账号(官方称速度更快,无频率限制,将false改为true)",
        "paid": false
}
  • session_token获取方法(随时过期)
  1. Go to https://chat.openai.com/chat and open the developer tools by F12.
  2. Find the __Secure-next-auth.session-token cookie in Application > Storage > Cookies > https://chat.openai.com.
  3. Copy the value in the Cookie Value field.
  • access_token获取方法(据说可以持续2周不过期)

登录ChatGPT官方网页版后再打开https://chat.openai.com/api/auth/session

  • 新建docker-compose.yml配置文件,粘贴以下内容并保存
services:
  chatgpt:
    image: sheepgreen/chatgpt-html
    container_name: htmchat
#    environment:
#      - CHATGPT_BASE_URL=你的代理服务端地址(不填默认使用作者服务器,目前偶尔会不可用)
    volumes:
      - ./config.json:/chatgpt-html/config.json
#      - ./chat.html:/chatgpt-html/templates/chat.html #默认内置我的UI,如需替换自用网页请取消注释
    ports:
      - "9999:8088" #8088为容器内端口,不可更换;9999为外部端口,可自行更换
    restart: always
  • 输入docker-compose up -d即启动成功

注意事项

  • 访问地址为http://ip:port
  • 修改chat.html文件后,需要docker restart htmchat才能生效

其他相关

chatgpt-html's People

Contributors

ritajie avatar slippersheepig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chatgpt-html's Issues

docker运行以后 [CRITICAL] WORKER TIMEOUT (pid:11)

[2023-02-12 12:55:47 +0000] [8] [INFO] Starting gunicorn 20.1.0
[2023-02-12 12:55:47 +0000] [8] [INFO] Listening at: http://0.0.0.0:80 (8)
[2023-02-12 12:55:47 +0000] [8] [INFO] Using worker: gevent
[2023-02-12 12:55:47 +0000] [11] [INFO] Booting worker with pid: 11
[2023-02-12 12:59:08 +0000] [8] [CRITICAL] WORKER TIMEOUT (pid:11)
[2023-02-12 12:59:08 +0000] [11] [INFO] Worker exiting (pid: 11)
Spawning browser...
Browser spawned.
[2023-02-12 12:59:08 +0000] [275] [INFO] Booting worker with pid: 275
服务器能够正常访问openai的网站,请大佬解惑

服务器500

我本地搭建,api正常使用,为啥他一直显示500错误,可以正常科学上网

网页无响应

按照readme的步骤来进行配置,以下是我docker-compose.yml和config.json的相关配置,在config.json我是用邮箱账号登录的。
[
2
3

](url)
最后docker命令也启用了,结果提问后却是未响应,如下图
1
@slippersheepig

用腾讯云的海外服务器搭建了main分支里的网址,但在本地和服务器里都打不通,可能是什么原因?

首先把防火墙的端口全部打开了,然后在本地git了main分支里的内容并上传到服务器里,cd chatgpt-html-main后把需要的文件都创建好了,只修改了端口号,运行docker-compose up -d后由于编码错误,我把main.py中的中文替换成了英文(是否和这步有关?),最后成功运行没有报错,但ip:端口不论在本地还是服务器上都time out,可能是什么原因呢?

docker状态一直重启 看log有个keyerror 然后就关闭了 怎么解决

File "/usr/local/lib/python3.11/site-packages/OpenAIAuth/OpenAIAuth.py", line 352, in get_access_token\n","stream":"stderr","time":"2023-02-17T03:25:00.121560866Z"}
{"log":" self.access_token = response.json()["accessToken"]\n","stream":"stderr","time":"2023-02-17T03:25:00.121564987Z"}
{"log":" ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^\n","stream":"stderr","time":"2023-02-17T03:25:00.121569417Z"}
{"log":"KeyError: 'accessToken'\n","stream":"stderr","time":"2023-02-17T03:25:00.121573633Z"}

docker服务起不来

把项目上传到服务器后,执行docker-compose命令后报错,信息如图片:
MVIMG_20230218_142938

找不到config.json?

我想不用docker直接運行,main.py 找不到 config.json?

這個文件在哪裡呢?

OpenAIAuth.Error

Docker logs:
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 76, in begin
self.__part_one(token=csrf_token)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 117, in __part_one
self.__part_two(url=url)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 146, in __part_two
self.__part_three(state=state)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 170, in __part_three
self.__part_four(state=state)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 208, in __part_four
self.__part_five(state=state)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 245, in __part_five
self.__part_six(old_state=state, new_state=new_state)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 271, in __part_six
self.__part_seven(redirect_url=redirect_url, previous_url=url)
File "/home/appuser/.local/lib/python3.11/site-packages/OpenAIAuth.py", line 300, in __part_seven
raise Error(
OpenAIAuth.Error
[2023-03-03 14:45:15 +0000] [7] [INFO] Worker exiting (pid: 7)
[2023-03-03 14:45:16 +0000] [1] [INFO] Shutting down: Master
[2023-03-03 14:45:16 +0000] [1] [INFO] Reason: Worker failed to boot.
[2023-03-03 14:45:23 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-03-03 14:45:23 +0000] [1] [INFO] Listening at: http://0.0.0.0:8088 (1)
[2023-03-03 14:45:23 +0000] [1] [INFO] Using worker: gevent
[2023-03-03 14:45:23 +0000] [7] [INFO] Booting worker with pid: 7
[2023-03-03 14:45:31 +0000] [7] [ERROR] Exception in worker process

config.json:
{
"email": "填写你的OpenAI账号(即邮箱)",
"password": "填写你的OpenAI密码"
}

出现chrome不可用的错误。Message: unknown error: cannot connect to chrome at 127.0.0.1:50131 from chrome not reachable

我启动main的镜像,出现了以下错误,
(我进入镜像发现chrome是安装好的,不知道哪里出错了 )

[2023-02-21 03:34:01 +0000] [118] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 146, in init_process
super().init_process()
File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/chatgpt-html/main.py", line 12, in
chatbot = Chatbot(config)
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/revChatGPT/Unofficial.py", line 72, in init
self.__email_login()
File "/usr/local/lib/python3.11/site-packages/revChatGPT/Unofficial.py", line 481, in __email_login
driver = uc.Chrome(
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/undetected_chromedriver/init.py", line 441, in init
super(Chrome, self).init(
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 80, in init
super().init(
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 104, in init
super().init(
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 286, in init
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.11/site-packages/undetected_chromedriver/init.py", line 704, in start_session
super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:50131
from chrome not reachable
Stacktrace:
#0 0x55d9dc042d93
#1 0x55d9dbe1115d
#2 0x55d9dbdffa2b
#3 0x55d9dbe3dc63
#4 0x55d9dbe352fc
#5 0x55d9dbe7a4f4
#6 0x55d9dbe71353
#7 0x55d9dbe40e40
#8 0x55d9dbe42038
#9 0x55d9dc0968be
#10 0x55d9dc09a8f0
#11 0x55d9dc07af90
#12 0x55d9dc09bb7d
#13 0x55d9dc06c578
#14 0x55d9dc0c0348
#15 0x55d9dc0c04d6
#16 0x55d9dc0da341
#17 0x7f81c064fea7 start_thread

CHATGPT_BASE_URL是怎么样一个格式

CHATGPT_BASE_URL=你的代理服务端地址(不填默认使用作者服务器,目前偶尔会不可用)
这个地方是可以自己部署一个
ChatGPT-Proxy 这个项目,然后填写自己的服务器地址吗?
如果是 那变量是怎么样一个格式?

macos 操作执行不成功

➜ chatgpt-html git:(proxy) ✗ sudo docker-compose up
htmchat is up-to-date
Attaching to htmchat
htmchat | [2023-02-25 13:20:18 +0000] [1] [INFO] Starting gunicorn 20.1.0
htmchat | [2023-02-25 13:20:18 +0000] [1] [INFO] Listening at: http://0.0.0.0:8088 (1)
htmchat | [2023-02-25 13:20:18 +0000] [1] [INFO] Using worker: gevent
htmchat | [2023-02-25 13:20:18 +0000] [7] [INFO] Booting worker with pid: 7
htmchat | [2023-02-25 13:20:23 +0000] [7] [ERROR] Exception in worker process
htmchat | Traceback (most recent call last):
htmchat | File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
htmchat | worker.init_process()
htmchat | File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 146, in init_process
htmchat | super().init_process()
htmchat | File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
htmchat | self.load_wsgi()
htmchat | File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
htmchat | self.wsgi = self.app.wsgi()

建议改进2个地方

1.问题请求接口改为post。get方法有字数限制,贴段长代码就报错了。
2.聊天会话没有做隔离,多人使用对话上下文会干扰。没有会话重置按钮。

worker fail to boot

装在了vps上,网页不通。 用portainer观察,container貌似在运行,但log说:

json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
[2023-03-11 14:40:22 +0000] [6] [INFO] Worker exiting (pid: 6)
[2023-03-11 14:40:23 +0000] [1] [INFO] Shutting down: Master
[2023-03-11 14:40:23 +0000] [1] [INFO] Reason: Worker failed to boot.
[2023-03-11 14:41:25 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-03-11 14:41:25 +0000] [1] [INFO] Listening at: http://0.0.0.0:8088 (1)
[2023-03-11 14:41:25 +0000] [1] [INFO] Using worker: gevent
[2023-03-11 14:41:25 +0000] [6] [INFO] Booting worker with pid: 6
[2023-03-11 14:41:26 +0000] [6] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 146, in init_process
super().init_process()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/chatgpt-html/main.py", line 8, in
with open("config.json", "r") as f: config = json.load(f)
^^^^^^^^^^^^
File "/usr/lib/python3.11/json/init.py", line 293, in load
return loads(fp.read(),
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/init.py", line 335, in loads
raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
[2023-03-11 14:41:26 +0000] [6] [INFO] Worker exiting (pid: 6)
[2023-03-11 14:41:27 +0000] [1] [INFO] Shutting down: Master
[2023-03-11 14:41:27 +0000] [1] [INFO] Reason: Worker failed to boot.
[2023-03-11 14:42:29 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-03-11 14:42:29 +0000] [1] [INFO] Listening at: http://0.0.0.0:8088 (1)
[2023-03-11 14:42:29 +0000] [1] [INFO] Using worker: gevent
[2023-03-11 14:42:29 +0000] [6] [INFO] Booting worker with pid: 6
[2023-03-11 14:42:31 +0000] [6] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 146, in init_process
super().init_process()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.local/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/chatgpt-html/main.py", line 8, in
with open("config.json", "r") as f: config = json.load(f)
^^^^^^^^^^^^
File "/usr/lib/python3.11/json/init.py", line 293, in load
return loads(fp.read(),
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/init.py", line 335, in loads
raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
[2023-03-11 14:42:31 +0000] [6] [INFO] Worker exiting (pid: 6)
[2023-03-11 14:42:31 +0000] [1] [INFO] Shutting down: Master
[2023-03-11 14:42:31 +0000] [1] [INFO] Reason: Worker failed to boot.

HTTPSConnectionPool(host='chatgpt.duti.tech', port=443): Max retries exceeded with url: /api/conversation (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe837958150>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

提问后返回异常
HTTPSConnectionPool(host='chatgpt.duti.tech', port=443): Max retries exceeded with url: /api/conversation (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe837958150>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

can't start new thread

本地搭建的一切正常,能够正常响应
阿里云服务器上搭建的出现报错:can't start new thread
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.