mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-12-09 22:18:27 +00:00
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user