2021-07-04 01:21:54 +01:00
|
|
|
use std::{error::Error, process, time::Duration};
|
2021-06-25 20:48:06 +01:00
|
|
|
|
2021-06-28 19:57:06 +01:00
|
|
|
use chrono::Local;
|
2021-06-25 20:48:06 +01:00
|
|
|
use rand::Rng;
|
2021-06-25 18:59:46 +01:00
|
|
|
|
2021-07-05 01:43:11 +01:00
|
|
|
use crate::{
|
|
|
|
bot::IzzilisBot,
|
|
|
|
publish::FediversePublisher,
|
|
|
|
selection::{ConsoleSelector, SelectorExt},
|
|
|
|
};
|
2021-06-28 19:57:06 +01:00
|
|
|
|
2021-07-05 01:13:20 +01:00
|
|
|
use futures::StreamExt;
|
2021-07-04 01:21:54 +01:00
|
|
|
use futures_timer::Delay;
|
2021-07-05 01:13:20 +01:00
|
|
|
use model::SampleModelExt;
|
2021-07-04 01:21:54 +01:00
|
|
|
|
2021-06-25 18:59:46 +01:00
|
|
|
mod bot;
|
|
|
|
mod config;
|
|
|
|
mod model;
|
|
|
|
mod publish;
|
2021-06-28 19:57:06 +01:00
|
|
|
mod selection;
|
2021-06-25 18:59:46 +01:00
|
|
|
|
|
|
|
const CONFIG_PATH: &str = "bot_config.json";
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
2021-07-04 01:21:54 +01:00
|
|
|
smol::block_on(async {
|
|
|
|
let cfg = match config::Config::from(CONFIG_PATH.to_string()) {
|
|
|
|
Ok(cfg) => cfg,
|
|
|
|
Err(_) => {
|
|
|
|
println!(
|
|
|
|
"Failed reading config at [{}], writing default",
|
|
|
|
CONFIG_PATH
|
|
|
|
);
|
|
|
|
match config::Config::default().save(CONFIG_PATH.to_string()) {
|
|
|
|
Some(err) => println!("Failed writing file to {}: {}", CONFIG_PATH, err),
|
|
|
|
None => (),
|
|
|
|
}
|
|
|
|
process::exit(1);
|
2021-06-25 18:59:46 +01:00
|
|
|
}
|
2021-07-04 01:21:54 +01:00
|
|
|
};
|
2021-06-25 18:59:46 +01:00
|
|
|
|
2021-07-05 01:43:11 +01:00
|
|
|
let mut gpt_model = ConsoleSelector.filter(
|
|
|
|
model::GPTSampleModel::new(
|
|
|
|
cfg.python_path(),
|
|
|
|
cfg.gpt_code_path(),
|
|
|
|
vec![
|
|
|
|
"generate_unconditional_samples.py".to_string(),
|
|
|
|
"--model_name".to_string(),
|
|
|
|
cfg.model_name(),
|
|
|
|
"--temperature".to_string(),
|
|
|
|
cfg.temperature(),
|
|
|
|
"--top_k".to_string(),
|
|
|
|
cfg.top_k(),
|
|
|
|
"--nsamples".to_string(),
|
|
|
|
"1".to_string(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.into_stream()
|
|
|
|
.take(10),
|
|
|
|
);
|
2021-06-25 18:59:46 +01:00
|
|
|
|
2021-07-05 01:13:20 +01:00
|
|
|
while let Some(Ok(sample)) = gpt_model.next().await {
|
|
|
|
println!("{}", sample);
|
2021-06-25 20:48:06 +01:00
|
|
|
}
|
2021-07-05 01:13:20 +01:00
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
// let publisher = FediversePublisher::new(cfg.fediverse_base_url())?;
|
|
|
|
// // let publisher = ConsolePublisher::new();
|
|
|
|
// let console_selector = ConsoleSelector::new();
|
|
|
|
// let mut bot = IzzilisBot::new(gen, publisher, console_selector);
|
|
|
|
// bot.generate_samples();
|
|
|
|
|
|
|
|
// let cfg_interval = cfg.interval_seconds();
|
|
|
|
// loop {
|
|
|
|
// let wait_seconds = rand::thread_rng().gen_range(cfg_interval.min()..cfg_interval.max());
|
|
|
|
// let wait_time = Duration::from_secs(wait_seconds);
|
|
|
|
// let now = Local::now();
|
|
|
|
// println!("[{}] Next post is in [{}] seconds", now, wait_seconds);
|
|
|
|
// Delay::new(wait_time).await;
|
|
|
|
// match bot.publish() {
|
|
|
|
// Err(err) => println!("Got error from publish: [{}]; continuing", err),
|
|
|
|
// Ok(()) => println!("publish() call successful"),
|
|
|
|
// }
|
|
|
|
// }
|
2021-07-04 01:21:54 +01:00
|
|
|
})
|
2021-06-25 18:59:46 +01:00
|
|
|
}
|