pub trait TextModelChunkedExt: TextModel {
// Required method
fn complete_chunked<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_chars: usize,
prompt: impl 'async_trait + for<'a> FnMut(usize, usize, &'a str) -> Prompt + Send,
) -> Pin<Box<dyn Future<Output = Result<String, TextModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Chunk-and-reassemble companion to
TextModelExt (issue #847). Blanket-implemented
for every TextModel, so any model — Arc<dyn TextModel> included —
gets it; import the trait to call the method.
Required Methods§
Sourcefn complete_chunked<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_chars: usize,
prompt: impl 'async_trait + for<'a> FnMut(usize, usize, &'a str) -> Prompt + Send,
) -> Pin<Box<dyn Future<Output = Result<String, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete_chunked<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
max_chars: usize,
prompt: impl 'async_trait + for<'a> FnMut(usize, usize, &'a str) -> Prompt + Send,
) -> Pin<Box<dyn Future<Output = Result<String, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Completes text in chunks of at most max_chars chars: splits it
with split_text_chunks, calls TextModel::complete once per
chunk — sequentially, in order, chunk n asked only after n−1
answered — and reassembles the answers with
reassemble_text_chunks.
prompt(chunk_index, total_chunks, chunk_text) builds each request;
the helper never builds a prompt itself, so the tier, the system
instruction and the token ceiling stay the caller’s. Chunk indexes
are 0-based and total_chunks is every chunk sent to the model, so
a closure can say “part 3 of 7” without counting anything.
Empty text returns Ok(String::new()) without calling the model;
whitespace-only text returns itself unchanged, also without
calling it. The same rule applies per chunk: a whitespace-only
chunk — a blank run that could not share a chunk with either
neighbour — passes through untouched at no round trip, and is not
counted in total_chunks: there is nothing in it to rewrite.
§Errors
Whatever TextModel::complete returned for the chunk that
failed, unchanged — there is no wrapper variant on
TextModelError that could name the chunk without mislabelling
the failure (Transient must keep its retry_after, and the
message-carrying variants are documented as provider text). The run
stops at the first failure and completed chunk work is discarded.
§Panics
Panics if max_chars is zero, via split_text_chunks.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".