morristai commented on code in PR #3670: URL: https://github.com/apache/incubator-opendal/pull/3670#discussion_r1410112113
########## core/src/services/huggingface/core.rs: ########## @@ -0,0 +1,182 @@ +// 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::fmt::Debug; + +use bytes::Bytes; +use http::Request; +use http::Response; +use http::{header, StatusCode}; +use serde_json::json; + +use super::backend::RepoType; +use super::error::parse_error; +use crate::raw::*; +use crate::*; + +pub struct HuggingFaceCore { + pub repo_type: RepoType, + pub repo_id: String, + pub revision: String, + pub root: String, + pub read_token: Option<String>, + + pub client: HttpClient, +} + +impl Debug for HuggingFaceCore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("HuggingFaceCore") + .field("repo_type", &self.repo_type) + .field("repo_id", &self.repo_id) + .field("revision", &self.revision) + .field("root", &self.root) + .finish_non_exhaustive() + } +} + +impl HuggingFaceCore { + pub async fn hf_path_info(&self, path: &str) -> Result<Response<IncomingAsyncBody>> { + let p = build_abs_path(&self.root, path) + .trim_end_matches('/') + .to_string(); + + let url = match self.repo_type { + RepoType::Model => format!( + "https://huggingface.co/api/models/{}/paths-info/{}", Review Comment: I don't have a "common sense" of when we should use an enum and when we should not. Can you enlighten me on why it's better not to use an enum in this case? 🙏 ########## core/src/services/huggingface/core.rs: ########## @@ -0,0 +1,182 @@ +// 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::fmt::Debug; + +use bytes::Bytes; +use http::Request; +use http::Response; +use http::{header, StatusCode}; +use serde_json::json; + +use super::backend::RepoType; +use super::error::parse_error; +use crate::raw::*; +use crate::*; + +pub struct HuggingFaceCore { + pub repo_type: RepoType, + pub repo_id: String, + pub revision: String, + pub root: String, + pub read_token: Option<String>, + + pub client: HttpClient, +} + +impl Debug for HuggingFaceCore { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("HuggingFaceCore") + .field("repo_type", &self.repo_type) + .field("repo_id", &self.repo_id) + .field("revision", &self.revision) + .field("root", &self.root) + .finish_non_exhaustive() + } +} + +impl HuggingFaceCore { + pub async fn hf_path_info(&self, path: &str) -> Result<Response<IncomingAsyncBody>> { + let p = build_abs_path(&self.root, path) + .trim_end_matches('/') + .to_string(); + + let url = match self.repo_type { + RepoType::Model => format!( + "https://huggingface.co/api/models/{}/paths-info/{}", Review Comment: I don't have a "common sense" of when we should use an enum and when we should not. Can you enlighten me on why it's better not to use an enum in this case? 🙏 -- 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]
