pub trait BaseLlmExt: BaseLlm {
// Provided method
fn generate<'life0, 'async_trait, T>(
&'life0 self,
thread: T,
toolset: Option<Arc<dyn BaseToolset>>,
) -> Pin<Box<dyn Future<Output = AgentResult<LlmResponse>> + Send + 'async_trait>>
where T: 'async_trait + Into<Thread> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Extension trait providing ergonomic helpers for BaseLlm.
This trait is automatically implemented for all types that implement BaseLlm,
providing convenient methods that accept any type convertible to Thread.
§Design Pattern
This follows the standard Rust extension trait pattern used throughout the ecosystem
(e.g., Iterator + IteratorExt, AsyncRead + AsyncReadExt). The core trait
remains object-safe while extension methods provide zero-cost ergonomic improvements.
§Examples
use radkit::models::{BaseLlm, BaseLlmExt};
async fn example(llm: &impl BaseLlm) -> Result<(), Box<dyn std::error::Error>> {
// All of these work thanks to Into<Thread> implementations:
let r1 = llm.generate("What is 2+2?", None).await?;
let r2 = llm.generate(String::from("Hello!"), None).await?;
let r3 = llm.generate(Thread::from_user("Explain"), None).await?;
println!("Answer: {}", r1.content().first_text().unwrap_or("No text"));
Ok(())
}Provided Methods§
Sourcefn generate<'life0, 'async_trait, T>(
&'life0 self,
thread: T,
toolset: Option<Arc<dyn BaseToolset>>,
) -> Pin<Box<dyn Future<Output = AgentResult<LlmResponse>> + Send + 'async_trait>>
fn generate<'life0, 'async_trait, T>( &'life0 self, thread: T, toolset: Option<Arc<dyn BaseToolset>>, ) -> Pin<Box<dyn Future<Output = AgentResult<LlmResponse>> + Send + 'async_trait>>
Generates content from any type convertible to a Thread.
This method provides an ergonomic wrapper around BaseLlm::generate_content
that automatically converts strings, events, and other types into threads.
§Arguments
thread- Anything convertible toThread:String,&str,Event, orThreadtoolset- Optional set of tools the LLM can invoke during generation
§Returns
Returns an LlmResponse containing generated content and token usage.
§Examples
use radkit::models::{BaseLlm, BaseLlmExt};
async fn demo(llm: &impl BaseLlm) {
// String slice
let response = llm.generate("Hello", None).await?;
// Owned String
let query = String::from("What is Rust?");
let response = llm.generate(query, None).await?;
// Thread directly
let thread = Thread::from_user("Explain quantum computing");
let response = llm.generate(thread, None).await?;
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<T: BaseLlm + ?Sized> BaseLlmExt for T
Blanket implementation of BaseLlmExt for all BaseLlm implementors.
This ensures every type implementing BaseLlm automatically gains the ergonomic
generate method without any additional implementation work.