use thiserror::Error;
#[derive(Debug, Error)]
pub enum ExtractionError {
#[error("provider error: {0}")]
ProviderError(String),
#[error("authentication failed: {0}")]
AuthError(String),
#[error("model not found: {0}")]
ModelNotFound(String),
#[error("parse error: {0}")]
ParseError(String),
#[error("config error: {0}")]
ConfigError(String),
#[error("http error: {0}")]
HttpError(String),
#[error("embedding error: {0}")]
EmbeddingError(String),
#[error(
"{model} hit the output limit of {max_output_tokens} tokens before finishing; \
raise max_output_tokens (MENTEDB_LLM_MAX_OUTPUT_TOKENS) or lower effort"
)]
Truncated {
model: String,
max_output_tokens: u32,
},
#[error("rate limit exceeded after {attempts} attempts")]
RateLimitExceeded { attempts: usize },
}
impl From<reqwest::Error> for ExtractionError {
fn from(e: reqwest::Error) -> Self {
ExtractionError::HttpError(e.to_string())
}
}
impl From<serde_json::Error> for ExtractionError {
fn from(e: serde_json::Error) -> Self {
ExtractionError::ParseError(e.to_string())
}
}