use whatlang::detect;
pub const COOKLANG_CONVERTER_PROMPT: &str = include_str!("prompt.txt");
fn detect_language(text: &str) -> String {
detect(text)
.map(|info| info.lang().eng_name().to_string())
.unwrap_or_else(|| "the original language".to_string())
}
pub fn inject_recipe(recipe_content: &str) -> String {
let language = detect_language(recipe_content);
COOKLANG_CONVERTER_PROMPT
.replace("{{RECIPE}}", recipe_content)
.replace("{{LANGUAGE}}", &language)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_prompt_is_embedded() {
assert!(!COOKLANG_CONVERTER_PROMPT.is_empty());
assert!(COOKLANG_CONVERTER_PROMPT.contains("Cooklang"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("@ symbol"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("# symbol"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("timer"));
}
#[test]
fn test_prompt_contains_examples() {
assert!(COOKLANG_CONVERTER_PROMPT.contains("Example:"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("@salt"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("@potato{2}"));
assert!(COOKLANG_CONVERTER_PROMPT.contains("#pot"));
}
}