Skip to content

使用新的aistudio sdk下载模型文件,上传功能不受影响 #10723

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
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions paddlenlp/transformers/aistudio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from typing import Optional

from aistudio_sdk.hub import download
from aistudio_sdk.file_download import model_file_download


class UnauthorizedError(Exception):
Expand Down Expand Up @@ -42,26 +42,6 @@
if revision is None:
revision = "master"
filename = _add_subfolder(filename, subfolder)
download_kwargs = {}
if revision is not None:
download_kwargs["revision"] = revision
if cache_dir is not None:
download_kwargs["cache_dir"] = cache_dir
res = download(
repo_id=repo_id,
filename=filename,
**download_kwargs,
return model_file_download(

Check warning on line 45 in paddlenlp/transformers/aistudio_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/aistudio_utils.py#L45

Added line #L45 was not covered by tests
repo_id=repo_id, file_path=filename, revision=revision, local_dir=cache_dir if cache_dir is not None else None
)
if "path" in res:
return res["path"]
else:
if res["error_code"] == 10001:
raise ValueError("Illegal argument error")
elif res["error_code"] == 10002:
raise UnauthorizedError(
"Unauthorized Access. Please ensure that you have provided the AIStudio Access Token and you have access to the requested asset"
)
elif res["error_code"] == 12001:
raise EntryNotFoundError(f"Cannot find the requested file '{filename}' in repo '{repo_id}'")
else:
raise Exception(f"Unknown error: {res}")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typer
rich
safetensors
fast_dataindex>=0.1.1 ; platform_system == "Linux"
aistudio-sdk==0.2.6
aistudio-sdk>0.2.6
jinja2
regex
numpy<=1.26.4
Expand Down