File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -33,17 +33,23 @@ Add the following to your Cargo.toml file:
3333openai_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+
3642Then use the crate in your Rust code:
3743
3844``` rust
3945use openai_api_rust :: * ;
4046use openai_api_rust :: edits :: * ;
4147
4248fn 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:
6470choice: 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
6992This library is distributed under the terms of the MIT license. See [ LICENSE] ( LICENSE ) for details.
You can’t perform that action at this time.
0 commit comments