forked from mudler/LocalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: be consistent in downloading files, check for scanner errors (mu…
…dler#3108) * fix(downloader): be consistent in downloading files This PR puts some order in the downloader such as functions are re-used across several places. This fixes an issue with having uri's inside the model YAML file, it would resolve to MD5 rather then using the filename Signed-off-by: Ettore Di Giacinto <[email protected]> * fix(scanner): do raise error only if unsafeFiles are found Fixes: mudler#3114 Signed-off-by: Ettore Di Giacinto <[email protected]> --------- Signed-off-by: Ettore Di Giacinto <[email protected]>
- Loading branch information
Showing
13 changed files
with
173 additions
and
171 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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,49 @@ | ||
package downloader | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type HuggingFaceScanResult struct { | ||
RepositoryId string `json:"repositoryId"` | ||
Revision string `json:"revision"` | ||
HasUnsafeFiles bool `json:"hasUnsafeFile"` | ||
ClamAVInfectedFiles []string `json:"clamAVInfectedFiles"` | ||
DangerousPickles []string `json:"dangerousPickles"` | ||
ScansDone bool `json:"scansDone"` | ||
} | ||
|
||
var ErrNonHuggingFaceFile = errors.New("not a huggingface repo") | ||
var ErrUnsafeFilesFound = errors.New("unsafe files found") | ||
|
||
func HuggingFaceScan(uri URI) (*HuggingFaceScanResult, error) { | ||
cleanParts := strings.Split(uri.ResolveURL(), "/") | ||
if len(cleanParts) <= 4 || cleanParts[2] != "huggingface.co" { | ||
return nil, ErrNonHuggingFaceFile | ||
} | ||
results, err := http.Get(fmt.Sprintf("https://huggingface.co/api/models/%s/%s/scan", cleanParts[3], cleanParts[4])) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if results.StatusCode != 200 { | ||
return nil, fmt.Errorf("unexpected status code during HuggingFaceScan: %d", results.StatusCode) | ||
} | ||
scanResult := &HuggingFaceScanResult{} | ||
bodyBytes, err := io.ReadAll(results.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = json.Unmarshal(bodyBytes, scanResult) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if scanResult.HasUnsafeFiles { | ||
return scanResult, ErrUnsafeFilesFound | ||
} | ||
return scanResult, nil | ||
} |
Oops, something went wrong.