Skip to main content

entrenar/hf_pipeline/publish/
config.rs

1//! Publishing configuration types
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for publishing a model to HuggingFace Hub
6#[derive(Clone, Debug, Default, Serialize, Deserialize)]
7#[serde(default)]
8pub struct PublishConfig {
9    /// HuggingFace repository ID (e.g., "username/my-model")
10    pub repo_id: String,
11    /// Repository type
12    pub repo_type: RepoType,
13    /// Whether the repository should be private
14    pub private: bool,
15    /// HuggingFace API token (if not set, resolved from env/file)
16    #[serde(skip)]
17    pub token: Option<String>,
18    /// License identifier (e.g., "apache-2.0", "mit")
19    pub license: Option<String>,
20    /// Tags for discoverability
21    pub tags: Vec<String>,
22}
23
24/// HuggingFace repository type
25#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(rename_all = "lowercase")]
27pub enum RepoType {
28    /// Model repository
29    #[default]
30    Model,
31    /// Dataset repository
32    Dataset,
33    /// Space (app) repository
34    Space,
35}
36
37impl RepoType {
38    /// API path segment for this repo type
39    #[must_use]
40    pub fn api_path(&self) -> &'static str {
41        match self {
42            Self::Model => "models",
43            Self::Dataset => "datasets",
44            Self::Space => "spaces",
45        }
46    }
47}
48
49impl std::fmt::Display for RepoType {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        match self {
52            Self::Model => write!(f, "model"),
53            Self::Dataset => write!(f, "dataset"),
54            Self::Space => write!(f, "space"),
55        }
56    }
57}