pub struct ClientBuilder<Ext, ApiKey = Missing, H = Missing> { /* private fields */ }Expand description
Type-state builder for Client.
Each generic slot encodes a separate “has the user supplied this yet?” question:
ApiKey = Missingmeans the caller has not yet calledSelf::api_key; transitioning to a concreteApiKeytype is required beforeSelf::buildis reachable.H = Missingmeans the caller has not yet calledSelf::http_client; in that statebuild()substitutes the canonicalreqwest::Clientbackend at construction time. Once a backend has been supplied,His the concrete HTTP client type andbuild()uses it directly.
Keeping Missing as the type-level placeholder (rather than reusing reqwest::Client)
means the builder’s generics describe what the caller has actually provided, instead of
pretending a default value is already present. It also avoids carrying an Option<H> whose
None branch existed only to model the same “user hasn’t picked a backend” state.
Implementations§
Source§impl<Ext, H> ClientBuilder<Ext, Missing, H>
impl<Ext, H> ClientBuilder<Ext, Missing, H>
Sourcepub fn api_key<ApiKey>(
self,
api_key: impl Into<ApiKey>,
) -> ClientBuilder<Ext, ApiKey, H>
pub fn api_key<ApiKey>( self, api_key: impl Into<ApiKey>, ) -> ClientBuilder<Ext, ApiKey, H>
Set the API key for this client. This must be done before the build method can be
called
Source§impl<Ext, ApiKey, H> ClientBuilder<Ext, ApiKey, H>where
Ext: Clone,
impl<Ext, ApiKey, H> ClientBuilder<Ext, ApiKey, H>where
Ext: Clone,
Sourcepub fn http_client<U>(self, http_client: U) -> ClientBuilder<Ext, ApiKey, U>
pub fn http_client<U>(self, http_client: U) -> ClientBuilder<Ext, ApiKey, U>
Set the HTTP backend used in this client.
Calling this advances the builder’s H slot from whatever it was (typically Missing)
to the supplied client’s type, which selects the H-generic Self::build impl below.
Sourcepub fn http_headers(self, headers: HeaderMap) -> Self
pub fn http_headers(self, headers: HeaderMap) -> Self
Set the HTTP headers used in this client
Source§impl<Ext, Key, H> ClientBuilder<Ext, Key, H>
impl<Ext, Key, H> ClientBuilder<Ext, Key, H>
Source§impl<ExtBuilder, Key> ClientBuilder<ExtBuilder, Key, Missing>where
ExtBuilder: ProviderBuilder<ApiKey = Key>,
Key: ApiKey,
Default-backend build: when the caller never called ClientBuilder::http_client, the
builder’s H slot is still Missing, and we substitute the canonical reqwest::Client at
build time. This is the only place in the crate that knows about that default, and it is
disjoint by trait bound from the H-generic build below (Missing does not implement
HttpClientExt).
impl<ExtBuilder, Key> ClientBuilder<ExtBuilder, Key, Missing>where
ExtBuilder: ProviderBuilder<ApiKey = Key>,
Key: ApiKey,
Default-backend build: when the caller never called ClientBuilder::http_client, the
builder’s H slot is still Missing, and we substitute the canonical reqwest::Client at
build time. This is the only place in the crate that knows about that default, and it is
disjoint by trait bound from the H-generic build below (Missing does not implement
HttpClientExt).
Source§impl<ExtBuilder, Key, H> ClientBuilder<ExtBuilder, Key, H>
Concrete-backend build: the caller supplied an HTTP client via
ClientBuilder::http_client, so H is a real HttpClientExt type and we use it directly.
impl<ExtBuilder, Key, H> ClientBuilder<ExtBuilder, Key, H>
Concrete-backend build: the caller supplied an HTTP client via
ClientBuilder::http_client, so H is a real HttpClientExt type and we use it directly.
Source§impl<H> ClientBuilder<AnthropicBuilder, AnthropicKey, H>
Create a new anthropic client using the builder
impl<H> ClientBuilder<AnthropicBuilder, AnthropicKey, H>
Create a new anthropic client using the builder
§Example
use rig_core::providers::anthropic::{Client, self};
use rig_core::providers::anthropic::completion::ANTHROPIC_VERSION_LATEST;
// Initialize the Anthropic client
let anthropic_client = Client::builder()
.api_key("your-claude-api-key")
.anthropic_version(ANTHROPIC_VERSION_LATEST)
.anthropic_beta("prompt-caching-2024-07-31")
.build()?;pub fn anthropic_version(self, anthropic_version: &str) -> Self
pub fn anthropic_betas(self, anthropic_betas: &[&str]) -> Self
pub fn anthropic_beta(self, anthropic_beta: &str) -> Self
Source§impl<H> ClientBuilder<AzureExtBuilder, AzureOpenAIAuth, H>
impl<H> ClientBuilder<AzureExtBuilder, AzureOpenAIAuth, H>
Sourcepub fn api_version(self, api_version: &str) -> Self
pub fn api_version(self, api_version: &str) -> Self
API version to use (e.g., “2024-10-21” for GA, “2024-10-01-preview” for preview)
Source§impl<H> ClientBuilder<AzureExtBuilder, AzureOpenAIAuth, H>
impl<H> ClientBuilder<AzureExtBuilder, AzureOpenAIAuth, H>
Sourcepub fn azure_endpoint(self, endpoint: String) -> ClientBuilder<H>
pub fn azure_endpoint(self, endpoint: String) -> ClientBuilder<H>
Azure OpenAI endpoint URL, for example: https://{your-resource-name}.openai.azure.com
Source§impl<H> ClientBuilder<ChatGPTBuilder, Missing, H>
impl<H> ClientBuilder<ChatGPTBuilder, Missing, H>
pub fn oauth(self) -> ClientBuilder<ChatGPTBuilder, ChatGPTAuth, H>
Source§impl<H> ClientBuilder<ChatGPTBuilder, ChatGPTAuth, H>
impl<H> ClientBuilder<ChatGPTBuilder, ChatGPTAuth, H>
pub fn on_device_code<F>(self, handler: F) -> Self
pub fn token_dir(self, path: impl AsRef<Path>) -> Self
pub fn auth_file(self, path: impl AsRef<Path>) -> Self
pub fn default_instructions(self, instructions: impl Into<String>) -> Self
pub fn originator(self, originator: impl Into<String>) -> Self
pub fn user_agent(self, user_agent: impl Into<String>) -> Self
Source§impl<H> ClientBuilder<CopilotBuilder, Missing, H>
impl<H> ClientBuilder<CopilotBuilder, Missing, H>
pub fn github_access_token( self, access_token: impl Into<String>, ) -> ClientBuilder<CopilotBuilder, CopilotAuth, H>
pub fn oauth(self) -> ClientBuilder<CopilotBuilder, CopilotAuth, H>
Source§impl<H> ClientBuilder<CopilotBuilder, CopilotAuth, H>
impl<H> ClientBuilder<CopilotBuilder, CopilotAuth, H>
pub fn on_device_code<F>(self, handler: F) -> Self
pub fn token_dir(self, path: impl AsRef<Path>) -> Self
pub fn access_token_file(self, path: impl AsRef<Path>) -> Self
pub fn api_key_file(self, path: impl AsRef<Path>) -> Self
Source§impl<T> ClientBuilder<GaladrielBuilder, BearerAuth, T>
impl<T> ClientBuilder<GaladrielBuilder, BearerAuth, T>
pub fn fine_tune_api_key<S>(self, fine_tune_api_key: S) -> Self
Source§impl<H> ClientBuilder<HuggingFaceBuilder, BearerAuth, H>
impl<H> ClientBuilder<HuggingFaceBuilder, BearerAuth, H>
pub fn subprovider(self, subprovider: SubProvider) -> Self
Source§impl<H> ClientBuilder<MiniMaxBuilder, BearerAuth, H>
impl<H> ClientBuilder<MiniMaxBuilder, BearerAuth, H>
Source§impl<H> ClientBuilder<MiniMaxAnthropicBuilder, AnthropicKey, H>
impl<H> ClientBuilder<MiniMaxAnthropicBuilder, AnthropicKey, H>
pub fn global(self) -> Self
pub fn china(self) -> Self
pub fn anthropic_version(self, anthropic_version: &str) -> Self
pub fn anthropic_betas(self, anthropic_betas: &[&str]) -> Self
pub fn anthropic_beta(self, anthropic_beta: &str) -> Self
Source§impl<H> ClientBuilder<MoonshotBuilder, BearerAuth, H>
impl<H> ClientBuilder<MoonshotBuilder, BearerAuth, H>
Source§impl<H> ClientBuilder<MoonshotAnthropicBuilder, AnthropicKey, H>
impl<H> ClientBuilder<MoonshotAnthropicBuilder, AnthropicKey, H>
pub fn global(self) -> Self
pub fn anthropic_version(self, anthropic_version: &str) -> Self
pub fn anthropic_betas(self, anthropic_betas: &[&str]) -> Self
pub fn anthropic_beta(self, anthropic_beta: &str) -> Self
Source§impl<H> ClientBuilder<XiaomiMimoAnthropicBuilder, AnthropicKey, H>
impl<H> ClientBuilder<XiaomiMimoAnthropicBuilder, AnthropicKey, H>
pub fn anthropic_version(self, anthropic_version: &str) -> Self
pub fn anthropic_betas(self, anthropic_betas: &[&str]) -> Self
pub fn anthropic_beta(self, anthropic_beta: &str) -> Self
Source§impl<H> ClientBuilder<ZAiBuilder, BearerAuth, H>
impl<H> ClientBuilder<ZAiBuilder, BearerAuth, H>
Source§impl<H> ClientBuilder<ZAiAnthropicBuilder, AnthropicKey, H>
impl<H> ClientBuilder<ZAiAnthropicBuilder, AnthropicKey, H>
pub fn general(self) -> Self
pub fn anthropic_version(self, anthropic_version: &str) -> Self
pub fn anthropic_betas(self, anthropic_betas: &[&str]) -> Self
pub fn anthropic_beta(self, anthropic_beta: &str) -> Self
Trait Implementations§
Source§impl<Ext: Clone, ApiKey: Clone, H: Clone> Clone for ClientBuilder<Ext, ApiKey, H>
impl<Ext: Clone, ApiKey: Clone, H: Clone> Clone for ClientBuilder<Ext, ApiKey, H>
Source§fn clone(&self) -> ClientBuilder<Ext, ApiKey, H>
fn clone(&self) -> ClientBuilder<Ext, ApiKey, H>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<Ext, ApiKey, H> Freeze for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> RefUnwindSafe for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> Send for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> Sync for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> Unpin for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> UnsafeUnpin for ClientBuilder<Ext, ApiKey, H>
impl<Ext, ApiKey, H> UnwindSafe for ClientBuilder<Ext, ApiKey, H>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
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> 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