Skip to main content

generate_with_recovery

Function generate_with_recovery 

Source
pub fn generate_with_recovery(
    prompt: &str,
    catalog: &Catalog,
    options: &RecoveryOptions,
    generate: impl FnMut(&str, u32) -> Result<String>,
    on_activity: impl FnMut(&RecoveryActivity),
) -> Result<RecoveredSurface>
Expand description

Generates a surface, retrying with the validator’s complaints on failure.

generate receives the prompt for this attempt and the 1-based attempt number, and returns the model’s raw response. on_activity is called for every step, including the initial start.

§Errors

Returns Error::RecoveryExhausted when every attempt fails validation, or whatever error generate itself returns. A response that cannot be parsed at all is treated as a failed attempt and retried, since that is exactly the case retrying tends to fix.