Skip to main content

LLMBuilder

Struct LLMBuilder 

Source
pub struct LLMBuilder { /* private fields */ }
Expand description

Builder for configuring and instantiating LLM providers.

Implementations§

Source§

impl LLMBuilder

Source

pub fn new() -> Self

Creates a new empty builder instance with default values.

Source

pub fn backend(self, backend: LLMBackend) -> Self

Sets the backend provider to use.

Source

pub fn api_key(self, key: impl Into<String>) -> Self

Sets the API key for authentication.

Source

pub fn base_url(self, url: impl Into<String>) -> Self

Sets the base URL for API requests.

Source

pub fn model(self, model: impl Into<String>) -> Self

Sets the model identifier to use.

Source

pub fn max_tokens(self, max_tokens: u32) -> Self

Sets the maximum number of tokens to generate.

Source

pub fn temperature(self, temperature: f32) -> Self

Sets the temperature for controlling response randomness (0.0-1.0).

Source

pub fn system(self, system: impl Into<String>) -> Self

Sets the system prompt/context.

Source

pub fn reasoning_effort(self, reasoning_effort: ReasoningEffort) -> Self

Sets the reasoning effort level.

Source

pub fn reasoning(self, reasoning: bool) -> Self

Sets the reasoning flag.

Source

pub fn reasoning_budget_tokens(self, reasoning_budget_tokens: u32) -> Self

Sets the reasoning budget tokens.

Source

pub fn timeout_seconds(self, timeout_seconds: u64) -> Self

Sets the request timeout in seconds.

Source

pub fn stream(self, _stream: bool) -> Self

No-op for compatibility (streaming handled by provider traits).

Source

pub fn normalize_response(self, normalize_response: bool) -> Self

Sets whether to normalize responses.

Source

pub fn top_p(self, top_p: f32) -> Self

Sets the top_p sampling parameter.

Source

pub fn top_k(self, top_k: u32) -> Self

Sets the top_k sampling parameter.

Source§

impl LLMBuilder

Source

pub fn validator<F>(self, f: F) -> Self
where F: Fn(&str) -> Result<(), String> + Send + Sync + 'static,

Adds a validator function for responses.

Source

pub fn validator_attempts(self, attempts: usize) -> Self

Sets the number of validation attempts.

Source§

impl LLMBuilder

Source

pub fn schema(self, schema: impl Into<StructuredOutputFormat>) -> Self

Sets the JSON schema for structured output.

Source

pub fn function(self, function_builder: FunctionBuilder) -> Self

Adds a function tool to the builder.

Source

pub fn enable_parallel_tool_use(self, enable: bool) -> Self

Enable parallel tool use.

Source

pub fn tool_choice(self, choice: ToolChoice) -> Self

Set tool choice.

Source

pub fn disable_tools(self) -> Self

Explicitly disable the use of tools, even if they are provided.

Source

pub fn extra_body(self, extra_body: impl Serialize) -> Self

Set extra body JSON for compatible providers.

Source§

impl LLMBuilder

Source

pub fn build(self) -> Result<Box<dyn LLMProvider>, LLMError>

Source§

impl LLMBuilder

Source

pub fn memory(self, memory: impl MemoryProvider + 'static) -> Self

Sets a custom memory provider for conversation history.

Source

pub fn sliding_memory(self, memory: SlidingWindowMemory) -> Self

Sets a sliding window memory provider.

Source

pub fn sliding_window_memory(self, window_size: usize) -> Self

Sets up a sliding window memory with the specified window size.

Source

pub fn sliding_window_with_strategy( self, window_size: usize, strategy: TrimStrategy, ) -> Self

Sets up a sliding window memory with specified trim strategy.

Source§

impl LLMBuilder

Source

pub fn resilient(self, enable: bool) -> Self

Enable resilience retry/backoff wrapper.

Source

pub fn resilient_attempts(self, attempts: usize) -> Self

Sets the number of retry attempts for resilience.

Source

pub fn resilient_backoff(self, base_delay_ms: u64, max_delay_ms: u64) -> Self

Sets base and max backoff delays in milliseconds.

Source

pub fn resilient_jitter(self, jitter: bool) -> Self

Sets jitter toggle for backoff.

Source§

impl LLMBuilder

Enable web search for OpenAI-compatible providers.

Source

pub fn openai_web_search_context_size( self, context_size: impl Into<String>, ) -> Self

Set the web search context size.

Source

pub fn openai_web_search_user_location_type( self, location_type: impl Into<String>, ) -> Self

Set the web search user location type.

Source

pub fn openai_web_search_user_location_approximate_country( self, country: impl Into<String>, ) -> Self

Set the web search user location approximate country.

Source

pub fn openai_web_search_user_location_approximate_city( self, city: impl Into<String>, ) -> Self

Set the web search user location approximate city.

Source

pub fn openai_web_search_user_location_approximate_region( self, region: impl Into<String>, ) -> Self

Set the web search user location approximate region.

Source

pub fn search_mode(self, mode: impl Into<String>) -> Self

👎Deprecated:

Renamed to xai_search_mode.

Backward compatible alias for xAI search mode.

Source

pub fn xai_search_mode(self, mode: impl Into<String>) -> Self

Sets the search mode for search-enabled providers.

Source

pub fn xai_search_source( self, source_type: impl Into<String>, excluded_websites: Option<Vec<String>>, ) -> Self

Adds a search source with optional excluded websites.

Source

pub fn xai_max_search_results(self, max: u32) -> Self

Sets the maximum number of search results.

Source

pub fn xai_search_date_range( self, from: impl Into<String>, to: impl Into<String>, ) -> Self

Sets the date range for search results.

Source

pub fn xai_search_from_date(self, date: impl Into<String>) -> Self

Sets the start date for search results (format: “YYYY-MM-DD”).

Source

pub fn xai_search_to_date(self, date: impl Into<String>) -> Self

Sets the end date for search results (format: “YYYY-MM-DD”).

Source§

impl LLMBuilder

Source

pub fn api_version(self, api_version: impl Into<String>) -> Self

Set the API version (Azure OpenAI).

Source

pub fn deployment_id(self, deployment_id: impl Into<String>) -> Self

Set the deployment id (Azure OpenAI).

Source§

impl LLMBuilder

Source

pub fn embedding_encoding_format(self, format: impl Into<String>) -> Self

Sets the encoding format for embedding outputs.

Source

pub fn embedding_dimensions(self, embedding_dimensions: u32) -> Self

Sets the dimensions for embedding outputs.

Source§

impl LLMBuilder

Source

pub fn voice(self, voice: impl Into<String>) -> Self

Set the voice for TTS providers.

Trait Implementations§

Source§

impl Default for LLMBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSendSync for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more