Coder Social home page Coder Social logo

koishi-openchat-server's Introduction

前提准备

  • 搭建一个可以运行的koshi服务器
  • 拥有一个openai的账号 [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)
  • 拥有一台服务器并拥有python环境(如果不需要在服务器在搭建可以不需要)

一、本地自建server

  • 本地需要一个koishi的服务器

进入到官方插件的地址 @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

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

新建一个Python运行环境 venv

virutalenv venv
souce venv/bin/activate
pip install -r requirments.txt
python chat.py

二、服务器自建server

# 安装依赖
sudo apt update 
sudo apt ugrade 
sudo apt install git -y
pip3 install virtualenv

# 下载项目源码
git clone https://github.com/houko/koishi-openchat-server.git

# 进入项目
cd koishi-openchat-server

# 创建虚拟环境
virtualenv .venv

# 进入虚拟环境
source .venv/bin/activate

# 安装依赖
pip3 install -r requirments.txt

vim chat.py
# 修改第8行代码,把api_key换成自己的
# chatbot = Chatbot(api_key="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")

# 运行服务器
python3 chat.py

koishi-openchat-server's People

Contributors

houko avatar

Watchers

James Cloos 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.