Skip to main content

Client

Struct Client 

Source
pub struct Client<CTXEXT, FENSLLM, CUSG> {
    pub ensemble_llm_fetcher: Arc<CachingFetcher<CTXEXT, FENSLLM>>,
    pub usage_handler: Arc<CUSG>,
    pub upstream_client: Client,
    pub backoff_current_interval: Duration,
    pub backoff_initial_interval: Duration,
    pub backoff_randomization_factor: f64,
    pub backoff_multiplier: f64,
    pub backoff_max_interval: Duration,
    pub backoff_max_elapsed_time: Duration,
}
Expand description

Client for creating chat completions.

Handles Ensemble LLM fetching, upstream provider selection with fallbacks, retry logic with exponential backoff, and usage tracking.

Fields§

§ensemble_llm_fetcher: Arc<CachingFetcher<CTXEXT, FENSLLM>>

Caching fetcher for Ensemble LLM definitions.

§usage_handler: Arc<CUSG>

Handler for tracking usage after completion.

§upstream_client: Client

Client for communicating with upstream providers.

§backoff_current_interval: Duration

Current backoff interval for retry logic.

§backoff_initial_interval: Duration

Initial backoff interval for retry logic.

§backoff_randomization_factor: f64

Randomization factor for backoff jitter.

§backoff_multiplier: f64

Multiplier for exponential backoff growth.

§backoff_max_interval: Duration

Maximum backoff interval.

§backoff_max_elapsed_time: Duration

Maximum total time to spend on retries.

Implementations§

Source§

impl<CTXEXT, FENSLLM, CUSG> Client<CTXEXT, FENSLLM, CUSG>

Source

pub fn new( ensemble_llm_fetcher: Arc<CachingFetcher<CTXEXT, FENSLLM>>, usage_handler: Arc<CUSG>, upstream_client: Client, backoff_current_interval: Duration, backoff_initial_interval: Duration, backoff_randomization_factor: f64, backoff_multiplier: f64, backoff_max_interval: Duration, backoff_max_elapsed_time: Duration, ) -> Self

Creates a new chat completions client.

Source§

impl<CTXEXT, FENSLLM, CUSG> Client<CTXEXT, FENSLLM, CUSG>
where CTXEXT: ContextExt + Send + Sync + 'static, FENSLLM: Fetcher<CTXEXT> + Send + Sync + 'static, CUSG: UsageHandler<CTXEXT> + Send + Sync + 'static,

Source

pub async fn create_unary_for_chat_handle_usage( self: Arc<Self>, ctx: Context<CTXEXT>, request: Arc<ChatCompletionCreateParams>, ) -> Result<ChatCompletion, Error>

Creates a unary chat completion, tracking usage after completion.

Internally streams the response and aggregates chunks into a single response.

Source

pub async fn create_streaming_for_chat_handle_usage( self: Arc<Self>, ctx: Context<CTXEXT>, request: Arc<ChatCompletionCreateParams>, ) -> Result<impl Stream<Item = Result<ChatCompletionChunk, Error>> + Send + Unpin + 'static, Error>

Creates a streaming chat completion, tracking usage after the stream ends.

Source

pub async fn create_streaming_for_vector_handle_usage( self: Arc<Self>, ctx: Context<CTXEXT>, request: Arc<VectorCompletionCreateParams>, vector_pfx_indices: Vec<Arc<Vec<(String, usize)>>>, ensemble_llm: EnsembleLlmWithFallbacksAndCount, ) -> Result<impl Stream<Item = Result<ChatCompletionChunk, Error>> + Send + Unpin + 'static, Error>

Creates a streaming completion for vector voting, tracking usage after the stream ends.

Used internally by vector completions to generate LLM votes.

Source§

impl<CTXEXT, FENSLLM, CUSG> Client<CTXEXT, FENSLLM, CUSG>
where CTXEXT: ContextExt + Send + Sync + 'static, FENSLLM: Fetcher<CTXEXT> + Send + Sync + 'static,

Source

pub async fn create_streaming_for_chat( &self, ctx: Context<CTXEXT>, request: Arc<ChatCompletionCreateParams>, ) -> Result<impl Stream<Item = Result<ChatCompletionChunk, Error>> + Send + Unpin + 'static, Error>

Creates a streaming chat completion without usage tracking.

Handles model validation, Ensemble LLM fetching, fallback logic, and retry with exponential backoff.

Source

pub async fn create_streaming_for_vector( &self, ctx: Context<CTXEXT>, request: Arc<VectorCompletionCreateParams>, vector_pfx_indices: Vec<Arc<Vec<(String, usize)>>>, ensemble_llm: EnsembleLlmWithFallbacksAndCount, ) -> Result<impl Stream<Item = Result<ChatCompletionChunk, Error>> + Send + Unpin + 'static, Error>

Creates a streaming completion for vector voting without usage tracking.

Used internally by vector completions. Handles fallback logic and retry with exponential backoff.

Trait Implementations§

Source§

impl<CTXEXT: Clone, FENSLLM: Clone, CUSG: Clone> Clone for Client<CTXEXT, FENSLLM, CUSG>

Source§

fn clone(&self) -> Client<CTXEXT, FENSLLM, CUSG>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<CTXEXT: Debug, FENSLLM: Debug, CUSG: Debug> Debug for Client<CTXEXT, FENSLLM, CUSG>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<CTXEXT, FENSLLM, CUSG> Freeze for Client<CTXEXT, FENSLLM, CUSG>

§

impl<CTXEXT, FENSLLM, CUSG> !RefUnwindSafe for Client<CTXEXT, FENSLLM, CUSG>

§

impl<CTXEXT, FENSLLM, CUSG> Send for Client<CTXEXT, FENSLLM, CUSG>
where CUSG: Sync + Send, FENSLLM: Sync + Send, CTXEXT: Sync + Send,

§

impl<CTXEXT, FENSLLM, CUSG> Sync for Client<CTXEXT, FENSLLM, CUSG>
where CUSG: Sync + Send, FENSLLM: Sync + Send, CTXEXT: Sync + Send,

§

impl<CTXEXT, FENSLLM, CUSG> Unpin for Client<CTXEXT, FENSLLM, CUSG>

§

impl<CTXEXT, FENSLLM, CUSG> !UnwindSafe for Client<CTXEXT, FENSLLM, CUSG>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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