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 providerFields§
§id: StringPrimary 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: ModelTypeSupported 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: u32Number of classification labels (0 if not a classifier).
Implementations§
Source§impl ModelCard
impl ModelCard
Sourcepub fn new(id: impl Into<String>) -> Self
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).
Sourcepub fn with_display_name(self, name: impl Into<String>) -> Self
pub fn with_display_name(self, name: impl Into<String>) -> Self
Set the display name
Sourcepub fn with_alias(self, alias: impl Into<String>) -> Self
pub fn with_alias(self, alias: impl Into<String>) -> Self
Add a single alias
Sourcepub fn with_aliases(
self,
aliases: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_aliases( self, aliases: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Add multiple aliases
Sourcepub fn with_model_type(self, model_type: ModelType) -> Self
pub fn with_model_type(self, model_type: ModelType) -> Self
Set the model type (capabilities)
Sourcepub fn with_hf_model_type(self, hf_model_type: impl Into<String>) -> Self
pub fn with_hf_model_type(self, hf_model_type: impl Into<String>) -> Self
Set the HuggingFace model type string
Sourcepub fn with_architectures(self, architectures: Vec<String>) -> Self
pub fn with_architectures(self, architectures: Vec<String>) -> Self
Set the model architectures
Sourcepub fn with_provider(self, provider: ProviderType) -> Self
pub fn with_provider(self, provider: ProviderType) -> Self
Set the provider type (for external API transformations)
Sourcepub fn with_context_length(self, length: u32) -> Self
pub fn with_context_length(self, length: u32) -> Self
Set the context length
Sourcepub fn with_tokenizer_path(self, path: impl Into<String>) -> Self
pub fn with_tokenizer_path(self, path: impl Into<String>) -> Self
Set the tokenizer path
Sourcepub fn with_chat_template(self, template: impl Into<String>) -> Self
pub fn with_chat_template(self, template: impl Into<String>) -> Self
Set the chat template
Sourcepub fn with_reasoning_parser(self, parser: impl Into<String>) -> Self
pub fn with_reasoning_parser(self, parser: impl Into<String>) -> Self
Set the reasoning parser type
Sourcepub fn with_tool_parser(self, parser: impl Into<String>) -> Self
pub fn with_tool_parser(self, parser: impl Into<String>) -> Self
Set the tool parser type
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
Set custom metadata
Sourcepub fn with_id2label(self, id2label: HashMap<u32, String>) -> Self
pub fn with_id2label(self, id2label: HashMap<u32, String>) -> Self
Set the id2label mapping for classification models
Sourcepub fn with_num_labels(self, num_labels: u32) -> Self
pub fn with_num_labels(self, num_labels: u32) -> Self
Set num_labels directly (alternative to with_id2label)
Sourcepub fn matches(&self, model_id: &str) -> bool
pub fn matches(&self, model_id: &str) -> bool
Check if this model matches the given ID (including aliases)
Sourcepub fn supports_endpoint(&self, endpoint: Endpoint) -> bool
pub fn supports_endpoint(&self, endpoint: Endpoint) -> bool
Check if this model supports a given endpoint
Sourcepub fn has_external_provider(&self) -> bool
pub fn has_external_provider(&self) -> bool
Check if this model uses an external provider
Sourcepub fn is_embedding_model(&self) -> bool
pub fn is_embedding_model(&self) -> bool
Check if this is an embedding model
Sourcepub fn supports_vision(&self) -> bool
pub fn supports_vision(&self) -> bool
Check if this model supports vision/multimodal
Sourcepub fn supports_tools(&self) -> bool
pub fn supports_tools(&self) -> bool
Check if this model supports tools/function calling
Sourcepub fn supports_reasoning(&self) -> bool
pub fn supports_reasoning(&self) -> bool
Check if this model supports reasoning
Sourcepub fn is_classifier(&self) -> bool
pub fn is_classifier(&self) -> bool
Check if this is a classification model
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ModelCard
impl<'de> Deserialize<'de> for ModelCard
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for ModelCard
impl JsonSchema for ModelCard
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read more