opendal/services/huggingface/
config.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::fmt::Debug;
19use std::fmt::Formatter;
20
21use super::backend::HuggingfaceBuilder;
22use serde::Deserialize;
23use serde::Serialize;
24
25/// Configuration for Huggingface service support.
26#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct HuggingfaceConfig {
30    /// Repo type of this backend. Default is model.
31    ///
32    /// Available values:
33    /// - model
34    /// - dataset
35    pub repo_type: Option<String>,
36    /// Repo id of this backend.
37    ///
38    /// This is required.
39    pub repo_id: Option<String>,
40    /// Revision of this backend.
41    ///
42    /// Default is main.
43    pub revision: Option<String>,
44    /// Root of this backend. Can be "/path/to/dir".
45    ///
46    /// Default is "/".
47    pub root: Option<String>,
48    /// Token of this backend.
49    ///
50    /// This is optional.
51    pub token: Option<String>,
52}
53
54impl Debug for HuggingfaceConfig {
55    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
56        let mut ds = f.debug_struct("HuggingfaceConfig");
57
58        if let Some(repo_type) = &self.repo_type {
59            ds.field("repo_type", &repo_type);
60        }
61        if let Some(repo_id) = &self.repo_id {
62            ds.field("repo_id", &repo_id);
63        }
64        if let Some(revision) = &self.revision {
65            ds.field("revision", &revision);
66        }
67        if let Some(root) = &self.root {
68            ds.field("root", &root);
69        }
70        if self.token.is_some() {
71            ds.field("token", &"<redacted>");
72        }
73
74        ds.finish()
75    }
76}
77
78impl crate::Configurator for HuggingfaceConfig {
79    type Builder = HuggingfaceBuilder;
80    fn into_builder(self) -> Self::Builder {
81        HuggingfaceBuilder { config: self }
82    }
83}