需要安装revchatgpt库和flask库,自行安装
直接上代码。
chat.py
from flask import Flask, request, render_template from revChatGPT.V1 import Chatbot app = Flask(__name__) chatbot = Chatbot(config={ "access_token": "这里是你的access_token" }) @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": prompt = request.form["prompt"] response = "" for data in chatbot.ask(prompt): response = data["message"] return render_template("index.html", response=response) return render_template("index.html") if __name__ == "__main__": app.run(host="0.0.0.0")
templates\index.html
<!doctype html> <html> <head> <title>ChatGPT PLUS 开发示例</title> </head> <body> <h1>ChatGPT PLUS 开发示例:关注我获得更多新资讯</h1> <form method="post"> <input type="text" name="prompt" placeholder="输入问题" required> <button type="submit">发送</button> </form> {% if response %} <p>{{ response }}</p> {% endif %} </body> </html>