ChatGPT for Rust

Crates.io Docs.rs

Use ChatGPT easily from Rust. Or from the command line.

Based on acheong08/ChatGPT. All the hard stuff was done by the original project author acheong08, all credit goes to him!

Status: Not finished, but usable.

Library

Installation

Add the following to your Cargo.toml:

toml [dependencies] chatgpt_api = "0.1"

Usage

The config file contains the authentication credentials. Check out the authentication methods here: https://github.com/mrrobb/chatgpt#authentication-methods.

rust let config = Config::from_file(&config_file); let mut bot = Chatbot::new(config, None, None).await; let response = bot.ask("Hello, world!", None, None, None).await;

Note: Check out the examples for more.

CLI

Installation

From source (Recommended)

If you have Rust installed, you can install the CLI from source:

bash cargo install chatgpt

Usage

``` Usage: chatgpt [OPTIONS]

Options: -v, --verbose Sets the level of verbosity -h, --help Print help -V, --version Print version ```

By default, the CLI will look for a config file in ~/.config/chatgpt/config.json. You can specify a different path with the CHATGPT_CONFIG environment variable.

Authentication methods

Session token (Recommended)

Go to https://chat.openai.com and log in. Then, open the developer tools and go to the Application tab. In the Storage section, click on Cookies and copy the value of the __Secure-next-auth.session-token cookie.

json { "session_token": "..." }

Access token

Go to https://chat.openai.com and log in. Then, go to https://chat.openai.com/api/auth/session and copy the value of the accessToken field.

json { "access_token": "..." }

TODO