Skip to content

Commit

Permalink
Merge pull request #104 from getmetal/task/sp/allow-openai-env-variable
Browse files Browse the repository at this point in the history
Add `OPENAI_API_BASE` config
  • Loading branch information
Czechh authored Dec 19, 2023
2 parents dc4faeb + 4e52a01 commit 2631be7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Searches are segmented (filtered) by the session id provided automatically.
- `PORT` (default:8000) - Motorhead Server Port
- `OPENAI_API_KEY`- [Your api key](https://platform.openai.com/account/api-keys) to connect to OpenAI.
- `REDIS_URL` (required)- URL used to connect to `redis`.
- `OPENAI_API_BASE` (default:https://api.openai.com/v1) - OpenAI API Base URL

### Azure deployment

Expand Down
22 changes: 18 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,24 @@ impl Manager for OpenAIClientManager {
completion_client: Client::with_config(config),
}
}
_ => AnyOpenAIClient::OpenAI {
embedding_client: Client::new(),
completion_client: Client::new(),
},
_ => {
let openai_api_base = env::var("OPENAI_API_BASE");

if let Ok(openai_api_base) = openai_api_base {
let embedding_config = OpenAIConfig::default().with_api_base(&openai_api_base);
let completion_config = OpenAIConfig::default().with_api_base(&openai_api_base);

AnyOpenAIClient::OpenAI {
embedding_client: Client::with_config(embedding_config),
completion_client: Client::with_config(completion_config),
}
} else {
AnyOpenAIClient::OpenAI {
embedding_client: Client::new(),
completion_client: Client::new(),
}
}
}
};
Ok(openai_client)
}
Expand Down

0 comments on commit 2631be7

Please sign in to comment.