Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support openai_api_base env #2

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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