googleapis / googleapis/python-aiplatform

bug: Wrong code block in getting a model in README

未关闭
#2,994 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
api: vertex-ai
主要语言
Python
星标
905
派生
465
平均合并
1 天 13 小时
30 天内合并 PR
44

描述

Hi there,

I was following the README to get an existing model but got an error.

#### Steps to reproduce

Code:

```python
MODEL_ID = "2205063972435001344"
model = aiplatform.Model(f"/projects/{PROJECT_ID}/locations/us-central1/models/{MODEL_ID}")
```

#### Stack trace
```
ValueError Traceback (most recent call last)
Cell In[6], line 2
1 MODEL_ID = "2205063972435001344"
----> 2 model = aiplatform.Model(f"/projects/{PROJECT_ID}/locations/us-central1/models/{MODEL_ID}")
3 dir(model)

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/models.py:2857, in Model.__init__(self, model_name, project, location, credentials, version)
2855 # Create a versioned model_name, if it exists, for getting the GCA model
2856 versioned_model_name = ModelRegistry._get_versioned_name(model_name, version)
-> 2857 self._gca_resource = self._get_gca_resource(resource_name=versioned_model_name)
2859 # Create ModelRegistry with the unversioned resource name
2860 self._registry = ModelRegistry(
2861 self.resource_name,
2862 location=location,
2863 project=project,
2864 credentials=credentials,
2865 )

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/base.py:635, in VertexAiResourceNoun._get_gca_resource(self, resource_name, parent_resource_name_fields)
621 def _get_gca_resource(
622 self,
623 resource_name: str,
624 parent_resource_name_fields: Optional[Dict[str, str]] = None,
625 ) -> proto.Message:
626 """Returns GAPIC service representation of client class resource.
627
628 Args:
(...)
633 Should not include project and location.
634 """
--> 635 resource_name = utils.full_resource_name(
636 resource_name=resource_name,
637 resource_noun=self._resource_noun,
638 parse_resource_name_method=self._parse_resource_name,
639 format_resource_name_method=self._format_resource_name,
640 project=self.project,
641 location=self.location,
642 parent_resource_name_fields=parent_resource_name_fields,
643 resource_id_validator=self._resource_id_validator,
644 )
646 return getattr(self.api_client, self._getter_method)(
647 name=resource_name, retry=_DEFAULT_RETRY
648 )

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/utils/__init__.py:194, in full_resource_name(resource_name, resource_noun, parse_resource_name_method, format_resource_name_method, parent_resource_name_fields, project, location, resource_id_validator)
191 user_location = location or initializer.global_config.location
193 validate_region(user_location)
--> 194 resource_id_validator(resource_name)
196 format_args = {
197 "location": user_location,
198 "project": user_project,
199 convert_camel_case_resource_noun_to_snake_case(resource_noun): resource_name,
200 }
202 if parent_resource_name_fields:

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform/base.py:486, in VertexAiResourceNoun._revisioned_resource_id_validator(resource_id)
474 """Some revisioned resource names can have '@' in them
475 to separate the resource ID from the revision ID.
476 Thus, they need their own resource id validator.
(...)
483 ValueError: If a `resource_id` doesn't conform to appropriate revision syntax.
484 """
485 if not re.compile(r"^[\w-]+@?[\w-]+$").match(resource_id):
--> 486 raise ValueError(f"Resource {resource_id} is not a valid resource ID.")

ValueError: Resource /projects/derrick-playground/locations/us-central1/models/2205063972435001344 is not a valid resource ID.
```

#### fix

I suppose this was a typo, the current code should be:

```python
MODEL_ID = "2205063972435001344"
model = aiplatform.Model(f"/projects/{PROJECT_ID}/locations/us-central1/models/{MODEL_ID}")
```

In short, we should remove the `/` before `projects`.

Thanks!

贡献指南

打开贡献指南

调研方向

打开包含模型检索示例的 README 部分,并将其与报告的 Traceback 进行比较。确认预期的资源路径并相应地更新代码块,然后验证示例不再包含无效的路径形式。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
cloud, documentation
Issue 类型
缺陷
难度
1/5
预计耗时
1 小时以内
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。