Wauplin commented on code in PR #3670:
URL:
https://github.com/apache/incubator-opendal/pull/3670#discussion_r1407837175
##########
core/src/types/scheme.rs:
##########
@@ -357,6 +362,7 @@ impl From<Scheme> for &'static str {
Scheme::Gridfs => "gridfs",
Scheme::Hdfs => "hdfs",
Scheme::Http => "http",
+ Scheme::HuggingFace => "huggingface",
Review Comment:
The Python library already includes a filesystem interface (based on fsspec)
that uses `hf://` as a scheme. It would be nice to align on this to be
consistent between implementations. See
https://huggingface.co/docs/huggingface_hub/guides/hf_file_system for more
details.
##########
core/src/services/huggingface/docs.md:
##########
@@ -0,0 +1,63 @@
+This service will visit the [HuggingFace
API](https://huggingface.co/docs/huggingface_hub/package_reference/hf_api) to
access the HuggingFace File System.
+Currently, we only support the `model` and `dataset` types of repositories,
and operations are limited to reading and listing/stating.
+
+HuggingFace doesn't host official HTTP API docs. Detailed HTTP request API
information can be found on the [HuggingFace
Hub](https://github.com/huggingface/huggingface_hub).
Review Comment:
Technically, `huggingface_hub` is the name of the Python library to interact
with the Hugging Face Hub (the online platform). So
https://huggingface.co/docs/huggingface_hub/package_reference/hf_api is the
package reference of the Python library (which is a good starting point for
retro engineering). There is some documentation about the API itself (see
[here](https://huggingface.co/docs/hub/api)) but it's not complete yet.
##########
core/src/services/huggingface/mod.rs:
##########
@@ -0,0 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+mod backend;
+pub use backend::HuggingFaceBuilder as HuggingFace;
Review Comment:
I would also advocate for `huggingface` if possible :pray:
##########
core/src/services/huggingface/backend.rs:
##########
@@ -0,0 +1,313 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::StatusCode;
+use log::debug;
+
+use super::core::HuggingFaceCore;
+use super::error::parse_error;
+use super::lister::HuggingFaceLister;
+use super::message::HuggingFaceStatus;
+use crate::raw::*;
+use crate::*;
+
+///
[HuggingFace](https://huggingface.co/docs/huggingface_hub/package_reference/hf_api)'s
API support.
+#[doc = include_str!("docs.md")]
+#[derive(Default, Clone)]
+pub struct HuggingFaceBuilder {
+ repo_type: Option<String>,
+ repo_id: Option<String>,
+ revision: Option<String>,
+ root: Option<String>,
+ read_token: Option<String>,
+}
+
+impl Debug for HuggingFaceBuilder {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ let mut ds = f.debug_struct("Builder");
+
+ ds.field("repo_type", &self.repo_type);
+ ds.field("repo_id", &self.repo_id);
+ ds.field("revision", &self.revision);
+ ds.field("root", &self.root);
+
+ if self.read_token.is_some() {
+ ds.field("read_token", &"<redacted>");
+ }
+
+ ds.finish()
+ }
+}
+
+impl HuggingFaceBuilder {
+ /// Set repo type of this backend. Default is model.
+ ///
+ /// Available values:
+ /// - model
+ /// - dataset
+ ///
+ /// Currently, only models and datasets are supported.
+ /// [Reference](https://huggingface.co/docs/hub/repositories)
+ pub fn repo_type(&mut self, repo_type: &str) -> &mut Self {
+ if !repo_type.is_empty() {
+ self.repo_type = Some(repo_type.to_string());
+ }
+ self
+ }
+
+ /// Set repo id of this backend. This is required.
+ ///
+ /// Repo id consists of the account name and the repository name.
+ ///
+ /// For example, model's repo id looks like:
+ /// - meta-llama/Llama-2-7b
+ ///
+ /// Dataset's repo id looks like:
+ /// - databricks/databricks-dolly-15k
+ pub fn repo_id(&mut self, repo_id: &str) -> &mut Self {
+ if !repo_id.is_empty() {
+ self.repo_id = Some(repo_id.to_string());
+ }
+ self
+ }
+
+ /// Set revision of this backend. Default is main.
+ ///
+ /// Revision can be a branch name or a commit hash.
+ ///
+ /// For example, revision can be:
+ /// - main
+ /// - 1d0c4eb
+ pub fn revision(&mut self, revision: &str) -> &mut Self {
+ if !revision.is_empty() {
+ self.revision = Some(revision.to_string());
+ }
+ self
+ }
+
+ /// Set root of this backend.
+ ///
+ /// All operations will happen under this root.
+ pub fn root(&mut self, root: &str) -> &mut Self {
+ if !root.is_empty() {
+ self.root = Some(root.to_string());
+ }
+ self
+ }
+
+ /// Set the read token of this backend.
+ ///
+ /// This is optional.
Review Comment:
I would also name it `token` to be consistent with the existing huggingface
ecosystem (not only the HF libraries but also third-party libraries integrated
with the Hub). At the moment, tokens are mostly `read` or `write` it is not set
in stone. We recently introduced in beta tokens that have other types of
permissions (`api-inference` for instance). So I wouldn't differentiate token
types here and name everything `token`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]