Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python在统一AI平台上编辑端点设置?_Python_Google Cloud Platform_Google Cloud Ml_Google Ai Platform - Fatal编程技术网

如何使用Python在统一AI平台上编辑端点设置?

如何使用Python在统一AI平台上编辑端点设置?,python,google-cloud-platform,google-cloud-ml,google-ai-platform,Python,Google Cloud Platform,Google Cloud Ml,Google Ai Platform,我已经成功地在统一云AI平台上创建了一个端点,并在其上部署了两个Models-Model A和Model B,流量分别为20%和80%。现在,在云控制台(UI)上,我可以选择编辑设置,将流量拆分分别更改为30%和70%,并部署模型。但是,我不知道如何使用Python客户端API来实现这一点 以上提供的文件不足以理解我们如何做到这一点。任何帮助都将不胜感激。AI Platform Unified的文档还没有关于如何使用python编辑流量的示例。以下是代码: 注意:在运行代码之前,不要忘记更新端点

我已经成功地在统一云AI平台上创建了一个端点,并在其上部署了两个
Model
s-
Model A
Model B
,流量分别为20%和80%。现在,在云控制台(UI)上,我可以选择编辑设置,将流量拆分分别更改为30%和70%,并部署
模型。但是,我不知道如何使用Python客户端API来实现这一点


以上提供的文件不足以理解我们如何做到这一点。任何帮助都将不胜感激。

AI Platform Unified的文档还没有关于如何使用python编辑流量的示例。以下是代码:

注意:在运行代码之前,不要忘记更新
端点
(端点ID)、
项目
(项目ID)、
模型ID_1
模型ID_2
的值

from google.cloud import aiplatform
from google.cloud import aiplatform_v1


def update_endpoint_traffic(
    end_point: str, 
    project: str, 
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 7200,
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.EndpointServiceClient(client_options=client_options)
    client_model = aiplatform_v1.services.model_service.ModelServiceClient(client_options=client_options)

    deployed_model_id_list = []
    model_id_1 = 'xxxxxxxx' # place your model id here
    model_id_2 = 'xxxxxxxx' # place your model id here
    model_list = [f'projects/{project}/locations/{location}/models/{model_id_1}',f'projects/{project}/locations/{location}/models/{model_id_2}']

    for model in model_list:
        model_request = aiplatform_v1.types.GetModelRequest(name=model)
        model_info = client_model.get_model(request=model_request)
        deployed_models_info = model_info.deployed_models
        deployed_model_id=model_info.deployed_models[0].deployed_model_id
        deployed_model_id_list.append(deployed_model_id)

    traffic_split = {deployed_model_id_list[0]: 60, deployed_model_id_list[1]:40} #update values of 60 and 40 to desired traffic split ex.(30 70)

    name=f'projects/{project}/locations/{location}/endpoints/{end_point}'

    endpoint = aiplatform_v1.types.Endpoint(name=name,traffic_split=traffic_split)
    update_endpoint = aiplatform_v1.types.UpdateEndpointRequest(endpoint=endpoint)
    client.update_endpoint(request=update_endpoint)

update_endpoint_traffic(end_point='your-endpoint-id',project='your-project-id')