Git Product home page Git Product logo

chatrapper's Introduction

ChatGPT API (W)rapper

visitors GitHub

把网页版 ChatGPT 封装为一个简单的 API,以便在代码中使用。

Installation

pip3 install git+https://github.com/ultrasev/chatrapper.git

Usage

环境变量中设置 TOKEN,然后调用 chat 函数即可。

export TOKEN="eyJhbGci..."

在代码中使用 Rapper:

import os
from chatrapper import Rapper
token = os.environ.get("TOKEN")
rapper = Rapper(
    access_token=token
    model="text-davinci-002-render-sha"
)
rapper("鲁迅为什么打周树人?")

或者有异步需求的话,可以使用 AsyncRapper。这种情况下,最好有多个账号支持,单账号下,同一时间只支持一轮对话。

import os
import asyncio
from chatrapper import AsyncRapper

token = os.environ.get("TOKEN")
rapper = AsyncRapper(
    access_token=token
    model="text-davinci-002-render-sha"
)
async def main():
    print(await rapper("鲁迅为什么打周树人?"))

asyncio.run(main())

Demo:

Notes

  • 一定要保护好自己的 token,不要泄露给他人。
  • 合理使用 API,调用频率不宜过高,树大易招风,避免触发风控。

chatrapper's People

Contributors

ultrasev 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.