Skip to main content

ModelCard

Struct ModelCard 

Source
pub struct ModelCard {
Show 15 fields pub id: String, pub display_name: Option<String>, pub aliases: Vec<String>, pub model_type: ModelType, pub hf_model_type: Option<String>, pub architectures: Vec<String>, pub provider: Option<ProviderType>, pub context_length: Option<u32>, pub tokenizer_path: Option<String>, pub chat_template: Option<String>, pub reasoning_parser: Option<String>, pub tool_parser: Option<String>, pub metadata: Option<Value>, pub id2label: HashMap<u32, String>, pub num_labels: u32,
}
Expand description

Model card containing model configuration and capabilities.

§Example

use openai_protocol::{model_type::ModelType, model_card::ModelCard, worker::ProviderType};

let card = ModelCard::new("meta-llama/Llama-3.1-8B-Instruct")
    .with_display_name("Llama 3.1 8B Instruct")
    .with_alias("llama-3.1-8b")
    .with_model_type(ModelType::VISION_LLM)
    .with_context_length(128_000)
    .with_tokenizer_path("meta-llama/Llama-3.1-8B-Instruct");

assert!(card.matches("llama-3.1-8b"));
assert!(card.model_type.supports_vision());
assert!(card.provider.is_none()); // Local model, no external provider

Fields§

§id: String

Primary model ID (e.g., “meta-llama/Llama-3.1-8B-Instruct”)

§display_name: Option<String>

Optional display name (e.g., “Llama 3.1 8B Instruct”)

§aliases: Vec<String>

Alternative names/aliases for this model

§model_type: ModelType

Supported endpoint types (bitflags)

§hf_model_type: Option<String>

HuggingFace model type string (e.g., “llama”, “qwen2”, “gpt-oss”)

§architectures: Vec<String>

Model architectures from HuggingFace config (e.g., [“LlamaForCausalLM”])

§provider: Option<ProviderType>

Provider hint for API transformations. None means native/passthrough (no transformation needed).

§context_length: Option<u32>

Maximum context length in tokens

§tokenizer_path: Option<String>

Path to tokenizer (e.g., HuggingFace model ID or local path)

§chat_template: Option<String>

Chat template (Jinja2 template string or path)

§reasoning_parser: Option<String>

Reasoning parser type (e.g., “deepseek”, “qwen”)

§tool_parser: Option<String>

Tool/function calling parser type (e.g., “llama”, “mistral”)

§metadata: Option<Value>

User-defined metadata (for fields not covered above)

§id2label: HashMap<u32, String>

Classification label mapping (class index -> label name). Empty if not a classification model.

§num_labels: u32

Number of classification labels (0 if not a classifier).

Implementations§

Source§

impl ModelCard

Source

pub fn new(id: impl Into<String>) -> Self

Create a new model card with minimal configuration.

Defaults to ModelType::LLM and no provider (native/passthrough).

Source

pub fn with_display_name(self, name: impl Into<String>) -> Self

Set the display name

Source

pub fn with_alias(self, alias: impl Into<String>) -> Self

Add a single alias

Source

pub fn with_aliases( self, aliases: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Add multiple aliases

Source

pub fn with_model_type(self, model_type: ModelType) -> Self

Set the model type (capabilities)

Source

pub fn with_hf_model_type(self, hf_model_type: impl Into<String>) -> Self

Set the HuggingFace model type string

Source

pub fn with_architectures(self, architectures: Vec<String>) -> Self

Set the model architectures

Source

pub fn with_provider(self, provider: ProviderType) -> Self

Set the provider type (for external API transformations)

Source

pub fn with_context_length(self, length: u32) -> Self

Set the context length

Source

pub fn with_tokenizer_path(self, path: impl Into<String>) -> Self

Set the tokenizer path

Source

pub fn with_chat_template(self, template: impl Into<String>) -> Self

Set the chat template

Source

pub fn with_reasoning_parser(self, parser: impl Into<String>) -> Self

Set the reasoning parser type

Source

pub fn with_tool_parser(self, parser: impl Into<String>) -> Self

Set the tool parser type

Source

pub fn with_metadata(self, metadata: Value) -> Self

Set custom metadata

Source

pub fn with_id2label(self, id2label: HashMap<u32, String>) -> Self

Set the id2label mapping for classification models

Source

pub fn with_num_labels(self, num_labels: u32) -> Self

Set num_labels directly (alternative to with_id2label)

Source

pub fn matches(&self, model_id: &str) -> bool

Check if this model matches the given ID (including aliases)

Source

pub fn supports_endpoint(&self, endpoint: Endpoint) -> bool

Check if this model supports a given endpoint

Source

pub fn name(&self) -> &str

Get the display name or fall back to ID

Source

pub fn is_native(&self) -> bool

Check if this is a native/local model (no external provider)

Source

pub fn has_external_provider(&self) -> bool

Check if this model uses an external provider

Source

pub fn is_llm(&self) -> bool

Check if this is an LLM (supports chat)

Source

pub fn is_embedding_model(&self) -> bool

Check if this is an embedding model

Source

pub fn supports_vision(&self) -> bool

Check if this model supports vision/multimodal

Source

pub fn supports_tools(&self) -> bool

Check if this model supports tools/function calling

Source

pub fn supports_reasoning(&self) -> bool

Check if this model supports reasoning

Source

pub fn is_classifier(&self) -> bool

Check if this is a classification model

Source

pub fn get_label(&self, class_idx: u32) -> String

Get label for a class index, with fallback to generic label (LABEL_N)

Trait Implementations§

Source§

impl Clone for ModelCard

Source§

fn clone(&self) -> ModelCard

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 ModelCard

Source§

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

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

impl Default for ModelCard

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ModelCard

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ModelCard

Source§

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

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

impl Serialize for ModelCard

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

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,