58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
use std::{error::Error, path::Path};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use telegram_bot::ChatId;
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct Config {
|
|
pub python_path: String,
|
|
pub model_name: String,
|
|
pub temperature: String,
|
|
pub top_k: String,
|
|
pub gpt_code_path: String,
|
|
pub fediverse_base_url: String,
|
|
pub interval_seconds: MinMax,
|
|
pub bot_token: String,
|
|
pub chat_ref: ChatId,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct MinMax {
|
|
pub min: u64,
|
|
pub max: u64,
|
|
}
|
|
|
|
impl Default for Config {
|
|
fn default() -> Self {
|
|
Config {
|
|
python_path: String::from("/usr/bin/python3"),
|
|
model_name: String::from("117M"),
|
|
temperature: String::from("1"),
|
|
top_k: String::from("40"),
|
|
gpt_code_path: String::from("./gpt/"),
|
|
fediverse_base_url: String::from("https://lain.com"),
|
|
interval_seconds: MinMax {
|
|
min: 60 * 30,
|
|
max: 60 * 90,
|
|
},
|
|
bot_token: "".to_owned(),
|
|
chat_ref: ChatId::new(0),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Error>> {
|
|
let file_bytes = std::fs::read(path)?;
|
|
|
|
Ok(serde_json::from_slice(&file_bytes)?)
|
|
}
|
|
|
|
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<(), Box<dyn Error>> {
|
|
let cfg_json = serde_json::to_vec(self)?;
|
|
std::fs::write(path, &cfg_json)?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|