A community-maintained library provides a simple and convenient way to interact with the OpenAI API. No complex async and redundant dependencies.
check official API reference |API|Support| |---|---| |Models|✔️| |Completions|✔️| |Chat|✔️| |Edits|✔️| |Images|✔️| |Embeddings|✔️| |Audio|✔️| |Files|❌| |Fine-tunes|❌| |Moderations|❌| |Engines|❌|
Add the following to your Cargo.toml file:
toml
openai_api_rust = "0.1.1"
Then use the crate in your Rust code:
```rust use openaiapirust::; use openai_api_rust::edits::;
fn main() { let auth = Auth::fromenv().unwrap(); let openai = OpenAI::new(auth, "https://api.openai.com/v1/") .useenvproxy() .unwrap(); let body = EditsBody { model: "text-davinci-edit-001".tostring(), temperature: None, topp: None, n: Some(2), instruction: "Fix the spelling mistakes".tostring(), input: Some("What day of the wek is it?".tostring()), }; let rs = openai.editcreate(&body).unwrap(); let choice = rs.choices.get(0).unwrap(); println!("choice: {:?}", choice.text); } ```
Output:
bash
choice: Some("What day of the week is it?\n")
This library is distributed under the terms of the MIT license. See LICENSE for details.