pub trait InlineCompletionBackend: Send + Sync {
// Required method
fn stream(
&self,
req: &BackendRequest,
sink: &mut dyn FnMut(StreamChunk) -> StreamControl,
) -> Result<(), BackendError>;
// Provided method
fn complete(
&self,
req: &BackendRequest,
) -> Result<Vec<String>, BackendError> { ... }
}Expand description
Trait for AI inline completion backends.
Implementations provide streaming token generation. The default complete()
method buffers the stream into a one-shot result, so backends only need to
implement stream().
The trait is sync and callback-based to keep this crate dependency-light and runtime-agnostic. Network I/O happens in the provider crate.
Required Methods§
Sourcefn stream(
&self,
req: &BackendRequest,
sink: &mut dyn FnMut(StreamChunk) -> StreamControl,
) -> Result<(), BackendError>
fn stream( &self, req: &BackendRequest, sink: &mut dyn FnMut(StreamChunk) -> StreamControl, ) -> Result<(), BackendError>
Stream completion chunks to a callback sink.
Each StreamChunk.text is cumulative — the full candidate so far,
not a delta. The sink returns StreamControl::Stop to cancel early.
Provided Methods§
Sourcefn complete(&self, req: &BackendRequest) -> Result<Vec<String>, BackendError>
fn complete(&self, req: &BackendRequest) -> Result<Vec<String>, BackendError>
One-shot completion: returns the final candidate texts.
Default implementation buffers the stream.