diff --git a/README.md b/README.md index ddf58e8..c7c4182 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A simple common-line interface for [ChatGPT API](https://platform.openai.com/docs/api-reference/chat/create). -- 🌟 Streaming output! +- 🌟 Streaming output! - 🤖 Both interactive & one-shot mode Screen Shot 2023-03-07 at 09 30 53 @@ -19,9 +19,11 @@ cargo install --path . You'll need a OpenAI API key (you can get one [here](https://platform.openai.com/account/api-keys)), and you'll need to export your API Key as an environment variable: +You can also set a OpenAI API base environment variable, just like [openai-python](https://github.com/openai/openai-python/blob/main/openai/__init__.py#L37) ``` export OPENAI_API_KEY= +# export OPENAI_API_BASE="https://api.openai.com/v1" ``` Then you can start a conversation with ChatGPT: @@ -33,5 +35,5 @@ heygpt how to record screen on mac OR use the interactive mode by providing no prompt: ``` -heygpt +heygpt ``` diff --git a/src/main.rs b/src/main.rs index a3eb76e..f245bf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -192,9 +192,12 @@ async fn complete_and_print( format!("Bearer {}", openai_api_key).parse().unwrap(), ); + let key = "OPENAI_API_BASE"; + let openai_api_base = env::var(key).unwrap_or("https://api.openai.com/v1".into()); + let client = Client::new(); let req_builder = client - .post("https://api.openai.com/v1/chat/completions".to_string()) + .post(format!("{}/chat/completions", openai_api_base)) .headers(headers) .json(&data);