pub struct ExtractFailure { /* private fields */ }Available on crate feature
extract only.Expand description
A failed extraction: why it failed, the last provider response, and the record of the passes it made.
Carried by Error::Extract:
use allama::extract::{ExtractError, ExtractionMode, Extractor};
use allama::mock::{ChatResponseBuilder, MockProvider};
use allama::schemars::{self, JsonSchema};
use allama::{ChatRequest, Error};
#[derive(Debug, serde::Deserialize, JsonSchema)]
struct Person {
name: String,
}
let provider = MockProvider::build(|b| {
b.response(ChatResponseBuilder::new().text("not json").usage(10, 3).build())
.response(ChatResponseBuilder::new().text("still not json").usage(14, 4).build())
});
let request = ChatRequest::new("m")
.user("Ada wrote the first program.")
.with_option(ExtractionMode::Native);
let Err(Error::Extract { failure, .. }) = Extractor::new()
.retries(1)
.extract::<_, Person>(&provider, &request)
.await
else {
panic!("expected an extraction failure");
};
assert!(matches!(failure.error(), ExtractError::Parse { .. }));
assert_eq!(failure.response().and_then(|r| r.text()).as_deref(), Some("still not json"));
assert_eq!(failure.metadata().passes, 2);
assert_eq!(failure.metadata().usage.as_ref().and_then(|u| u.input_tokens), Some(24));Error’s serde form includes the response; its redacted logging view
(Error::as_log) does not. Its Debug withholds the response, and the
model’s text in the error (see ExtractError).
Implementations§
Source§impl ExtractFailure
impl ExtractFailure
Sourcepub fn new(error: ExtractError, metadata: ExtractionMetadata) -> Self
pub fn new(error: ExtractError, metadata: ExtractionMetadata) -> Self
A failure without a response (extraction stopped before or without one).
Sourcepub fn with_response(self, response: ChatResponse) -> Self
pub fn with_response(self, response: ChatResponse) -> Self
Attach the response whose output could not be used.
Sourcepub fn error(&self) -> &ExtractError
pub fn error(&self) -> &ExtractError
Why extraction failed.
Sourcepub fn response(&self) -> Option<&ChatResponse>
pub fn response(&self) -> Option<&ChatResponse>
The last provider response: the one whose output could not be used.
None when extraction failed before calling the provider.
Sourcepub fn metadata(&self) -> &ExtractionMetadata
pub fn metadata(&self) -> &ExtractionMetadata
How the extraction ran up to the failure: mode, provider calls made, and their summed usage.
Sourcepub fn into_response(self) -> Option<ChatResponse>
pub fn into_response(self) -> Option<ChatResponse>
Take the last provider response.
Trait Implementations§
Source§impl Clone for ExtractFailure
impl Clone for ExtractFailure
Source§impl Debug for ExtractFailure
impl Debug for ExtractFailure
Source§impl<'de> Deserialize<'de> for ExtractFailure
impl<'de> Deserialize<'de> for ExtractFailure
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ExtractFailure
impl Display for ExtractFailure
Source§impl Error for ExtractFailure
impl Error for ExtractFailure
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<ExtractFailure> for Error
impl From<ExtractFailure> for Error
Source§fn from(failure: ExtractFailure) -> Self
fn from(failure: ExtractFailure) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ExtractFailure
impl RefUnwindSafe for ExtractFailure
impl Send for ExtractFailure
impl Sync for ExtractFailure
impl Unpin for ExtractFailure
impl UnsafeUnpin for ExtractFailure
impl UnwindSafe for ExtractFailure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more