openai.rs
A wrapper for OpenAI API written in Rust
Usage Example
First of all, you need to initialize a client.
use Client;
let client = new;
Then you can use the methods to interact with the API:
let completion = client.create_completion
.await
.unwrap;
This method returns the response returned from the API.
You can do the following to get the content from the response:
use Content;
// Get the text data from the response
let text = completion.get_content.unwrap; // Get the first content
let text_by_range = completion.get_contents; // Get a vector of strings by a range
// Print the completion
for text in text_by_range
Like in this example, you can get the content by index or by a range.
If you want to get the json, you can directly get access the json
field:
let response = completion.json;
To see examples of other APIs you can look at the examples here.
Features to come
Chat API support- Embeddings API support
- Audio API support
- Fine tunes API support