chat_gpt_lib_rs/
lib.rs

1#![warn(missing_docs)]
2//! # OpenAI Rust Client Library
3//!
4//! This crate provides a Rust client library for the [OpenAI API](https://platform.openai.com/docs/api-reference),
5//! implemented in an idiomatic Rust style. It aims to mirror the functionality of other official and
6//! community OpenAI client libraries, while leveraging Rust’s strong type system, async
7//! capabilities, and error handling.
8//!
9//! ## Getting Started
10//!
11//! Add the following to your `Cargo.toml`:
12//!
13//! ```toml
14//! [dependencies]
15//! chat-gpt-lib-rs = "" // latest and greatest version
16//! ```
17//!
18//! Then in your code:
19//!
20//! ```rust,no_run
21//! use chat_gpt_lib_rs::{OpenAIClient, OpenAIError};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), OpenAIError> {
25//!     // Create the client (pull the API key from the OPENAI_API_KEY environment variable by default).
26//!     let client = OpenAIClient::new(Some("sk-...".to_string()))?;
27//!
28//!     // Now you can make calls like:
29//!     // let response = client.create_completion("text-davinci-003", "Hello, world!", 50, 0.7).await?;
30//!     // println!("Completion: {}", response);
31//!
32//!     Ok(())
33//! }
34//! ```
35//!
36//! ## Environment Variables
37//!
38//! By default, this library reads your OpenAI API key from the `OPENAI_API_KEY` environment variable.
39//! If you wish to pass in a key at runtime, use the [`OpenAIClient::new`](crate::OpenAIClient::new) constructor
40//! with an explicit key.
41//!
42//! ## Features
43//!
44//! - **Async-first** – Uses [Tokio](https://tokio.rs/) and [Reqwest](https://crates.io/crates/reqwest)
45//! - **JSON Serialization** – Powered by [Serde](https://serde.rs/)
46//! - **Custom Error Handling** – Utilizes [thiserror](https://crates.io/crates/thiserror) for ergonomic error types
47//! - **Configurable** – Customize timeouts, organization IDs, or other settings
48//!
49//! ## Roadmap
50//!
51//! 1. Implement all major endpoints (e.g. Completions, Chat, Embeddings, Files, Fine-tunes, Moderations).
52//! 2. Provide detailed logging with [`log`](https://crates.io/crates/log) and [`env_logger`](https://crates.io/crates/env_logger).
53//! 3. Offer improved error handling by parsing OpenAI error fields directly.
54//! 4. Provide thorough documentation and examples.
55//!
56//! ## Contributing
57//!
58//! Contributions to this project are more than welcome! Feel free to open issues, submit pull requests,
59//! or suggest improvements. Please see our [GitHub repository](https://github.com/Arend-Jan/chat-gpt-lib-rs) for more details.
60
61/// This module will contain the central configuration, including the `OpenAIClient` struct,
62/// environment variable helpers, and other utilities.
63pub mod config;
64
65/// This module will define custom errors and error types for the library.
66pub mod error;
67
68/// This module will contain the low-level request and response logic,
69/// leveraging `reqwest` to communicate with the OpenAI endpoints.
70pub mod api;
71pub mod api_resources;
72
73/// Re-export commonly used structs and errors for convenience.
74pub use config::OpenAIClient;
75pub use error::OpenAIError;