chatgpt_api

Crates.iochatgpt_api
lib.rschatgpt_api
version0.3.0
sourcesrc
created_at2023-03-02 14:32:15.711518
updated_at2023-03-15 10:04:38.108257
descriptionUse ChatGPT easily from Rust. Or from the command line.
homepage
repositoryhttps://github.com/MrRobb/chatgpt
max_upload_size
id798918
size92,347
Mr.Robb (MrRobb)

documentation

https://docs.rs/chatgpt_api

README

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:

[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.

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:

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.

{
    "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.

{
    "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
Commit count: 0

cargo fmt