pub trait Backend: Send + Sync {
type Message: Send + Sync + 'static;
// Required method
fn chat_complete<P>(
&self,
prompt: P,
) -> Pin<Box<dyn Future<Output = Result<P::Output>> + Send>>
where P: PromptTemplate + Send + 'static,
<P as IntoPrompt>::Message: Into<Self::Message>;
}
Expand description
A backend turns a prompt into a network call to a concrete provider (OpenAI, Ollama, Anthropic, …) and parses the structured response.
The trait is intentionally minimal:
- One associated type – the in-memory
Message
representation this provider accepts. - One async-ish method –
complete
, which performs a single non-streaming round-trip and returns a value whose type is dictated by thePromptTemplate
.
The method returns a Pin<Box<dyn Future>>
so we stay object-safe
without pulling in async_trait
.
Required Associated Types§
Required Methods§
Sourcefn chat_complete<P>(
&self,
prompt: P,
) -> Pin<Box<dyn Future<Output = Result<P::Output>> + Send>>
fn chat_complete<P>( &self, prompt: P, ) -> Pin<Box<dyn Future<Output = Result<P::Output>> + Send>>
Execute the prompt and deserialize the provider’s reply into
P::Output
.
The blanket constraint P: PromptTemplate<Message = Self::Message>
guarantees at compile time that callers only feed the backend
messages it understands.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.