diff --git a/Cargo.lock b/Cargo.lock index f4d3631..68875cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -841,6 +841,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dtoa" version = "1.0.11" @@ -987,6 +993,7 @@ dependencies = [ "chrono", "color-eyre", "crossterm", + "dotenv", "futures", "futures-timer", "hound", diff --git a/Cargo.toml b/Cargo.toml index d0c9010..a6291cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ better-panic = "0.3.0" chrono = { version = "0.4.44", features = ["serde"] } color-eyre = "0.6.5" crossterm = { version = "0.29.0", features = ["event-stream"] } +dotenv = "0.15.0" futures = "0.3.32" futures-timer = "3.0.4" hound = "3.5.1" diff --git a/src/main.rs b/src/main.rs index 280411d..6f726df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -587,7 +587,9 @@ async fn main() { println!("Panic: {}", msg); })); - if option_env!("OPENAI_API_KEY").is_none() { + dotenv::dotenv().ok(); + + if std::env::var("OPENAI_API_KEY").is_err() { eprintln!("Error: OPENAI_API_KEY environment variable not set. The application will not function without it."); return; }