目录

ChatGPT Wrapper

ChatGPT Wrapper is an open-source unofficial Power CLI, Python API and Flask API that lets you interact programmatically with ChatGPT.

安装

必要条件

  • macOS
    brew install moreutils
    
  • Ubuntu
    sudo apt install moreutils
    

创建虚拟环境

mkdir chatgpt-wrapper && cd chatgpt-wrapper

python -m venv env
source ./env/bin/activate

使用 GitHub 安装最新版本

pip install --upgrade pip
pip install git+https://github.com/mmabrouk/chatgpt-wrapper

Playwright 中安装浏览器,默认为 firefox。

playwright install

ChatGPT 安装

以安装模式启动程序。 这将打开一个浏览器窗口。 在浏览器窗口中登录 ChatGPT,然后停止该程序。

chatgpt install
Install mode: Log in to ChatGPT in the browser that pops up, and click
through all the dialogs, etc. Once that is achieved, exit and restart
this program without the 'install' parameter.


    Provide a prompt for ChatGPT, or type /help or ? to list commands.                                                        

1> /quit
GoodBye!

使用

一次性模式

chatgpt hello   
Hello! How can I assist you today?

交互模式

chatgpt 

    Provide a prompt for ChatGPT, or type /help or ? to list commands.                                                        

1> /ask hello

Hello! How can I assist you today?

2> /quit
GoodBye!

Python

from chatgpt_wrapper import ChatGPT

bot = ChatGPT()
response = bot.ask("Hello, world!")
print(response)  # prints the response from chatGPT

参考资料