GithubHelp home page GithubHelp logo

hqfeijian / chatgptapi_server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xiaroustar/chatgptapi_server

0.0 0.0 0.0 373 KB

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

JavaScript 10.51% Python 52.30% HTML 37.19%

chatgptapi_server's Introduction

browser-chatgptapi

这是一个,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

chatgptapi_server's People

Contributors

xx025 avatar

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.