Coder Social home page Coder Social logo

free-chatgpt-api's Introduction

基于pandora的ChatGPT API

说明

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

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

写在前面

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

通过使用本项目的脚本,我们将获得一个 pk-xxxxxxx 格式的api keyBaseUrl则为https://ai.fakeopen.com

大致流程

准备账号密码 => 获取 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 时会自动轮转,实现了多人同时会话。

因此,我们在使用 api key 时需要将反代url设置为https://ai.fakeopen.com

更多信息可以查看pandora文档

文件说明

  • run_job.bat windows执行脚本的批处理脚本
  • auto_pool_token.py 实现功能的脚本。
  • credentials.txt 存储账号、密码
  • tokens.txt 存储 Access Token
  • share_tokens.txt 存储 Share Token
  • pool_token.txt 存储 Pool Token

使用方法

  1. 安装python环境

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

方法二:使用miniconda

  • 在终端中执行:
# 使用scoop安装miniconda3 (没有scoop请手动安装miniconda)
scoop install miniconda3
# 创建pandora专用的环境
conda create -n pool python=3.10
conda init pool
conda activate pool
  • 打开run_job.bat,在python auto_pool_token.py之前添加call conda activate pool conda
  1. 安装依赖
pip install pandora-chatgpt
  1. 新建credentials.txt并设置内容为账号密码,一行一个,账号密码用逗号分隔
  1. 新建pool_token.txt并设置内容为你的pool tohen (可选,没有会自动生成)
pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  1. 运行脚本

windows:

执行run_job.bat, pool tohen最后会保存到pool_token.txt

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

在其他项目中使用 pool token

ChatGPT-Next-Web

OPENAI_API_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
BASE_URL: 'https://ai.fakeopen.com'

gpt_academic

API_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
CUSTOM_API_KEY_PATTERN : 'pk-[a-zA-Z0-9-]+$$'
API_URL_REDIRECT : '{"https://api.openai.com/v1/chat/completions": "https://ai.fakeopen.com/v1/chat/completions"}'

定时执行

windows:

  1. 打开任务计划程序, 创建任务。

创建计划任务

  1. 设置触发器,根据你的需求添加即可。

设置触发器

  1. 操作选择执行脚本:run_job.bat

操作

  1. 其他的设置看自己需求,添加好后可以运行一次试试有没有问题。

测试

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.