LLMBuilder

Struct LLMBuilder 

Source
pub struct LLMBuilder<L: LLMProvider> {
    pub model: Option<String>,
    pub max_tokens: Option<u32>,
    pub temperature: Option<f32>,
    pub system: Option<String>,
    pub top_p: Option<f32>,
    /* private fields */
}
Expand description

Builder for configuring and instantiating LLM providers.

Provides a fluent interface for setting various configuration options like model selection, API keys, generation parameters, etc.

Fields§

§model: Option<String>

Model identifier/name to use

§max_tokens: Option<u32>

Maximum tokens to generate in responses

§temperature: Option<f32>

Temperature parameter for controlling response randomness (0.0-1.0)

§system: Option<String>

System prompt/context to guide model behavior

§top_p: Option<f32>

Top-p (nucleus) sampling parameter

Implementations§

Source§

impl<L: LLMProvider> LLMBuilder<L>

Source

pub fn new() -> Self

Creates a new empty builder instance with default values.

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 flag.

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 top_p(self, top_p: f32) -> Self

Sets the top-p (nucleus) sampling parameter.

Source

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

Sets the top-k sampling parameter.

Source

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

Sets the encoding format for embeddings.

Source

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

Sets the dimensions for embeddings.

Source

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

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
Source

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

Sets the number of retry attempts for validation failures.

§Arguments
  • attempts - Maximum number of times to retry generating a valid response
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. Note that if the choice is given as Tool(name), and that tool isn’t available, the builder will fail.

Source

pub fn disable_tools(self) -> Self

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

Source

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

Set the API version.

Source

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

Set the deployment id. Used in Azure OpenAI.

Trait Implementations§

Source§

impl<L: LLMProvider> Default for LLMBuilder<L>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<L> Freeze for LLMBuilder<L>

§

impl<L> !RefUnwindSafe for LLMBuilder<L>

§

impl<L> Send for LLMBuilder<L>

§

impl<L> Sync for LLMBuilder<L>

§

impl<L> Unpin for LLMBuilder<L>
where L: Unpin,

§

impl<L> !UnwindSafe for LLMBuilder<L>

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> 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<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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
Source§

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