Skip to content

Commit 6a62547

Browse files
committed
v6.0.13
1 parent 0cc47c3 commit 6a62547

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openai-api-rs"
3-
version = "6.0.12"
3+
version = "6.0.13"
44
edition = "2021"
55
authors = ["Dongri Jin <[email protected]>"]
66
license = "MIT"

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
# OpenAI API client library for Rust (unofficial)
2+
23
The OpenAI API client Rust library provides convenient access to the OpenAI API from Rust applications.
34

45
Check out the [docs.rs](https://docs.rs/openai-api-rs/).
56

67
## Installation:
8+
79
Cargo.toml
10+
811
```toml
912
[dependencies]
10-
openai-api-rs = "6.0.12"
13+
openai-api-rs = "6.0.13"
1114
```
1215

1316
## Usage
17+
1418
The library needs to be configured with your account's secret key, which is available on the [website](https://platform.openai.com/account/api-keys). We recommend setting it as an environment variable. Here's an example of initializing the library with the API key loaded from an environment variable and creating a completion:
1519

1620
### Set OPENAI_API_KEY or OPENROUTER_API_KEY to environment variable
21+
1722
```bash
1823
$ export OPENAI_API_KEY=sk-xxxxxxx
1924
or
2025
$ export OPENROUTER_API_KEY=sk-xxxxxxx
2126
```
2227

2328
### Create OpenAI client
29+
2430
```rust
2531
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
2632
let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
2733
```
2834

2935
### Create OpenRouter client
36+
3037
```rust
3138
let api_key = env::var("OPENROUTER_API_KEY").unwrap().to_string();
3239
let mut client = OpenAIClient::builder()
@@ -36,6 +43,7 @@ let mut client = OpenAIClient::builder()
3643
```
3744

3845
### Create request
46+
3947
```rust
4048
let req = ChatCompletionRequest::new(
4149
GPT4_O.to_string(),
@@ -50,6 +58,7 @@ let req = ChatCompletionRequest::new(
5058
```
5159

5260
### Send request
61+
5362
```rust
5463
let result = client.chat_completion(req)?;
5564
println!("Content: {:?}", result.choices[0].message.content);
@@ -60,11 +69,13 @@ for (key, value) in client.headers.unwrap().iter() {
6069
```
6170

6271
### Set OPENAI_API_BASE to environment variable (optional)
72+
6373
```bash
6474
$ export OPENAI_API_BASE=https://api.openai.com/v1
6575
```
6676

6777
## Example of chat completion
78+
6879
```rust
6980
use openai_api_rs::v1::api::OpenAIClient;
7081
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
@@ -99,6 +110,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
99110
```
100111

101112
## Example for OpenRouter
113+
102114
```rust
103115
use openai_api_rs::v1::api::OpenAIClient;
104116
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
@@ -126,7 +138,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
126138

127139
let result = client.chat_completion(req).await?;
128140
println!("Content: {:?}", result.choices[0].message.content);
129-
141+
130142
for (key, value) in client.headers.unwrap().iter() {
131143
println!("{}: {:?}", key, value);
132144
}
@@ -140,6 +152,7 @@ More Examples: [examples](https://github.com/dongri/openai-api-rs/tree/main/exam
140152
Check out the [full API documentation](https://platform.openai.com/docs/api-reference/completions) for examples of all the available functions.
141153

142154
## Supported APIs
155+
143156
- [x] [Completions](https://platform.openai.com/docs/api-reference/completions)
144157
- [x] [Chat](https://platform.openai.com/docs/api-reference/chat)
145158
- [x] [Edits](https://platform.openai.com/docs/api-reference/edits)
@@ -155,4 +168,5 @@ Check out the [full API documentation](https://platform.openai.com/docs/api-refe
155168
- [x] [Realtime](https://platform.openai.com/docs/api-reference/realtime)
156169

157170
## License
171+
158172
This project is licensed under [MIT license](https://github.com/dongri/openai-api-rs/blob/main/LICENSE).

0 commit comments

Comments
 (0)