pub struct Extractor<M, T>where
M: CompletionModel,
T: JsonSchema + for<'a> Deserialize<'a> + WasmCompatSend + WasmCompatSync,{ /* private fields */ }Expand description
Extractor for structured data from text
Implementations§
Source§impl<M, T> Extractor<M, T>where
M: CompletionModel,
T: JsonSchema + for<'a> Deserialize<'a> + WasmCompatSend + WasmCompatSync,
impl<M, T> Extractor<M, T>where
M: CompletionModel,
T: JsonSchema + for<'a> Deserialize<'a> + WasmCompatSend + WasmCompatSync,
Sourcepub async fn extract(
&self,
text: impl Into<Message> + WasmCompatSend,
) -> Result<T, ExtractionError>
pub async fn extract( &self, text: impl Into<Message> + WasmCompatSend, ) -> Result<T, ExtractionError>
Attempts to extract data from the given text with a number of retries.
The function will retry the extraction if the initial attempt fails or
if the model does not call the submit tool.
The number of retries is determined by the retries field on the Extractor struct.
Sourcepub async fn extract_with_chat_history(
&self,
text: impl Into<Message> + WasmCompatSend,
chat_history: Vec<Message>,
) -> Result<T, ExtractionError>
pub async fn extract_with_chat_history( &self, text: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> Result<T, ExtractionError>
Attempts to extract data from the given text with a number of retries.
The function will retry the extraction if the initial attempt fails or
if the model does not call the submit tool.
The number of retries is determined by the retries field on the Extractor struct.
Sourcepub async fn extract_with_usage(
&self,
text: impl Into<Message> + WasmCompatSend,
) -> Result<ExtractionResponse<T>, ExtractionError>
pub async fn extract_with_usage( &self, text: impl Into<Message> + WasmCompatSend, ) -> Result<ExtractionResponse<T>, ExtractionError>
Attempts to extract data from the given text with a number of retries, returning both the extracted data and accumulated token usage.
The function will retry the extraction if the initial attempt fails or
if the model does not call the submit tool.
The number of retries is determined by the retries field on the Extractor struct.
Usage accumulates across all retry attempts, including attempts that received
a billed response but failed extraction (e.g. the model never called submit).
Attempts whose completion call itself returned an error (e.g. network failures
or unparseable provider responses) contribute no usage, and when every attempt
fails the returned error carries no usage information at all.
Sourcepub async fn extract_with_chat_history_with_usage(
&self,
text: impl Into<Message> + WasmCompatSend,
chat_history: Vec<Message>,
) -> Result<ExtractionResponse<T>, ExtractionError>
pub async fn extract_with_chat_history_with_usage( &self, text: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> Result<ExtractionResponse<T>, ExtractionError>
Attempts to extract data from the given text with a number of retries, providing chat history context, and returning both the extracted data and accumulated token usage.
The function will retry the extraction if the initial attempt fails or
if the model does not call the submit tool.
The number of retries is determined by the retries field on the Extractor struct.
Usage accumulates across all retry attempts, including attempts that received
a billed response but failed extraction (e.g. the model never called submit).
Attempts whose completion call itself returned an error (e.g. network failures
or unparseable provider responses) contribute no usage, and when every attempt
fails the returned error carries no usage information at all.