pub mod battalion_processor;
pub mod paladin_processor;
pub use battalion_processor::{BattalionContentProcessor, BattalionPattern};
pub use paladin_processor::PaladinContentProcessor;
use crate::core::platform::container::content::{ContentItem, ContentType};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OutputParsing {
#[default]
RawText,
Json,
}
impl OutputParsing {
pub fn as_str(&self) -> &'static str {
match self {
OutputParsing::RawText => "raw_text",
OutputParsing::Json => "json",
}
}
}
#[derive(Debug, Clone)]
pub struct PromptTemplate {
template: String,
}
impl Default for PromptTemplate {
fn default() -> Self {
Self {
template: "Analyze the following content and provide your response.\n\nTitle: {title}\n\nContent:\n{content}".to_string(),
}
}
}
impl PromptTemplate {
pub fn new(template: impl Into<String>) -> Self {
Self {
template: template.into(),
}
}
pub fn render(&self, content: &ContentItem) -> String {
let title = content.title().cloned().unwrap_or_default();
let body = extract_text(content);
self.template
.replace("{title}", &title)
.replace("{content}", &body)
}
}
pub(crate) fn extract_text(content: &ContentItem) -> String {
match content.content() {
ContentType::Text(text) => text
.content
.clone()
.or_else(|| text.path.clone())
.unwrap_or_default(),
ContentType::Video(_) => "[video content]".to_string(),
ContentType::Audio(_) => "[audio content]".to_string(),
ContentType::Image(_) => "[image content]".to_string(),
}
}