oaapi
An unofficial Rust client for the OpenAI API.
Installation
Run the following Cargo command in your project directory:
cargo add oaapi
or add the following line to your Cargo.toml:
[]
= "0.2.0"
Features
[!NOTE] You need to enable the feature flags to use the corresponding APIs.
Supported APIs
Beta version APIs:
Usage
- Enable API feature flags that you want to use, e.g.
chat. - Create a [
crate::Client] with the API key and the other optional settings. - Use the client to call the APIs, e.g. [
crate::Client::chat_complete].
Examples
An example to call the chat completions API with the chat feature:
[]
= { = "0.2.0", = ["chat"] }
and setting the API key to the environment variable: OPENAI_API_KEY
OPENAI_API_KEY={your-openai-api-key}
is as follows:
use Client;
use CompletionsRequestBody;
use SystemMessage;
use UserMessage;
use ChatModel;
async
See also examples in documents of each feature module for more details.
Other examples
See the ./examples directory.
Changelog
See CHANGELOG.
License
Licensed under either of the Apache License, Version 2.0 or the MIT license at your option.