ChatGPT for Rust
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:
[]
= "0.1"
Usage
The config file contains the authentication credentials. Check out the authentication methods here: https://github.com/mrrobb/chatgpt#authentication-methods.
let config = from_file;
let mut bot = new.await;
let response = bot.ask.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:
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 theCHATGPT_CONFIGenvironment 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.
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.
TODO
- Add builder pattern to the
Chatbotstruct - Better (some?) error handling
- Better formatting for the CLI
- Custom config file path for the CLI
- Test email and password authentication