Skip to main content

LlmBackend

Trait LlmBackend 

Source
pub trait LlmBackend: Send + Sync {
    // Required methods
    fn complete(&self, prompt: &str, max_tokens: u32) -> Result<String>;
    fn name(&self) -> &'static str;

    // Provided method
    fn complete_usage(
        &self,
        prompt: &str,
        max_tokens: u32,
    ) -> Result<(String, LlmUsage)> { ... }
}
Expand description

One AI call: a prompt in, the model’s text reply out.

Required Methods§

Source

fn complete(&self, prompt: &str, max_tokens: u32) -> Result<String>

Source

fn name(&self) -> &'static str

Stable label for logs / provenance.

Provided Methods§

Source

fn complete_usage( &self, prompt: &str, max_tokens: u32, ) -> Result<(String, LlmUsage)>

Like complete but also reports token usage when the backend exposes it. Default: run complete and report no usage, so mocks and minimal backends need not implement it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§