pub fn cleanup_thinking_blocks(content: String) -> String {
let mut is_thinking: bool = false;
let mut result: String = String::new();
let mut first_line = true;
for line in content.lines() {
if line.trim() == "<think>" {
is_thinking = true;
continue;
}
if line.trim() == "</think>" {
is_thinking = false;
continue;
}
if !is_thinking {
if !first_line {
result.push('\n');
}
result.push_str(line);
first_line = false;
}
}
result
}
pub fn extract_result_content(content: &str) -> String {
if let Some(start) = content.find("<result>") {
if let Some(end) = content.find("</result>") {
if start < end {
return content[start + 8..end].trim().to_string();
}
}
}
content.trim().to_string()
}
pub fn format_additional_instructions(additional_instructions: &Vec<String>) -> String {
let mut prompt: String = String::new();
if !additional_instructions.is_empty() {
prompt.push_str("\nAdditional instructions:\n");
for instruction in additional_instructions {
prompt.push_str(&format!("- {}\n", instruction));
}
}
prompt
}