mirror of
https://github.com/modelscope/modelscope.git
synced 2026-02-25 04:30:48 +01:00
[to #45451935]fix: add create model detail log for create failed.
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10382795
This commit is contained in:
@@ -24,8 +24,8 @@ from modelscope.utils.constant import (DEFAULT_DATASET_REVISION,
|
||||
DownloadMode)
|
||||
from modelscope.utils.logger import get_logger
|
||||
from .errors import (InvalidParameter, NotExistError, RequestError,
|
||||
datahub_raise_on_error, handle_http_response, is_ok,
|
||||
raise_on_error)
|
||||
datahub_raise_on_error, handle_http_post_error,
|
||||
handle_http_response, is_ok, raise_on_error)
|
||||
from .utils.utils import (get_dataset_hub_endpoint, get_endpoint,
|
||||
model_id_to_group_owner_name)
|
||||
|
||||
@@ -105,17 +105,15 @@ class HubApi:
|
||||
|
||||
path = f'{self.endpoint}/api/v1/models'
|
||||
owner_or_group, name = model_id_to_group_owner_name(model_id)
|
||||
r = requests.post(
|
||||
path,
|
||||
json={
|
||||
'Path': owner_or_group,
|
||||
'Name': name,
|
||||
'ChineseName': chinese_name,
|
||||
'Visibility': visibility, # server check
|
||||
'License': license
|
||||
},
|
||||
cookies=cookies)
|
||||
r.raise_for_status()
|
||||
body = {
|
||||
'Path': owner_or_group,
|
||||
'Name': name,
|
||||
'ChineseName': chinese_name,
|
||||
'Visibility': visibility, # server check
|
||||
'License': license
|
||||
}
|
||||
r = requests.post(path, json=body, cookies=cookies)
|
||||
handle_http_post_error(r, path, body)
|
||||
raise_on_error(r.json())
|
||||
model_repo_url = f'{get_endpoint()}/{model_id}'
|
||||
return model_repo_url
|
||||
|
||||
@@ -4,6 +4,10 @@ from http import HTTPStatus
|
||||
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
from modelscope.utils.logger import get_logger
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class NotExistError(Exception):
|
||||
pass
|
||||
@@ -45,15 +49,24 @@ def is_ok(rsp):
|
||||
return rsp['Code'] == HTTPStatus.OK and rsp['Success']
|
||||
|
||||
|
||||
def handle_http_post_error(response, url, request_body):
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except HTTPError as error:
|
||||
logger.error('Request %s with body: %s exception, respoonse body: %s' %
|
||||
(url, request_body, response.body))
|
||||
raise error
|
||||
|
||||
|
||||
def handle_http_response(response, logger, cookies, model_id):
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except HTTPError:
|
||||
except HTTPError as error:
|
||||
if cookies is None: # code in [403] and
|
||||
logger.error(
|
||||
f'Authentication token does not exist, failed to access model {model_id} which may not exist or may be \
|
||||
private. Please login first.')
|
||||
raise
|
||||
raise error
|
||||
|
||||
|
||||
def raise_on_error(rsp):
|
||||
|
||||
Reference in New Issue
Block a user