-
Notifications
You must be signed in to change notification settings - Fork 155
added support for huggingface dataset repositories #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arnab2001
wants to merge
7
commits into
kitops-ml:main
Choose a base branch
from
arnab2001:added-support-for-huggingface-dataset-repositories
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
87cdb11
added support for huggingface dataset repositories
arnab2001 81e20e7
Resolved Code Comments (Created typed enums, Hf-specific logic sepera…
arnab2001 b52bd5f
remove agent marker
arnab2001 61c15ea
Add Apache 2.0 license header to repo.go
arnab2001 eb35533
fixed dco issues
arnab2001 a87b7c4
formatting issues fixed
arnab2001 6d23881
resolved comments
arnab2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright 2025 The KitOps Authors. | ||
| // | ||
| // Licensed 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package hf | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
| "strings" | ||
| ) | ||
|
|
||
| // RepositoryType represents the kind of Hugging Face repository. | ||
| type RepositoryType int | ||
|
|
||
| const ( | ||
| RepoTypeUnknown RepositoryType = iota | ||
| RepoTypeModel | ||
| RepoTypeDataset | ||
| ) | ||
|
|
||
| // ParseHuggingFaceRepo parses a Hugging Face repository URL or path and returns | ||
| // the normalized repository path (org/repo) and the repository type. | ||
| func ParseHuggingFaceRepo(rawURL string) (string, RepositoryType, error) { | ||
| u, err := url.Parse(rawURL) | ||
| if err != nil { | ||
| return "", RepoTypeUnknown, fmt.Errorf("failed to parse url: %w", err) | ||
| } | ||
|
|
||
| if u.Host != "" && !strings.Contains(u.Host, "huggingface.co") { | ||
| return "", RepoTypeUnknown, fmt.Errorf("not a Hugging Face repository") | ||
| } | ||
|
|
||
| path := strings.Trim(u.Path, "/") | ||
| segments := strings.Split(path, "/") | ||
|
|
||
| if len(segments) >= 3 && segments[0] == "datasets" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return strings.Join(segments[1:3], "/"), RepoTypeDataset, nil | ||
| } | ||
| if len(segments) == 2 && segments[0] == "datasets" { | ||
| return "", RepoTypeUnknown, fmt.Errorf("could not extract repository from path '%s'", path) | ||
| } | ||
|
|
||
| if len(segments) >= 2 { | ||
| return strings.Join(segments[len(segments)-2:], "/"), RepoTypeModel, nil | ||
| } | ||
|
|
||
| return "", RepoTypeUnknown, fmt.Errorf("could not extract repository from path '%s'", path) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright 2025 The KitOps Authors. | ||
| // | ||
| // Licensed 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package hf | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestParseHuggingFaceRepo(t *testing.T) { | ||
| testcases := []struct { | ||
| input string | ||
| expectedRepo string | ||
| expectedType RepositoryType | ||
| expectErrRegexp string | ||
| }{ | ||
| {input: "https://huggingface.co/org/repo", expectedRepo: "org/repo", expectedType: RepoTypeModel}, | ||
| {input: "https://huggingface.co/datasets/org/repo", expectedRepo: "org/repo", expectedType: RepoTypeDataset}, | ||
| {input: "org/repo", expectedRepo: "org/repo", expectedType: RepoTypeModel}, | ||
| {input: "datasets/org/repo", expectedRepo: "org/repo", expectedType: RepoTypeDataset}, | ||
| {input: "datasets/only-one-segment", expectErrRegexp: "could not extract repository"}, | ||
| {input: "https://example.com/org/repo", expectErrRegexp: "not a Hugging Face repository"}, | ||
| } | ||
|
|
||
| for _, tt := range testcases { | ||
| t.Run(fmt.Sprintf("handles %s", tt.input), func(t *testing.T) { | ||
| actualRepo, actualType, actualErr := ParseHuggingFaceRepo(tt.input) | ||
| if tt.expectErrRegexp != "" { | ||
| if !assert.Error(t, actualErr) { | ||
| return | ||
| } | ||
| assert.Regexp(t, tt.expectErrRegexp, actualErr.Error()) | ||
| } else { | ||
| if !assert.NoError(t, actualErr) { | ||
| return | ||
| } | ||
| assert.Equal(t, tt.expectedRepo, actualRepo) | ||
| assert.Equal(t, tt.expectedType, actualType) | ||
| } | ||
| }) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this check, inputs like https://huggingface.co.evil.com/org/repo pass the “is HF” check and proceed as if they were Hugging Face. Can you tighten the parsing and validation of the host?