2023-09-16 20:07:00 +01:00
|
|
|
mod algos;
|
2023-09-16 16:13:57 +01:00
|
|
|
mod config;
|
2023-09-07 18:02:36 +01:00
|
|
|
mod processes;
|
|
|
|
mod services;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-08-31 08:42:56 +01:00
|
|
|
use anyhow::Result;
|
2023-09-21 11:33:17 +01:00
|
|
|
use env_logger::Env;
|
2023-09-21 09:36:47 +01:00
|
|
|
use lingua::LanguageDetectorBuilder;
|
2023-09-21 10:22:18 +01:00
|
|
|
use log::info;
|
2023-08-31 08:42:56 +01:00
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
use crate::algos::AlgosBuilder;
|
|
|
|
use crate::algos::Nederlandskie;
|
2023-09-16 16:13:57 +01:00
|
|
|
use crate::config::Config;
|
2023-09-16 16:21:18 +01:00
|
|
|
use crate::processes::FeedServer;
|
|
|
|
use crate::processes::PostIndexer;
|
|
|
|
use crate::processes::ProfileClassifier;
|
|
|
|
use crate::services::Bluesky;
|
|
|
|
use crate::services::Database;
|
2023-09-16 20:07:00 +01:00
|
|
|
use crate::services::AI;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
2023-08-31 08:42:56 +01:00
|
|
|
async fn main() -> Result<()> {
|
2023-09-21 10:22:18 +01:00
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
|
|
|
|
|
|
info!("Loading configuration");
|
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
let config = Arc::new(Config::load()?);
|
|
|
|
|
2023-09-21 10:22:18 +01:00
|
|
|
info!("Initializing service clients");
|
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
let ai = Arc::new(AI::new(&config.chat_gpt_api_key, "https://api.openai.com"));
|
|
|
|
let bluesky = Arc::new(Bluesky::new("https://bsky.social"));
|
|
|
|
let database = Arc::new(Database::connect(&config.database_url).await?);
|
2023-09-21 10:22:18 +01:00
|
|
|
|
|
|
|
info!("Initializing language detector");
|
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
let language_detector = Arc::new(
|
|
|
|
LanguageDetectorBuilder::from_all_languages()
|
|
|
|
.with_preloaded_language_models()
|
|
|
|
.build(),
|
|
|
|
);
|
2023-09-07 18:20:38 +01:00
|
|
|
|
2023-09-21 09:36:47 +01:00
|
|
|
let algos = Arc::new(
|
|
|
|
AlgosBuilder::new()
|
|
|
|
.add("nederlandskie", Nederlandskie::new(language_detector))
|
|
|
|
.build(),
|
|
|
|
);
|
2023-08-31 08:42:56 +01:00
|
|
|
|
2023-09-21 11:33:17 +01:00
|
|
|
let post_indexer = PostIndexer::new(
|
|
|
|
database.clone(),
|
|
|
|
bluesky.clone(),
|
|
|
|
algos.clone(),
|
|
|
|
config.clone(),
|
|
|
|
);
|
2023-09-21 09:36:47 +01:00
|
|
|
let profile_classifier = ProfileClassifier::new(database.clone(), ai.clone(), bluesky.clone());
|
|
|
|
let feed_server = FeedServer::new(database.clone(), config.clone(), algos.clone());
|
2023-09-06 07:26:03 +01:00
|
|
|
|
2023-09-21 10:22:18 +01:00
|
|
|
info!("Starting everything up");
|
|
|
|
|
2023-09-16 16:13:57 +01:00
|
|
|
tokio::try_join!(
|
2023-09-16 16:16:01 +01:00
|
|
|
post_indexer.start(),
|
2023-09-16 16:13:57 +01:00
|
|
|
profile_classifier.start(),
|
|
|
|
feed_server.serve(),
|
|
|
|
)?;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|