5 unstable releases
0.3.2 | Sep 12, 2024 |
---|---|
0.3.1 | Sep 12, 2024 |
0.3.0 | Sep 12, 2024 |
0.2.0 | Sep 12, 2024 |
0.1.0 | Sep 10, 2024 |
#1638 in Web programming
Used in mesh
57KB
1.5K
SLoC
OpenAI Rust SDK
This is an unofficial Rust SDK for the OpenAI API.
More information about this crate can be found in the crate documentation.
Installation
Add opai
as a dependency to your Cargo.toml
$ cargo add opai
Usage
An example to create a completion.
use opai::{
chats::message::{CreateChatCompletion, Message, Role},
client::Client,
config::Config,
models::{gpt::Gpt, Model},
};
#[tokio::main]
async fn main() {
let config = Config::from_env().unwrap();
let client = Client::new(config).unwrap();
let messages: Vec<Message> = vec![Message {
content: "Hello World".into(),
role: Role::User,
name: None,
}];
let request = CreateChatCompletion::new(Model::Gpt(Gpt::GPT4), messages);
let completion = client.chat.create_completion(request).await.unwrap();
println!("{:?}", completion);
}
License
This project is licensed under the MIT license and Apache-2.0 license.
Dependencies
~7–18MB
~231K SLoC