| Crates.io | opai |
| lib.rs | opai |
| version | 0.3.2 |
| created_at | 2024-09-10 00:18:49.141208+00 |
| updated_at | 2024-09-12 20:46:30.968298+00 |
| description | OpenAI Rust SDK |
| homepage | https://github.com/roushou/mesh |
| repository | https://github.com/roushou/mesh |
| max_upload_size | |
| id | 1369906 |
| size | 56,892 |
This is an unofficial Rust SDK for the OpenAI API.
More information about this crate can be found in the crate documentation.
Add opai as a dependency to your Cargo.toml
$ cargo add opai
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);
}
This project is licensed under the MIT license and Apache-2.0 license.