pub struct LlmBroker { /* private fields */ }Expand description
Main interface for LLM interactions
Implementations§
Source§impl LlmBroker
impl LlmBroker
Sourcepub fn new(
model: impl Into<String>,
gateway: Arc<dyn LlmGateway>,
tracer: Option<Arc<TracerSystem>>,
) -> Self
pub fn new( model: impl Into<String>, gateway: Arc<dyn LlmGateway>, tracer: Option<Arc<TracerSystem>>, ) -> Self
Create a new LLM broker
§Arguments
model- The name of the LLM model to usegateway- The gateway to use for LLM communicationtracer- Optional tracer system for observability
Sourcepub async fn generate(
&self,
messages: &[LlmMessage],
tools: Option<&[Box<dyn LlmTool>]>,
config: Option<CompletionConfig>,
correlation_id: Option<String>,
) -> Result<String>
pub async fn generate( &self, messages: &[LlmMessage], tools: Option<&[Box<dyn LlmTool>]>, config: Option<CompletionConfig>, correlation_id: Option<String>, ) -> Result<String>
Generate text response from LLM
§Arguments
messages- The messages to send to the LLMtools- Optional tools available to the LLMconfig- Optional completion configurationcorrelation_id- Optional correlation ID for tracing (generates UUID if None)
Sourcepub async fn generate_object<T>(
&self,
messages: &[LlmMessage],
config: Option<CompletionConfig>,
correlation_id: Option<String>,
) -> Result<T>
pub async fn generate_object<T>( &self, messages: &[LlmMessage], config: Option<CompletionConfig>, correlation_id: Option<String>, ) -> Result<T>
Generate structured object response from LLM
§Arguments
messages- The messages to send to the LLMconfig- Optional completion configurationcorrelation_id- Optional correlation ID for tracing (generates UUID if None)
Sourcepub fn generate_stream<'a>(
&'a self,
messages: &'a [LlmMessage],
tools: Option<&'a [Box<dyn LlmTool>]>,
config: Option<CompletionConfig>,
correlation_id: Option<String>,
) -> Pin<Box<dyn Stream<Item = Result<String>> + 'a>>
pub fn generate_stream<'a>( &'a self, messages: &'a [LlmMessage], tools: Option<&'a [Box<dyn LlmTool>]>, config: Option<CompletionConfig>, correlation_id: Option<String>, ) -> Pin<Box<dyn Stream<Item = Result<String>> + 'a>>
Generate streaming text response from LLM
Returns a stream that yields content chunks as they arrive. When tool calls are detected, the broker executes them and recursively streams the LLM’s follow-up response.
§Arguments
messages- The messages to send to the LLMtools- Optional tools available to the LLMconfig- Optional completion configurationcorrelation_id- Optional correlation ID for tracing (generates UUID if None)
§Example
ⓘ
use futures::stream::StreamExt;
let broker = LlmBroker::new("qwen3:32b", gateway, None);
let messages = vec![LlmMessage::user("Tell me a story")];
let mut stream = broker.generate_stream(&messages, None, None, None);
while let Some(result) = stream.next().await {
match result {
Ok(chunk) => print!("{}", chunk),
Err(e) => eprintln!("Error: {}", e),
}
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for LlmBroker
impl !RefUnwindSafe for LlmBroker
impl Send for LlmBroker
impl Sync for LlmBroker
impl Unpin for LlmBroker
impl !UnwindSafe for LlmBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more