pub struct LLMBuilder { /* private fields */ }Expand description
re-export the llm types so downstream code can use the same structs/enums. Builder for configuring and instantiating LLM providers.
Provides a fluent interface for setting various configuration options like model selection, API keys, generation parameters, etc.
Implementations§
Source§impl LLMBuilder
impl LLMBuilder
Sourcepub fn new() -> LLMBuilder
pub fn new() -> LLMBuilder
Creates a new empty builder instance with default values.
Sourcepub fn backend(self, backend: LLMBackend) -> LLMBuilder
pub fn backend(self, backend: LLMBackend) -> LLMBuilder
Sets the backend provider to use.
Sourcepub fn api_key(self, key: impl Into<String>) -> LLMBuilder
pub fn api_key(self, key: impl Into<String>) -> LLMBuilder
Sets the API key for authentication.
Sourcepub fn base_url(self, url: impl Into<String>) -> LLMBuilder
pub fn base_url(self, url: impl Into<String>) -> LLMBuilder
Sets the base URL for API requests.
Sourcepub fn model(self, model: impl Into<String>) -> LLMBuilder
pub fn model(self, model: impl Into<String>) -> LLMBuilder
Sets the model identifier to use.
Sourcepub fn max_tokens(self, max_tokens: u32) -> LLMBuilder
pub fn max_tokens(self, max_tokens: u32) -> LLMBuilder
Sets the maximum number of tokens to generate.
Sourcepub fn temperature(self, temperature: f32) -> LLMBuilder
pub fn temperature(self, temperature: f32) -> LLMBuilder
Sets the temperature for controlling response randomness (0.0-1.0).
Sourcepub fn system(self, system: impl Into<String>) -> LLMBuilder
pub fn system(self, system: impl Into<String>) -> LLMBuilder
Sets the system prompt/context.
Sourcepub fn reasoning_effort(self, reasoning_effort: ReasoningEffort) -> LLMBuilder
pub fn reasoning_effort(self, reasoning_effort: ReasoningEffort) -> LLMBuilder
Sets the reasoning flag.
Sourcepub fn reasoning(self, reasoning: bool) -> LLMBuilder
pub fn reasoning(self, reasoning: bool) -> LLMBuilder
Sets the reasoning flag.
Sourcepub fn reasoning_budget_tokens(self, reasoning_budget_tokens: u32) -> LLMBuilder
pub fn reasoning_budget_tokens(self, reasoning_budget_tokens: u32) -> LLMBuilder
Sets the reasoning budget tokens.
Sourcepub fn timeout_seconds(self, timeout_seconds: u64) -> LLMBuilder
pub fn timeout_seconds(self, timeout_seconds: u64) -> LLMBuilder
Sets the request timeout in seconds.
Sourcepub fn stream(self, _stream: bool) -> LLMBuilder
👎Deprecated: This method is deprecated and will be removed in a future release. Streaming is defined by the function used (e.g. chat_stream)
pub fn stream(self, _stream: bool) -> LLMBuilder
chat_stream)Enables or disables streaming responses, stub kept for compatibility.
§Deprecation
This method is deprecated and will be removed in a future release.
Streaming is defined by the function called (e.g. chat_stream).
Sourcepub fn top_p(self, top_p: f32) -> LLMBuilder
pub fn top_p(self, top_p: f32) -> LLMBuilder
Sets the top-p (nucleus) sampling parameter.
Sourcepub fn top_k(self, top_k: u32) -> LLMBuilder
pub fn top_k(self, top_k: u32) -> LLMBuilder
Sets the top-k sampling parameter.
Sourcepub fn embedding_encoding_format(
self,
embedding_encoding_format: impl Into<String>,
) -> LLMBuilder
pub fn embedding_encoding_format( self, embedding_encoding_format: impl Into<String>, ) -> LLMBuilder
Sets the encoding format for embeddings.
Sourcepub fn embedding_dimensions(self, embedding_dimensions: u32) -> LLMBuilder
pub fn embedding_dimensions(self, embedding_dimensions: u32) -> LLMBuilder
Sets the dimensions for embeddings.
Sourcepub fn schema(self, schema: impl Into<StructuredOutputFormat>) -> LLMBuilder
pub fn schema(self, schema: impl Into<StructuredOutputFormat>) -> LLMBuilder
Sets the JSON schema for structured output.
Sourcepub fn validator<F>(self, f: F) -> LLMBuilder
pub fn validator<F>(self, f: F) -> LLMBuilder
Sets a validation function to verify LLM responses.
§Arguments
f- Function that takes a response string and returns Ok(()) if valid, or Err with error message if invalid
Sourcepub fn validator_attempts(self, attempts: usize) -> LLMBuilder
pub fn validator_attempts(self, attempts: usize) -> LLMBuilder
Sets the number of retry attempts for validation failures.
§Arguments
attempts- Maximum number of times to retry generating a valid response
Sourcepub fn function(self, function_builder: FunctionBuilder) -> LLMBuilder
pub fn function(self, function_builder: FunctionBuilder) -> LLMBuilder
Adds a function tool to the builder
Sourcepub fn enable_parallel_tool_use(self, enable: bool) -> LLMBuilder
pub fn enable_parallel_tool_use(self, enable: bool) -> LLMBuilder
Enable parallel tool use
Sourcepub fn tool_choice(self, choice: ToolChoice) -> LLMBuilder
pub fn tool_choice(self, choice: ToolChoice) -> LLMBuilder
Set tool choice. Note that if the choice is given as Tool(name), and that tool isn’t available, the builder will fail.
Sourcepub fn disable_tools(self) -> LLMBuilder
pub fn disable_tools(self) -> LLMBuilder
Explicitly disable the use of tools, even if they are provided.
Sourcepub fn api_version(self, api_version: impl Into<String>) -> LLMBuilder
pub fn api_version(self, api_version: impl Into<String>) -> LLMBuilder
Set the API version.
Sourcepub fn deployment_id(self, deployment_id: impl Into<String>) -> LLMBuilder
pub fn deployment_id(self, deployment_id: impl Into<String>) -> LLMBuilder
Set the deployment id. Used in Azure OpenAI.
Sourcepub fn voice(self, voice: impl Into<String>) -> LLMBuilder
pub fn voice(self, voice: impl Into<String>) -> LLMBuilder
Set the voice.
Sourcepub fn openai_enable_web_search(self, enable: bool) -> LLMBuilder
pub fn openai_enable_web_search(self, enable: bool) -> LLMBuilder
Enable web search
Sourcepub fn openai_web_search_context_size(
self,
context_size: impl Into<String>,
) -> LLMBuilder
pub fn openai_web_search_context_size( self, context_size: impl Into<String>, ) -> LLMBuilder
Set the web search context
Sourcepub fn openai_web_search_user_location_type(
self,
location_type: impl Into<String>,
) -> LLMBuilder
pub fn openai_web_search_user_location_type( self, location_type: impl Into<String>, ) -> LLMBuilder
Set the web search user location type
Sourcepub fn openai_web_search_user_location_approximate_country(
self,
country: impl Into<String>,
) -> LLMBuilder
pub fn openai_web_search_user_location_approximate_country( self, country: impl Into<String>, ) -> LLMBuilder
Set the web search user location approximate country
Sourcepub fn openai_web_search_user_location_approximate_city(
self,
city: impl Into<String>,
) -> LLMBuilder
pub fn openai_web_search_user_location_approximate_city( self, city: impl Into<String>, ) -> LLMBuilder
Set the web search user location approximate city
Sourcepub fn openai_web_search_user_location_approximate_region(
self,
region: impl Into<String>,
) -> LLMBuilder
pub fn openai_web_search_user_location_approximate_region( self, region: impl Into<String>, ) -> LLMBuilder
Set the web search user location approximate region
Sourcepub fn resilient(self, enable: bool) -> LLMBuilder
pub fn resilient(self, enable: bool) -> LLMBuilder
Enables or disables the resilience wrapper (retry/backoff).
Sourcepub fn resilient_attempts(self, attempts: usize) -> LLMBuilder
pub fn resilient_attempts(self, attempts: usize) -> LLMBuilder
Sets the maximum number of attempts for resilience (including the first try).
Sourcepub fn resilient_backoff(
self,
base_delay_ms: u64,
max_delay_ms: u64,
) -> LLMBuilder
pub fn resilient_backoff( self, base_delay_ms: u64, max_delay_ms: u64, ) -> LLMBuilder
Sets the backoff bounds in milliseconds for resilience.
Sourcepub fn resilient_jitter(self, jitter: bool) -> LLMBuilder
pub fn resilient_jitter(self, jitter: bool) -> LLMBuilder
Enables or disables jitter for backoff delays.
pub fn search_mode(self, mode: impl Into<String>) -> LLMBuilder
xai_search_mode.Sourcepub fn xai_search_mode(self, mode: impl Into<String>) -> LLMBuilder
pub fn xai_search_mode(self, mode: impl Into<String>) -> LLMBuilder
Sets the search mode for search-enabled providers.
Sourcepub fn xai_search_source(
self,
source_type: impl Into<String>,
excluded_websites: Option<Vec<String>>,
) -> LLMBuilder
pub fn xai_search_source( self, source_type: impl Into<String>, excluded_websites: Option<Vec<String>>, ) -> LLMBuilder
Adds a search source with optional excluded websites.
Sourcepub fn xai_max_search_results(self, max: u32) -> LLMBuilder
pub fn xai_max_search_results(self, max: u32) -> LLMBuilder
Sets the maximum number of search results.
Sourcepub fn xai_search_date_range(
self,
from: impl Into<String>,
to: impl Into<String>,
) -> LLMBuilder
pub fn xai_search_date_range( self, from: impl Into<String>, to: impl Into<String>, ) -> LLMBuilder
Sets the date range for search results.
Sourcepub fn xai_search_from_date(self, date: impl Into<String>) -> LLMBuilder
pub fn xai_search_from_date(self, date: impl Into<String>) -> LLMBuilder
Sets the start date for search results (format: “YYYY-MM-DD”).
Sourcepub fn xai_search_to_date(self, date: impl Into<String>) -> LLMBuilder
pub fn xai_search_to_date(self, date: impl Into<String>) -> LLMBuilder
Sets the end date for search results (format: “YYYY-MM-DD”).
Sourcepub fn memory(self, memory: impl MemoryProvider + 'static) -> LLMBuilder
pub fn memory(self, memory: impl MemoryProvider + 'static) -> LLMBuilder
Sets a custom memory provider for storing conversation history.
§Arguments
memory- A boxed memory provider implementing the MemoryProvider trait
§Examples
use llm::builder::{LLMBuilder, LLMBackend};
use llm::memory::SlidingWindowMemory;
let memory = SlidingWindowMemory::new(10);
let builder = LLMBuilder::new()
.backend(LLMBackend::OpenAI)
.memory(memory);Sourcepub fn sliding_memory(self, memory: SlidingWindowMemory) -> LLMBuilder
pub fn sliding_memory(self, memory: SlidingWindowMemory) -> LLMBuilder
Sets a sliding window memory instance directly (convenience method).
§Arguments
memory- A SlidingWindowMemory instance
§Examples
use llm::builder::{LLMBuilder, LLMBackend};
use llm::memory::SlidingWindowMemory;
let memory = SlidingWindowMemory::new(10);
let builder = LLMBuilder::new()
.backend(LLMBackend::OpenAI)
.sliding_memory(memory);Sourcepub fn sliding_window_memory(self, window_size: usize) -> LLMBuilder
pub fn sliding_window_memory(self, window_size: usize) -> LLMBuilder
Sets up a sliding window memory with the specified window size.
This is a convenience method for creating a SlidingWindowMemory instance.
§Arguments
window_size- Maximum number of messages to keep in memory
§Examples
use llm::builder::{LLMBuilder, LLMBackend};
let builder = LLMBuilder::new()
.backend(LLMBackend::OpenAI)
.sliding_window_memory(5); // Keep last 5 messagesSourcepub fn sliding_window_with_strategy(
self,
window_size: usize,
strategy: TrimStrategy,
) -> LLMBuilder
pub fn sliding_window_with_strategy( self, window_size: usize, strategy: TrimStrategy, ) -> LLMBuilder
Sets up a sliding window memory with specified trim strategy.
§Arguments
window_size- Maximum number of messages to keep in memorystrategy- How to handle overflow when window is full
§Examples
use llm::builder::{LLMBuilder, LLMBackend};
use llm::memory::TrimStrategy;
let builder = LLMBuilder::new()
.backend(LLMBackend::OpenAI)
.sliding_window_with_strategy(5, TrimStrategy::Summarize);Trait Implementations§
Source§impl Default for LLMBuilder
impl Default for LLMBuilder
Source§fn default() -> LLMBuilder
fn default() -> LLMBuilder
Auto Trait Implementations§
impl Freeze for LLMBuilder
impl !RefUnwindSafe for LLMBuilder
impl Send for LLMBuilder
impl Sync for LLMBuilder
impl Unpin for LLMBuilder
impl !UnwindSafe for LLMBuilder
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more