如何从 GCP 上的 Vertex AI 管道的 gcp_resources 中正确提取端点 ID?
How to properly extract endpoint id from gcp_resources of a Vertex AI pipeline on GCP?
我正在使用 GCP Vertex AI 管道 (KFP) 并使用 google-cloud-aiplatform==1.10.0
、kfp==1.8.11
、google-cloud-pipeline-components==0.2.6
在一个组件中,我得到一个 gcp_resources documentation :
gcp_resources (str):
Serialized gcp_resources proto tracking the create endpoint's long running operation.
要提取 endpoint_id 来对我部署的模型进行在线预测,我正在做:
from google_cloud_pipeline_components.proto.gcp_resources_pb2 import GcpResources
from google.protobuf.json_format import Parse
input_gcp_resources = Parse(endpoint_ressource_name, GcpResources())
gcp_resources=input_gcp_resources.resources.__getitem__(0).resource_uri.split('/')
endpoint_id=gcp_resources[gcp_resources.index('endpoints')+1]
是否有 better/native 提取此类信息的方法?
在这种情况下是提取信息的最佳方式。但是,我建议使用 yarl 库来解析复杂的 uri。
你可以看到这个例子:
>>> from yarl import URL
>>> url = URL('https://www.python.org/~guido?arg=1#frag')
>>> url
URL('https://www.python.org/~guido?arg=1#frag')
所有 URL 部分都可以通过这些属性访问。
>>> url.scheme
'https'
>>> url.host
'www.python.org'
>>> url.path
'/~guido'
>>> url.query_string
'arg=1'
>>> url.query
<MultiDictProxy('arg': '1')>
>>> url.fragment
'frag'
我正在使用 GCP Vertex AI 管道 (KFP) 并使用 google-cloud-aiplatform==1.10.0
、kfp==1.8.11
、google-cloud-pipeline-components==0.2.6
在一个组件中,我得到一个 gcp_resources documentation :
gcp_resources (str):
Serialized gcp_resources proto tracking the create endpoint's long running operation.
要提取 endpoint_id 来对我部署的模型进行在线预测,我正在做:
from google_cloud_pipeline_components.proto.gcp_resources_pb2 import GcpResources
from google.protobuf.json_format import Parse
input_gcp_resources = Parse(endpoint_ressource_name, GcpResources())
gcp_resources=input_gcp_resources.resources.__getitem__(0).resource_uri.split('/')
endpoint_id=gcp_resources[gcp_resources.index('endpoints')+1]
是否有 better/native 提取此类信息的方法?
在这种情况下是提取信息的最佳方式。但是,我建议使用 yarl 库来解析复杂的 uri。
你可以看到这个例子:
>>> from yarl import URL
>>> url = URL('https://www.python.org/~guido?arg=1#frag')
>>> url
URL('https://www.python.org/~guido?arg=1#frag')
所有 URL 部分都可以通过这些属性访问。
>>> url.scheme
'https'
>>> url.host
'www.python.org'
>>> url.path
'/~guido'
>>> url.query_string
'arg=1'
>>> url.query
<MultiDictProxy('arg': '1')>
>>> url.fragment
'frag'