Trait Backend

Source
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 methodcomplete, which performs a single non-streaming round-trip and returns a value whose type is dictated by the PromptTemplate.

The method returns a Pin<Box<dyn Future>> so we stay object-safe without pulling in async_trait.

Required Associated Types§

Source

type Message: Send + Sync + 'static

Chat message type consumed by this backend.

A simple setup can re-use crate::generic::GenericMessage. Providers with richer wire formats (function calls, images …) can supply their own struct.

Required Methods§

Source

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>,

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.

Implementors§