Skip to main content

Verifier

Struct Verifier 

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

持有一个可复用的 HTTP 客户端。

§为什么要有这个类型

reqwest::Client 内部持有连接池,官方明确要求复用。每次验证都现建一个, 连接池就永远是空的 —— 每次都要重新做 TCP + TLS 握手,跨境端点尤其贵。 「全部验证」这种一次点四下的按钮会连做四次完整握手。

建一次、存起来、反复用:

let verifier = Verifier::new()?;          // 应用启动时建一次
let cfg = ServiceConfig::new(Protocol::OpenAiCompatible, "https://api.deepseek.com/v1");
let ok = verifier.verify(cfg).await?;     // 之后反复用

Implementations§

Source§

impl Verifier

Source

pub fn new() -> Result<Self, VerifyError>

用默认配置建一个。

Source

pub fn from_builder(builder: ClientBuilder) -> Result<Self, VerifyError>

从调用方自备的 builder 建 —— 代理、自定义证书、UA 都在这里配。

存在的理由:代理配置各家差异很大。sigil 用的是 reqwest::Proxy::custom(闭包) 做按 URL 动态路由,不是一个静态代理地址, 任何「传一个代理 URL 字符串」的简化 API 都覆盖不了它。

§🔴 安全默认值由本函数强制施加,调用方覆盖不掉

超时与禁重定向是在你的配置之后加的(reqwest 的 builder 后写覆盖先写)。 禁重定向不容商量:跨 host 跳转时 reqwest 只剥 Authorization 等标准头, 不剥自定义头 —— Anthropic 的 x-api-key 会被原样发往跳转目标。

用本 crate 重导出的 crate::reqwest 来建 builder,版本必然匹配:

let v = Verifier::from_builder(apply_proxy(ai_profile::reqwest::Client::builder()))?;
Source

pub async fn verify( &self, cfg: ServiceConfig<'_>, ) -> Result<VerifyOk, VerifyError>

零成本验证:只打端点的模型列表接口,不产生任何生成费用。

四种 kind 都可调 —— 与 dry_run(真实调用,产生费用)分开正是因为 四者的调用成本差几个数量级。

本方法只借用 &self,可以并发调用(reqwest::Client 自身是 Send + Sync 且内部共享连接池),批量验证多家服务商时直接 join_all 即可。

§错误

每个 VerifyError 变体都对应一个调用方应当给出的动作,见该类型文档。

Trait Implementations§

Source§

impl Clone for Verifier

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Verifier

Source§

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

Formats the value using the given formatter. 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> 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: Sized + 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: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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