gglib_core/ports/huggingface/
client.rs

1//! `HuggingFace` client port trait.
2
3use super::error::HfPortResult;
4use super::types::{HfFileInfo, HfQuantInfo, HfRepoInfo, HfSearchOptions, HfSearchResult};
5use async_trait::async_trait;
6
7/// Port trait for `HuggingFace` Hub operations.
8///
9/// This trait defines the interface that the core domain uses to interact
10/// with `HuggingFace`. The implementation lives in `gglib-hf`.
11///
12/// # Design
13///
14/// - Uses core-owned DTOs, not `HuggingFace` API types
15/// - Returns `HfPortError` for all failures
16/// - Async methods for network operations
17/// - No implementation details leak through this interface
18#[async_trait]
19pub trait HfClientPort: Send + Sync {
20    /// Search for GGUF models on `HuggingFace`.
21    async fn search(&self, options: &HfSearchOptions) -> HfPortResult<HfSearchResult>;
22
23    /// List available quantizations for a model.
24    ///
25    /// # Arguments
26    ///
27    /// * `model_id` - Full model ID (e.g., `TheBloke/Llama-2-7B-GGUF`)
28    async fn list_quantizations(&self, model_id: &str) -> HfPortResult<Vec<HfQuantInfo>>;
29
30    /// List all GGUF files in a model repository.
31    ///
32    /// # Arguments
33    ///
34    /// * `model_id` - Full model ID
35    async fn list_gguf_files(&self, model_id: &str) -> HfPortResult<Vec<HfFileInfo>>;
36
37    /// Get files for a specific quantization.
38    ///
39    /// Returns (path, size) tuples for all files in the quantization,
40    /// sorted for correct shard ordering.
41    ///
42    /// # Arguments
43    ///
44    /// * `model_id` - Full model ID
45    /// * `quantization` - Quantization name (e.g., `Q4_K_M`)
46    async fn get_quantization_files(
47        &self,
48        model_id: &str,
49        quantization: &str,
50    ) -> HfPortResult<Vec<(String, u64)>>;
51
52    /// Get the current commit SHA for a model.
53    ///
54    /// Used for version tracking and update detection.
55    async fn get_commit_sha(&self, model_id: &str) -> HfPortResult<String>;
56
57    /// Get detailed information about a model.
58    async fn get_model_info(&self, model_id: &str) -> HfPortResult<HfRepoInfo>;
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64    use std::sync::Arc;
65
66    // Verify the trait is object-safe
67    fn _assert_object_safe(_: Arc<dyn HfClientPort>) {}
68}