Crates.io | chatgpt_api |
lib.rs | chatgpt_api |
version | 0.3.0 |
source | src |
created_at | 2023-03-02 14:32:15.711518 |
updated_at | 2023-03-15 10:04:38.108257 |
description | Use ChatGPT easily from Rust. Or from the command line. |
homepage | |
repository | https://github.com/MrRobb/chatgpt |
max_upload_size | |
id | 798918 |
size | 92,347 |
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.
Add the following to your Cargo.toml
:
[dependencies]
chatgpt_api = "0.1"
The config file contains the authentication credentials. Check out the authentication methods here: https://github.com/mrrobb/chatgpt#authentication-methods.
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.
If you have Rust installed, you can install the CLI from source:
cargo install chatgpt
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_CONFIG
environment variable.
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.
{
"session_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.
{
"access_token": "..."
}
Chatbot
struct