Skip to content

Commit

Permalink
feat: support openai_api_base env
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyufjh authored and Bowser1704 committed Mar 7, 2023
1 parent b334ed7 commit 63a6b53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<img width="1022" alt="Screen Shot 2023-03-07 at 09 30 53" src="https://user-images.githubusercontent.com/10192522/223295925-00eed881-cdfc-4f46-9510-1e0bd1c99e60.png">
Expand All @@ -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=<your api key>
# export OPENAI_API_BASE="https://api.openai.com/v1"
```

Then you can start a conversation with ChatGPT:
Expand All @@ -33,5 +35,5 @@ heygpt how to record screen on mac
OR use the interactive mode by providing no prompt:

```
heygpt
heygpt
```
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 63a6b53

Please sign in to comment.