Skip to content

Commit f64b867

Browse files
author
Guantong
committed
More usage
1 parent b40f033 commit f64b867

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ Add the following to your Cargo.toml file:
3333
openai_api_rust = "0.1.1"
3434
```
3535

36+
Export your API key into the environment variables
37+
38+
```bash
39+
export OPENAI_API_KEY=<your_api_key>
40+
```
41+
3642
Then use the crate in your Rust code:
3743

3844
```rust
3945
use openai_api_rust::*;
4046
use openai_api_rust::edits::*;
4147

4248
fn main() {
49+
// Load API key from environment OPENAI_API_KEY.
50+
// You can also hadcode through `Auth::new(<your_api_key>)`, but it is not recommended.
4351
let auth = Auth::from_env().unwrap();
44-
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
45-
.use_env_proxy()
46-
.unwrap();
52+
let openai = OpenAI::new(auth, "https://api.openai.com/v1/");
4753
let body = EditsBody {
4854
model: "text-davinci-edit-001".to_string(),
4955
temperature: None,
@@ -64,6 +70,23 @@ Output:
6470
choice: Some("What day of the week is it?\n")
6571
```
6672

73+
### Use proxy
74+
75+
Load proxy from env
76+
77+
```rust
78+
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
79+
.use_env_proxy()
80+
.unwrap();
81+
```
82+
83+
Set the proxy manually
84+
85+
```rust
86+
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
87+
.set_proxy("http://127.0.0.1:1080");
88+
```
89+
6790
## License
6891

6992
This library is distributed under the terms of the MIT license. See [LICENSE](LICENSE) for details.

0 commit comments

Comments
 (0)