Skip to main content

ModelOption

Struct ModelOption 

Source
#[non_exhaustive]
pub struct ModelOption { pub value: &'static str, pub label: &'static str, pub context_window: Option<u32>, pub max_output: Option<u32>, }
Expand description

一个模型候选项。

下拉只是建议清单 —— 调用方应当允许用户手填任意 model id,也可以调 crate::model_filter 清洗端点返回的真实清单。所以这里的值过期不会卡死用户。

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§value: &'static str

模型 id,原样传给服务商

§label: &'static str

展示用标签;与 value 相同则调用方直接显示 value

§context_window: Option<u32>

上下文窗口(输入 + 输出总量)的静态兜底值,端点不报时用。

🔴 只在官方文档明确写了时填,且宁可保守 —— 猜大了会让裁历史裁不够, 表现为「明明裁过还是超限」;猜小了只是浪费一点窗口,代价小得多。

None = 不知道。调用方应当让用户手填,而不是自己兜一个默认值。

§max_output: Option<u32>

单次输出上限的静态兜底值。同上,只填文档明确的。

Implementations§

Source§

impl ModelOption

Source

pub const fn plain(value: &'static str) -> Self

标签与 id 相同、且不带限额信息的快捷构造。

绝大多数预置用它 —— 限额优先从端点实时取,静态值只给 「端点不报 + 官方文档明确」的那些模型补。

Source

pub const fn with_limits( value: &'static str, context_window: u32, max_output: u32, ) -> Self

带静态限额兜底的构造。

用于 OpenAI 规范兼容端点 —— 它们的 /models 只返回 {id, object, owned_by},一个限额字段都没有(LM Studio / Ollama 实测如此),不给静态值的话这个能力在那些端点上等于不存在。

⚠️ 这些数字会过时。DeepSeek V3 时代是 128K/8K,V4 已经是 1M/384K —— 半年翻了八倍。所以:端点报了就用端点的,静态值只是端点沉默时的下限保证。

// DeepSeek V4 系官方标称:1M 上下文、384K 输出(2026-09-22 核对)
let m = ModelOption::with_limits("deepseek-flash", 1_000_000, 384_000);
assert_eq!(m.context_window, Some(1_000_000));
Source

pub const fn with_context(value: &'static str, context_window: u32) -> Self

只知道上下文窗口、不知道输出上限时用。

这种情况很常见:多数服务商文档会写「支持 200K 上下文」, 却不单独说明单次输出上限。不知道就是不知道,别拿窗口大小去猜输出上限。

Source

pub fn preset_limits(&self) -> Option<TokenLimits>

这条模型的静态兜底限额;两者都没有时返回 None。

🔴 返回的 TokenLimits 带 source: Preset 标记 —— 调用方据此知道这是估计值、该允许用户修改, 而不是端点保证的事实。

Trait Implementations§

Source§

impl Clone for ModelOption

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 Copy for ModelOption

Source§

impl Debug for ModelOption

Source§

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

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

impl Eq for ModelOption

Source§

impl PartialEq for ModelOption

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ModelOption

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ModelOption

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