Skip to main content

llm/usage/
model_identity.rs

1use crate::LlmModel;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use super::ModelPricing;
6
7/// Provider, model id, and catalog pricing of the model serving a call. All
8/// fields are `None` for dynamic or local models the catalog does not know.
9#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
10pub struct ModelIdentity {
11    pub provider: Option<String>,
12    pub model_id: Option<String>,
13    pub pricing: Option<ModelPricing>,
14}
15
16impl ModelIdentity {
17    pub fn of(model: Option<&LlmModel>) -> Self {
18        Self {
19            provider: model.map(|model| model.provider().to_string()),
20            model_id: model.map(|model| model.model_id().into_owned()),
21            pricing: model.and_then(LlmModel::pricing),
22        }
23    }
24}