use crate::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;
pub(crate) const SHAKESPEARE_PACK: Pack = Pack {
name: "tiny_shakespeare",
version: "1.0.0",
license: "public-domain",
files: &[PackFile {
name: "input.txt",
size: 1_115_394,
shake256: "f71bef2200fc229ce76fac55556cac487c21be9ed12e4bfc828882d8219fab91",
urls: &[
"https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt",
],
}],
};
pub const DEFAULT_SEQ_LEN: usize = 128;
#[derive(Clone, Debug)]
pub struct TinyShakespeareConfig {
pub seq_len: usize,
pub cache_dir: Option<PathBuf>,
}
impl Default for TinyShakespeareConfig {
fn default() -> Self {
Self {
seq_len: DEFAULT_SEQ_LEN,
cache_dir: None,
}
}
}
impl TinyShakespeareConfig {
#[inline]
#[must_use]
pub fn new() -> Self {
Self::default()
}
}
impl super::TinyShakespeare {
#[inline]
pub fn load(config: &TinyShakespeareConfig) -> Result<Self> {
Self::load_on(&Engine::current()?, config)
}
#[inline]
pub fn load_on(engine: &Engine, config: &TinyShakespeareConfig) -> Result<Self> {
Self::load_with_progress_on(engine, config, &mut |_| true)
}
#[inline]
pub fn load_with_progress(
config: &TinyShakespeareConfig,
progress: &mut impl FnMut(FetchProgress) -> bool,
) -> Result<Self> {
Self::load_with_progress_on(&Engine::current()?, config, progress)
}
}