2021-06-25 18:59:46 +01:00
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use crate::model;
|
|
|
|
const SAMPLE_SPLIT_WORD: &str = "<|endoftext|>";
|
|
|
|
const SAMPLE_SAMPLE_LINE: &str =
|
|
|
|
"======================================== SAMPLE 1 ========================================";
|
|
|
|
pub struct Generator<T: model::SampleModel> {
|
|
|
|
model: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Why did this fucking shit take so long to sort out??
|
|
|
|
impl<T> Generator<T>
|
|
|
|
where
|
|
|
|
T: model::SampleModel,
|
|
|
|
{
|
|
|
|
pub fn new(model: T) -> Generator<T> {
|
|
|
|
Self { model }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn generate_sample_lines(&self) -> Result<Vec<String>, io::Error> {
|
2021-07-04 01:21:54 +01:00
|
|
|
Ok(self
|
|
|
|
.model
|
|
|
|
.get_sample()?
|
2021-06-25 18:59:46 +01:00
|
|
|
.replace(SAMPLE_SAMPLE_LINE, "")
|
|
|
|
.split(SAMPLE_SPLIT_WORD)
|
|
|
|
.into_iter()
|
2021-07-04 01:21:54 +01:00
|
|
|
.map(|elem| elem.trim().to_owned())
|
|
|
|
.collect::<Vec<_>>())
|
2021-06-25 18:59:46 +01:00
|
|
|
}
|
|
|
|
}
|