# ChatGPT for Rust [![Crates.io](https://img.shields.io/crates/v/chatgpt_api.svg)](https://crates.io/crates/chatgpt_api) [![Docs.rs](https://docs.rs/chatgpt_api/badge.svg)](https://docs.rs/chatgpt_api) Use ChatGPT easily from Rust. Or from the command line. Based on [acheong08/ChatGPT](https://github.com/acheong08/ChatGPT). All the hard stuff was done by the original project author acheong08, all credit goes to him! > Status: [Not finished](#TODO), 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](#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](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](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](https://chat.openai.com) and log in. Then, go to [https://chat.openai.com/api/auth/session](https://chat.openai.com/api/auth/session) and copy the value of the `accessToken` field. ```json { "access_token": "..." } ``` ## TODO - [ ] Add builder pattern to the `Chatbot` struct - [ ] Better (some?) error handling - [ ] Better formatting for the CLI - [ ] Custom config file path for the CLI - [ ] Test email and password authentication