Merge pull request #22 from dongri/endpoint-from-env

Endpoint from env
This commit is contained in:
Dongri Jin
2023-08-04 06:42:18 +09:00
committed by GitHub
3 changed files with 11 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "openai-api-rs"
version = "0.1.11"
version = "0.1.12"
edition = "2021"
authors = ["Dongri Jin <dongrify@gmail.com>"]
license = "MIT"

View File

@@ -1,13 +1,13 @@
# OpenAI API client library for Rust (unofficial)
The OpenAI API client Rust library provides convenient access to the OpenAI API from Rust applications.
Check out the [docs.rs](https://docs.rs/openai-api-rs/0.1.11/openai_api_rs/v1/index.html).
Check out the [docs.rs](https://docs.rs/openai-api-rs/).
## Installation:
Cargo.toml
```toml
[dependencies]
openai-api-rs = "0.1.11"
openai-api-rs = "0.1"
```
## Usage
@@ -18,6 +18,11 @@ The library needs to be configured with your account's secret key, which is avai
$ export OPENAI_API_KEY=sk-xxxxxxx
```
### Set OPENAI_API_ENDPOINT to environment variable (optional)
```bash
$ export OPENAI_API_ENDPOINT=https://api.openai.com/v1
```
### Create client
```rust
use openai_api_rs::v1::api::Client;

View File

@@ -35,7 +35,9 @@ pub struct Client {
impl Client {
pub fn new(api_key: String) -> Self {
Self::new_with_endpoint(API_URL_V1.to_owned(), api_key)
let endpoint =
std::env::var("OPENAI_API_ENDPOINT").unwrap_or_else(|_| API_URL_V1.to_owned());
Self::new_with_endpoint(endpoint, api_key)
}
pub fn new_with_endpoint(api_endpoint: String, api_key: String) -> Self {