rs_openai/
lib.rs

1//! The OpenAI Rust library provides convenient access to the OpenAI API from Rust applications.
2//!
3//! ## Creating client
4//!
5//! ```ignore
6//! use dotenvy::dotenv;
7//! use rs_openai::{OpenAI};
8//! use std::env::var;
9//!
10//! dotenv().ok();
11//! let api_key = var("OPENAI_API_KEY").unwrap();
12//!
13//! let client = OpenAI::new(&OpenAI {
14//!     api_key,
15//!     org_id: None,
16//! });
17//! ```
18//!
19//! ## Making requests
20//!
21//!```ignore
22//! use dotenvy::dotenv;
23//! use rs_openai::{
24//!     chat::{ChatCompletionMessageRequestBuilder, CreateChatRequestBuilder, Role},
25//!     OpenAI,
26//! };
27//! use std::env::var;
28//!
29//! #[tokio::main]
30//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
31//!     dotenv().ok();
32//!     let api_key = var("OPENAI_API_KEY").unwrap();
33//!
34//!     let client = OpenAI::new(&OpenAI {
35//!         api_key,
36//!         org_id: None,
37//!     });
38//!
39//!     let req = CreateChatRequestBuilder::default()
40//!         .model("gpt-3.5-turbo")
41//!         .messages(vec![ChatCompletionMessageRequestBuilder::default()
42//!             .role(Role::User)
43//!             .content("To Solve LeetCode's problem 81 in Rust.")
44//!             .build()?])
45//!         .build()?;
46//!
47//!     let res = client.chat().create(&req).await?;
48//!     println!("{:?}", res);
49//!
50//!     Ok(())
51//! }
52//!```
53//!
54//! ## Examples
55//! For full working examples for all supported features see [examples](https://github.com/YanceyOfficial/rs-openai/tree/master/examples) directory in the repository.
56//!
57pub mod apis;
58pub mod client;
59pub mod shared;
60pub mod interfaces;
61
62pub use apis::*;
63pub use client::*;