drfoo/
lib.rs

1/// DrFoo is an OpenAI client library for Rust. It is designed to be a thin shim
2/// around the OpenAI HTTP API.
3///
4/// # Examples
5///
6/// ```no_run
7/// use drfoo::*;
8/// use std::env;
9///
10/// #[tokio::main]
11/// async fn main() {
12///     drfoo::init_logger();
13///     let client = Client::new(env::var("OPENAI_API_KEY").unwrap().into());
14///
15///     let request = Chat::new()
16///        .with_messages([
17///           "You're a linux expert and systems administrator.",
18///           "You're going to provide a short clever answer to my next question",
19///           "What command would you use to find all files in the current directory modified in the last day?"])
20///        .with_max_tokens(200);
21///
22///     let response = client.do_chat(&request).await.unwrap();
23///     println!("Response: {:#?}", response);
24/// }
25/// ```
26
27#[macro_use]
28extern crate log;
29
30pub mod base;
31pub mod chat;
32pub mod client;
33pub mod completion;
34pub mod model;
35
36pub use base::*;
37pub use chat::*;
38pub use client::*;
39pub use completion::*;
40pub use model::*;
41
42/// This method initializes [`env_logger`] from the environment, defaulting to `info` level logging.
43pub fn init_logger() {
44    // We use try_init here so it can by run by tests.
45    let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
46        .try_init();
47    debug!("Logger initialized.");
48}