Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions async-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ Features that makes `async-openai` unique:
## Usage

The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`.
The library reads [API base](https://platform.openai.com/account/api-base) from the environment variable `OPENAI_API_BASE`.

```bash
# On macOS/Linux
export OPENAI_API_KEY='sk-...'
export OPENAI_API_BASE='https://api.openai.com/v1'
```

```powershell
# On Windows Powershell
$Env:OPENAI_API_KEY='sk-...'
$Env:OPENAI_API_BASE='https://api.openai.com/v1'
```

- Visit [examples](https://github.com/64bit/async-openai/tree/main/examples) directory on how to use `async-openai`.
Expand Down
8 changes: 5 additions & 3 deletions async-openai/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub struct OpenAIConfig {
impl Default for OpenAIConfig {
fn default() -> Self {
Self {
api_base: OPENAI_API_BASE.to_string(),
api_base: std::env::var("OPENAI_API_BASE")
.unwrap_or_else(|_| OPENAI_API_BASE.to_string()),
api_key: std::env::var("OPENAI_API_KEY")
.or_else(|_| {
std::env::var("OPENAI_ADMIN_KEY").map(|admin_key| {
Expand All @@ -86,7 +87,7 @@ impl Default for OpenAIConfig {
}

impl OpenAIConfig {
/// Create client with default [OPENAI_API_BASE] url and default API key from OPENAI_API_KEY env var
/// Create client with default API BASE from OPENAI_API_BASE env var or [OPENAI_API_BASE] and default API key from OPENAI_API_KEY env var
pub fn new() -> Self {
Default::default()
}
Expand Down Expand Up @@ -198,7 +199,8 @@ pub struct AzureConfig {
impl Default for AzureConfig {
fn default() -> Self {
Self {
api_base: Default::default(),
api_base: std::env::var("OPENAI_API_BASE")
.unwrap_or_else(|_| Default::default()),
api_key: std::env::var("OPENAI_API_KEY")
.unwrap_or_else(|_| "".to_string())
.into(),
Expand Down