let matches = Command::new("ChatGPT CLI") .author("lg.json@gmail.com") .version("1.0.0") .about( "x\n ChatGPT CLI Create by zhulg (lg.json@gmail.com) | 1.You just need to input your api key, the cli version V0.1.1 | | 2.No need access internet with VPN, and just enjoy it. | | 3.If you want to use it in China, you can use my api key. | | |-------------------------------------------------------------------|", ) .arg( Arg::new("DomainName") .action(ArgAction::Set) .short('d') .long("Domain") .default_value("api.openai.com") .help("Sets the API Domain name."), )
支持自定义API域名和API密钥,支持从命令行参数或环境变量中设置密钥
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn read_api_key() -> String { // If the OPENAI_API_KEY environment variable is not set, // ask the user to input the API key and save it to the // environment variables for future use. let api_key = env::var("OPENAI_API_KEY").unwrap_or_else(|_| { console::set_colors_enabled(true); let prompt_style = Style::new().yellow(); let api_key: String = Input::new() .with_prompt(prompt_style.apply_to("Input your API key").to_string()) .interact_text() .unwrap(); env::set_var("OPENAI_API_KEY", &api_key); api_key }); api_key }
ChatGPT CLI Create by zhulg (lg.json@gmail.com) | 1.You just need to input your api key, the cli version | | 2.No need access internet with VPN, and just enjoy it. | | 3.If you want to use it in China, you can use my api key. | | --------------------------------------------------------- |
Usage: chatgpt_rust [OPTIONS]
Options: -d, --Domain <DomainName> Sets the API Domain name. [default: api.openai.com] -k, --key <APIKey> Sets the API key. If not provided, the cli will ask for it, You can also set the OPENAI_API_KEY environment variable. [default: ] -t, --tokens <max_tokens> sets the max_tokens, default is 1000 [default: 1000] -h, --help Print help -V, --version Print version
Option:
Set your ‘OPENAI_API_KEY’ Environment Variable using zsh, No set will ask the user to input the API key in the terminal.
Run the following command in your terminal, replacing yourkey with your API key.