Skip to main content

ClientBuilder

Struct ClientBuilder 

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

Client 的构建器。

Implementations§

Source§

impl ClientBuilder

Source

pub fn from_env() -> Self

从环境变量构建默认配置。

Source

pub fn provider(self, provider: Provider) -> Self

设置 Provider。

Source

pub fn http_client(self, client: Client) -> Self

注入一个自定义 reqwest::Client

Source

pub fn log_level(self, log_level: LogLevel) -> Self

设置 SDK 内部日志级别。

Source

pub fn logger<L>(self, logger: L) -> Self
where L: Logger + 'static,

注入一个用户自定义日志器。

Source

pub fn api_key<T>(self, api_key: T) -> Self
where T: Into<String>,

设置静态 API Key。

Source

pub fn api_key_provider<F>(self, provider: F) -> Self
where F: Fn() -> Result<SecretString> + Send + Sync + 'static,

设置动态 API Key 回调。

Source

pub fn api_key_async_provider<F, Fut>(self, provider: F) -> Self
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<SecretString>> + Send + 'static,

设置异步 API Key 回调。

Source

pub fn base_url<T>(self, base_url: T) -> Self
where T: Into<String>,

覆盖基础地址。

Source

pub fn disable_proxy_for_local_base_url(self, disable: bool) -> Self

控制当 base_url 指向本机地址时,是否显式关闭系统代理。

该开关默认关闭。

Source

pub fn azure_endpoint<T>(self, endpoint: T) -> Self
where T: Into<String>,

设置 Azure 资源级 endpoint。

该值应类似 https://example-resource.openai.azure.com, SDK 会在发送请求时自动补上 /openai

Source

pub fn azure_api_version<T>(self, api_version: T) -> Self
where T: Into<String>,

设置 Azure api-version

Source

pub fn azure_deployment<T>(self, deployment: T) -> Self
where T: Into<String>,

设置 Azure 默认 deployment。

Source

pub fn azure_bearer_auth(self) -> Self

切换 Azure 为 Bearer Token 认证。

Source

pub fn azure_ad_token<T>(self, token: T) -> Self
where T: Into<String>,

设置 Azure AD Bearer Token。

Source

pub fn azure_ad_token_provider<F, Fut>(self, provider: F) -> Self
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<SecretString>> + Send + 'static,

设置 Azure AD Bearer Token 异步提供器。

Source

pub fn timeout(self, timeout: Duration) -> Self

覆盖默认超时时间。

Source

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

覆盖默认最大重试次数。

Source

pub fn default_header<T, U>(self, key: T, value: U) -> Self
where T: Into<String>, U: Into<String>,

添加默认请求头。

Source

pub fn default_headers(self, headers: BTreeMap<String, String>) -> Self

批量设置默认请求头。

Source

pub fn default_query<T, U>(self, key: T, value: U) -> Self
where T: Into<String>, U: Into<String>,

添加默认查询参数。

Source

pub fn default_query_map(self, query: BTreeMap<String, String>) -> Self

批量设置默认查询参数。

Source

pub fn webhook_secret<T>(self, secret: T) -> Self
where T: Into<String>,

设置 Webhook 密钥。

Source

pub fn compatibility_mode(self, mode: CompatibilityMode) -> Self

设置兼容性模式。

Source

pub fn build(self) -> Result<Client>

构建客户端。

§Errors

当基础地址非法或底层 reqwest::Client 初始化失败时返回错误。

Trait Implementations§

Source§

impl Clone for ClientBuilder

Source§

fn clone(&self) -> ClientBuilder

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 Debug for ClientBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ClientBuilder

Source§

fn default() -> ClientBuilder

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> Same for T

Source§

type Output = T

Should always be Self
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