pub mod ooda;
use crate::chains::Outcome;
use crate::context;
use crate::prompt::Task;
use crate::tools::ToolUseError;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Failed to add to the chat history: {0}")]
ChatHistoryError(#[from] context::Error),
#[error("Error from the model: {0}")]
ModelError(#[from] crate::models::Error),
}
pub(crate) fn format_outcome(
task: &Task,
invocation_count: &usize,
tool_name: &Option<String>,
outcome: &Outcome,
) -> String {
match outcome {
Outcome::Success { result } => {
let msg = task.action_success_prompt(
tool_name.clone().unwrap_or("unknown".to_string()),
*invocation_count,
result,
);
const MAX_RESPONSE_CHAR: usize = 2048;
if msg.len() > MAX_RESPONSE_CHAR {
let msg = format!("The response is too long ({}B). Max allowed is {}B. Ask for a shorter response or use SandboxedPython Tool to process the response the data.",
msg.len(), MAX_RESPONSE_CHAR);
let e = ToolUseError::InvocationFailed(msg);
let msg = task
.action_failed_prompt(tool_name.clone().unwrap_or("unknown".to_string()), &e);
format!("{}\n{}", msg, task.to_prompt())
} else {
format!("{}\n{}", msg, task.to_prompt())
}
}
Outcome::NoValidInvocationsFound { e } => {
let msg = task.invalid_action_prompt(e);
format!("{}\n{}", msg, task.to_prompt())
}
Outcome::NoInvocationsFound { e } => {
let msg = task.invalid_action_prompt(e);
format!("{}\n{}", msg, task.to_prompt())
}
Outcome::ToolUseError { e } => {
let msg =
task.action_failed_prompt(tool_name.clone().unwrap_or("unknown".to_string()), e);
format!("{}\n{}", msg, task.to_prompt())
}
}
}