diff --git a/rust_fortune_teller/.env.sample b/rust_fortune_teller/.env.sample new file mode 100644 index 0000000..3f9ccc4 --- /dev/null +++ b/rust_fortune_teller/.env.sample @@ -0,0 +1 @@ +GEMINI_API_KEY=changeMe \ No newline at end of file diff --git a/rust_fortune_teller/.gitignore b/rust_fortune_teller/.gitignore index c41cc9e..0b745e2 100644 --- a/rust_fortune_teller/.gitignore +++ b/rust_fortune_teller/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +.env \ No newline at end of file diff --git a/rust_fortune_teller/Cargo.lock b/rust_fortune_teller/Cargo.lock index 38919c2..d677264 100644 --- a/rust_fortune_teller/Cargo.lock +++ b/rust_fortune_teller/Cargo.lock @@ -115,6 +115,12 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -756,6 +762,7 @@ name = "rust_fortune_teller" version = "0.1.0" dependencies = [ "ask_gemini", + "dotenv", "rand", "serde", "tokio", diff --git a/rust_fortune_teller/Cargo.toml b/rust_fortune_teller/Cargo.toml index 92c2396..3e9948b 100644 --- a/rust_fortune_teller/Cargo.toml +++ b/rust_fortune_teller/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] ask_gemini = "0.1.4" +dotenv = "0.15.0" rand = "0.8.5" serde = { version = "1.0.204", features = ["derive"] } -tokio = "1.38.1" \ No newline at end of file +tokio = "1.38.1" diff --git a/rust_fortune_teller/src/main.rs b/rust_fortune_teller/src/main.rs index 92e8df6..3137bf3 100644 --- a/rust_fortune_teller/src/main.rs +++ b/rust_fortune_teller/src/main.rs @@ -5,8 +5,7 @@ use rand; use rand::seq::SliceRandom; use ask_gemini::Gemini; use std::fmt::Write; - -const GEMINI_API_KEY: &str = "changeMe"; +use dotenv::dotenv; #[derive(Serialize, Deserialize, Debug)] pub enum Suit { @@ -131,6 +130,11 @@ fn format_reading(reading: &[String]) -> String { #[tokio::main] async fn main() { + dotenv().ok(); + + let gemini_api_key = std::env::var("GEMINI_API_KEY") + .expect("GEMINI_API_KEY must be set"); + println!("[INFO] Welcome to Vadar Fortune Teller!"); println!("[INFO] Please let me know your name: "); let mut username = String::new(); @@ -169,7 +173,7 @@ async fn main() { // println!("PROMPTS = {prompt}"); - let gemini = Gemini::new(Some(GEMINI_API_KEY), None); + let gemini = Gemini::new(Some(&gemini_api_key), None); match gemini.ask(&prompt).await { Ok(response) => { //println!("[INFO] Signal from the universe: \n {:?}", response);