建议跳转到B站查看4K画质视频

https://www.bilibili.com/video/BV1PT41197AK/

注意事项

fastapi~=0.89.1
pydantic~=1.10.2
revChatGPT~=1.1.4
uvicorn~=0.20.0

前提准备

一、本地自建server

进入到官方插件的地址 @42

https://github.com/MirrorCY/openchat

在我们的项目中新建一个server目录,然后新建一个 chat.py文件 ,再新建一个 requirements.txt

# chat.py
from revChatGPT.Official import Chatbot
from fastapi import FastAPI
import uvicorn
from pydantic import BaseModel

port = 8006
app = FastAPI()
chatbot = Chatbot(api_key="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")

# 只需填入你的 openai api_key 即可。一键直达 <https://platform.openai.com/account/api-keys>
# 不再需要 2captcha 密钥
# 按照 <https://github.com/acheong08/ChatGPT> 的说法是完全免费的,但未经证实

class ChatRequest(BaseModel):
  prompt: str

@app.get("/ping")
def ping():
  return {"message": "pong"}

@app.post("/chat")
def chatGPT(request: ChatRequest):
  prompt = request.prompt
  print(prompt)
  if prompt == "__clear__":
    chatbot.reset()
    return {"message": "OK"}
  answer = chatbot.ask(prompt)["choices"][0]["text"]
  print(answer)
  return {"message": answer}

if __name__ == "__main__":
  uvicorn.run(app, host="0.0.0.0", port=port)

requriements.txt

revChatGPT不要用原来的1.0.2,要用最新的1.1.4