如何有效地使用 azureml.exceptions.WebserviceException 进行高效的 REST API 错误管理?
How to effectively use azureml.exceptions.WebserviceException for efficient REST API Error Management?
在 Azure 机器学习服务中,当我们将模型部署为 AKS Web 服务端点时,如果 API 调用不成功,我们如何引发异常以使最终用户获得适当的反馈? Azure 在其 documentation 中提到使用 azureml.exceptions.WebserviceException
。但是,如果无法正确处理 API 调用并且最终用户对此负责,我们如何使用此 class 引发异常?
以下代码示例显示如何处理 WebserviceException
,它是 AzureMLException
的子类。在代码中,如果服务检查失败,则处理WebserviceException
并打印一条消息。
from azureml.core.model import InferenceConfig
from azureml.core.webservice import AciWebservice
service_name = 'my-custom-env-service'
inference_config = InferenceConfig(entry_script='score.py', environment=environment)
aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
service = Model.deploy(workspace=ws,
name=service_name,
models=[model],
inference_config=inference_config,
deployment_config=aci_config,
overwrite=True)
service.wait_for_deployment(show_output=True)
如果有帮助请告诉我。
如果最终用户的 API 调用不成功,为了引发异常以让最终用户获得适当的反馈,我们使用 azureml.contrib.services.aml_response.AMLResponse
Class.
score.py
中的使用示例:
if [some-condition]:
return AMLResponse("bad request", 500)
可以找到文档 Link here。
在 Azure 机器学习服务中,当我们将模型部署为 AKS Web 服务端点时,如果 API 调用不成功,我们如何引发异常以使最终用户获得适当的反馈? Azure 在其 documentation 中提到使用 azureml.exceptions.WebserviceException
。但是,如果无法正确处理 API 调用并且最终用户对此负责,我们如何使用此 class 引发异常?
以下代码示例显示如何处理 WebserviceException
,它是 AzureMLException
的子类。在代码中,如果服务检查失败,则处理WebserviceException
并打印一条消息。
from azureml.core.model import InferenceConfig
from azureml.core.webservice import AciWebservice
service_name = 'my-custom-env-service'
inference_config = InferenceConfig(entry_script='score.py', environment=environment)
aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)
service = Model.deploy(workspace=ws,
name=service_name,
models=[model],
inference_config=inference_config,
deployment_config=aci_config,
overwrite=True)
service.wait_for_deployment(show_output=True)
如果有帮助请告诉我。
如果最终用户的 API 调用不成功,为了引发异常以让最终用户获得适当的反馈,我们使用 azureml.contrib.services.aml_response.AMLResponse
Class.
score.py
中的使用示例:
if [some-condition]:
return AMLResponse("bad request", 500)
可以找到文档 Link here。