Read chatgpt and postgresql credentials from .env
This commit is contained in:
		
							parent
							
								
									832bdf6e92
								
							
						
					
					
						commit
						c2899951f6
					
				| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					CHAT_GPT_API_KEY="fake-chat-gpt-key"
 | 
				
			||||||
 | 
					DATABASE_URL="postgres://postgres:password@localhost/nederlandskie"
 | 
				
			||||||
| 
						 | 
					@ -1 +1,2 @@
 | 
				
			||||||
/target
 | 
					/target
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -481,6 +481,12 @@ dependencies = [
 | 
				
			||||||
 "subtle",
 | 
					 "subtle",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "dotenv"
 | 
				
			||||||
 | 
					version = "0.15.0"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "dotenvy"
 | 
					name = "dotenvy"
 | 
				
			||||||
version = "0.15.7"
 | 
					version = "0.15.7"
 | 
				
			||||||
| 
						 | 
					@ -1239,6 +1245,7 @@ dependencies = [
 | 
				
			||||||
 "chat-gpt-lib-rs",
 | 
					 "chat-gpt-lib-rs",
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 "ciborium",
 | 
					 "ciborium",
 | 
				
			||||||
 | 
					 "dotenv",
 | 
				
			||||||
 "futures",
 | 
					 "futures",
 | 
				
			||||||
 "libipld-core",
 | 
					 "libipld-core",
 | 
				
			||||||
 "rs-car",
 | 
					 "rs-car",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ atrium-xrpc = "0.4.0"
 | 
				
			||||||
chat-gpt-lib-rs = "0.2.1"
 | 
					chat-gpt-lib-rs = "0.2.1"
 | 
				
			||||||
chrono = "0.4.29"
 | 
					chrono = "0.4.29"
 | 
				
			||||||
ciborium = "0.2.1"
 | 
					ciborium = "0.2.1"
 | 
				
			||||||
 | 
					dotenv = "0.15.0"
 | 
				
			||||||
futures = "0.3.28"
 | 
					futures = "0.3.28"
 | 
				
			||||||
libipld-core = { version = "0.16.0", features = ["serde-codec"] }
 | 
					libipld-core = { version = "0.16.0", features = ["serde-codec"] }
 | 
				
			||||||
rs-car = "0.4.1"
 | 
					rs-car = "0.4.1"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,13 @@ Heavily WIP. Doesn't work yet at all, but does read the stream of posts as they
 | 
				
			||||||
- [ ] Publish the feed
 | 
					- [ ] Publish the feed
 | 
				
			||||||
- [ ] Handle deleting of posts
 | 
					- [ ] Handle deleting of posts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Initial setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Copy `.env.example` into `.env` and set up the environment variables within:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- `CHAT_GPT_API_KEY` for your ChatGPT key
 | 
				
			||||||
 | 
					- `DATABASE_URL` for PostgreSQL credentials
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Running
 | 
					## Running
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`cargo run`
 | 
					`cargo run`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										27
									
								
								src/main.rs
								
								
								
								
							| 
						 | 
					@ -1,7 +1,10 @@
 | 
				
			||||||
mod processes;
 | 
					mod processes;
 | 
				
			||||||
mod services;
 | 
					mod services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use std::env;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use anyhow::Result;
 | 
					use anyhow::Result;
 | 
				
			||||||
 | 
					use dotenv::dotenv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::processes::post_saver::PostSaver;
 | 
					use crate::processes::post_saver::PostSaver;
 | 
				
			||||||
use crate::processes::profile_classifier::ProfileClassifier;
 | 
					use crate::processes::profile_classifier::ProfileClassifier;
 | 
				
			||||||
| 
						 | 
					@ -9,13 +12,29 @@ use crate::services::ai::AI;
 | 
				
			||||||
use crate::services::bluesky::Bluesky;
 | 
					use crate::services::bluesky::Bluesky;
 | 
				
			||||||
use crate::services::database::Database;
 | 
					use crate::services::database::Database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Config {
 | 
				
			||||||
 | 
					    chat_gpt_api_key: String,
 | 
				
			||||||
 | 
					    database_url: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Config {
 | 
				
			||||||
 | 
					    fn load() -> Result<Self> {
 | 
				
			||||||
 | 
					        dotenv()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Ok(Self {
 | 
				
			||||||
 | 
					            chat_gpt_api_key: env::var("CHAT_GPT_API_KEY")?,
 | 
				
			||||||
 | 
					            database_url: env::var("DATABASE_URL")?,
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[tokio::main]
 | 
					#[tokio::main]
 | 
				
			||||||
async fn main() -> Result<()> {
 | 
					async fn main() -> Result<()> {
 | 
				
			||||||
    // TODO: Use env vars
 | 
					    let config = Config::load()?;
 | 
				
			||||||
    let ai = AI::new("fake-api-key", "https://api.openai.com");
 | 
					
 | 
				
			||||||
 | 
					    let ai = AI::new(&config.chat_gpt_api_key, "https://api.openai.com");
 | 
				
			||||||
    let bluesky = Bluesky::new("https://bsky.social");
 | 
					    let bluesky = Bluesky::new("https://bsky.social");
 | 
				
			||||||
    let database =
 | 
					    let database = Database::connect(&config.database_url).await?;
 | 
				
			||||||
        Database::connect("postgres://postgres:password@localhost/nederlandskie").await?;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let post_saver = PostSaver::new(&database, &bluesky);
 | 
					    let post_saver = PostSaver::new(&database, &bluesky);
 | 
				
			||||||
    let profile_classifier = ProfileClassifier::new(&database, &ai, &bluesky);
 | 
					    let profile_classifier = ProfileClassifier::new(&database, &ai, &bluesky);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue