GithubHelp home page GithubHelp logo

damxin / free-chatgpt-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mufeng510/free-chatgpt-api

0.0 0.0 0.0 22.02 MB

基于pandora的ChatGPT API,实现了pool token的自动更新

License: MIT License

free-chatgpt-api's Introduction

基于pandora的ChatGPT API

说明

感谢pandora项目,这一次真正实现了ChatGPT自由。本项目主要实现了根据账号密码自动获取accessToken并更新至pool-token。初始脚本来源于旧的pandora,该库被删除,无法添加链接,这个脚本是我进行修改过后的,使用更方便。本人也是小白一枚,欢迎大家一起补充完善。

2023/12/11 重写了脚本,不再需要Python环境,基于PandoraNext 0.5.0

如果对您有帮助,请给一个免费的star,谢谢!

写在前面

我们的目标是获得一个 ChatGPT API Key,通常是在使用ChatGPT的衍生项目时使用,比如ChatGPT-Next-Webgpt_academic等。这些项目需要我们提供一个 API Key 及其对应的 APIUrl

通过使用本项目的脚本,我们将获得一个 pk-xxxxxxx 格式的api keyAPIUrl则为你部署的PandoraNext地址

大致流程

准备账号密码 => 获取 Access Token => 获取 Share Token => 获取 Pool Token

Pool Token 就是我们最后需要的 api key

简单说明

Access Token是 OpenAI 官方的用户鉴权信息,相当于用户的唯一标识了,直接使用Access Token和使用官方key一样会扣额度,Access Token有效期是14天,所以我们至少要14天运行一次脚本。

Share TokenPool Token 均是由 pandora 作者提供的服务,与官方无关。Share Token可以实现多人共享一个账号,可以进行会话隔离,不会扣除额度,实现了ChatGPT自由。但是Share Token依旧存在 1 个会话的限制,所以作者提供了 Pool Token,使用由最多 100Share Token组合的 Pool Token 时会自动轮转,实现了多人同时会话。

更多信息可以查看pandora文档

文件说明

demo目录下存放了各环境的示例,本项目是通过scripts下的文件实现功能的。

  • run_job.bat windows执行脚本的批处理脚本
  • add_auto_run_job.bat 添加定时任务的批处理脚本
  • update_pool_token.* 实现功能的脚本。
  • credentials.txt 存储账号、密码
  • pool_token.txt 存储 Pool Token

使用方法

部署PandoraNext

首先你需要参考PandoraNext文档进行部署,本项目的脚本无需与PandoraNext在同一位置。如果你怕出问题,就按照demo一样,将本项目的scripts文件夹放在PandoraNext目录下。

部署PandoraNext时,你至少应配置config.json中的 bind,license_idproxy_api_prefix

示例
{
    "bind": "0.0.0.0:8181",
    "license_id": "xxxxxxxxxxx",
    "proxy_api_prefix": "qqrr123123",
}

我们在使用 api key 时需要将反代url设置为http(s)://<bind>/<proxy_api_prefix>

如: http://127.0.0.1:8181/qqrr123123

自动更新pool token脚本

  1. 下载scripts到你本地

  2. 打开update_pool_token文件,修改$api_urlhttp(s)://<bind>/<proxy_api_prefix>

  3. 新建credentials.txt并设置内容为账号密码,一行一个,账号密码用逗号分隔

  1. 新建pool_token.txt并设置内容为你的pool tohen (可选,没有会自动生成)
pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

pool tohen设置一次后就不会再变了,以后添加修改账号密码只需要执行一次脚本就行了。

  1. windows执行run_job.bat 即可,linux 执行bash update_pool_token.sh,如果缺少权限先执行chmod +x update_pool_token.sh。 pool tohen最后会保存到pool_token.txt
python额外要做的(在上述步骤之前)
  1. 安装python环境

方法一:下载python安装并设置环境变量。

方法二:使用miniconda

  • 在终端中执行:
# 使用scoop安装miniconda3 (没有scoop请手动安装miniconda)
scoop install miniconda3
# 创建pandora专用的环境
conda create -n pool python=3.10
conda init bash
conda activate pool
  • 打开run_job.bat,在python update_pool_token.py之前添加call conda activate pool conda
  1. 安装依赖
pip install pandora-chatgpt

在其他项目中使用 pool token

OPENAI_API_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
BASE_URL: 'http(s)://<bind>/<proxy_api_prefix>'
API_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
CUSTOM_API_KEY_PATTERN : 'pk-[a-zA-Z0-9-]+$$'
API_URL_REDIRECT : '{"https://api.openai.com/v1/chat/completions": "http(s)://<bind>/<proxy_api_prefix>/v1/chat/completions"}'

定时执行

windows:

运行add_auto_run_job.bat,默认每周二执行,想修改可以发给GPT说明你的需求进行改,添加好后可以运行一次试试有没有问题。

测试

linux:

执行bash add_auto_run_job.sh,每隔7天执行一次,需要删除可执行 bash delete_auto_run_job.sh。可在 crontab -e 查看

共享站

PandoraNext提供了一个功能等同chat-shared3.zhile.io的共享站,如果你需要保存access_token以供共享站使用,需要做以下修改

  1. 将本项目脚本放置PandoraNext的子目录下,如本项目demo一样

  2. 打开update_pool_token文件,取消 Run 方法中的 Save-Tokens 的注释

  3. 运行脚本

free-chatgpt-api's People

Contributors

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