llmvm_core_lib/
presets.rs1use llmvm_protocol::GenerationParameters;
2use llmvm_util::{get_file_path, DirType};
3use rust_embed::RustEmbed;
4use tokio::fs;
5
6use crate::{error::CoreError, Result};
7
8#[derive(RustEmbed)]
9#[folder = "./presets"]
10struct BuiltInPresets;
11
12pub async fn load_preset(preset_id: &str) -> Result<GenerationParameters> {
14 let preset_file_name = format!("{}.toml", preset_id);
15 let preset_path = get_file_path(DirType::Presets, &preset_file_name, false)
16 .ok_or(CoreError::UserHomeNotFound)?;
17 let preset_toml = match fs::try_exists(&preset_path).await.unwrap_or_default() {
18 true => fs::read_to_string(preset_path).await?,
19 false => std::str::from_utf8(
20 &BuiltInPresets::get(&preset_file_name)
21 .ok_or(CoreError::PresetNotFound)?
22 .data,
23 )?
24 .to_string(),
25 };
26 Ok(toml::from_str(&preset_toml)?)
27}