googleapis / googleapis/python-aiplatform
bug: Wrong code block in getting a model in README
- Vorherrschende Sprache
- Python
- Sterne
- 905
- Forks
- 465
- Ø Merge
- 1 T. 13 Std.
- Gemergte PRs (30 T.)
- 44
Beschreibung
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!
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.