XDYB / chatgptapi_server

协调多个chatgpt账户收发消息,构建ChatGPT3.5 API服务;一个账号没办法同时请求两个问题,但一百个可以啊!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

browser-chatgpt

体验地址:https://xx025.github.io/hhlfx57c50/

Snipaste_2023-03-01_22-59-42.png 这是一个,ChatGPT3.5 API 服务(即在OpenAI网页使用的模型),它允许连接多个ChatGPT账户协同工作,并构建一个对外的API接口服务。

快速开始

在此之前你需要有一个redis数据库,在example.setting.cfg一些基础的配置选项,包含主机地址、端口号、redis数据库等。

  1. 运行web服务

    git clone -b master https://github.com/xx025/browser-chatgptapi.git
    cd browser-chatgptapi
    pip install virtualenv
    virtualenv venv
    venv\Scripts\activate.bat  
    pip install -r requirements.txt
    python run.py

    此时web服务正在允许,他有两个重要的接口

    • ws://localhost:8010/user 供用户连接
    • ws://localhost:8010/server 供chatgpt服务连接

    数据格式示例:

    {
       "msg": "hello, i am user1"
    }   
    {
     "msg": "hello user1, i am  server1"
    }   
  2. 连接chatgpt服务

     import json
     from revChatGPT.V1 import Chatbot
     from ws4py.client.threadedclient import WebSocketClient
     from ws4py.messaging import TextMessage
      
     class CG_Client(WebSocketClient):    
         def received_message(self, resp:TextMessage):
             prompt = json.loads(str(resp)).get('msg', 'hello')
             print(prompt)
             access_token = "you_access_token"
             chatbot = Chatbot(config={"access_token": access_token})
             response = ""
             for data in chatbot.ask(prompt):
                 response = data["message"]
             data = json.dumps({'msg': response})
             self.send(data)    
     
     if __name__ == '__main__':
         ws = None
         try:
             ws = CG_Client('ws://127.0.0.1:8010/server?token=r64XoPjdpVWPpSTrnin1')
             ws.connect()
             ws.run_forever()
         except KeyboardInterrupt:
             ws.close()

    其他

  3. 进行测试

    我写了一个简单的测速页面你可以打开一个或多个http://localhost:8010/ 进行测试,你可以用postman打开一个WebSocket API测速页面进行测式

演示:

演示视频YouTube

image

架构图

架构图.png

最后

代码比较简陋,可完善之处多多,欢迎参与一起开发

git checkout --orphan latest_branch
git add -A
git commit -am "Initial commit"
git branch -D main
git branch -m main

About

协调多个chatgpt账户收发消息,构建ChatGPT3.5 API服务;一个账号没办法同时请求两个问题,但一百个可以啊!


Languages

Language:HTML 75.5%Language:Python 20.6%Language:JavaScript 3.9%