googleapis / googleapis/python-aiplatform
`get_version` returns latest prompt content instead of specified version content
- Ngôn ngữ chính
- Python
- Star
- 905
- Fork
- 465
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 44
Mô tả
### Description
**Bug Description**
The `get_version` method in `Prompts` class (and `AsyncPrompts`) always returns the latest prompt content regardless of which `version_id` is specified. This is because the method creates the `Prompt` object from `prompt_dataset_resource` (which contains the latest prompt data) instead of `prompt_version_resource` (which contains the version-specific data).
**Steps to Reproduce**
1. Create a prompt with initial content (e.g., "Version 1 content")
2. Create a new version with different content (e.g., "Version 2 content")
3. Repeat step 2 to create multiple versions
4. Call `get_version(prompt_id="...", version_id="1")` to retrieve version 1
5. The returned prompt contains "Version 2 content" (latest) instead of "Version 1 content"
**Expected Behavior**
`get_version` should return the prompt content corresponding to the specified `version_id`.
**Actual Behavior**
`get_version` always returns the latest prompt content, ignoring the `version_id` parameter for the prompt data.
**Root Cause**
In `vertexai/_genai/prompts.py`, the `get_version` method creates the `Prompt` object from `prompt_dataset_resource`:
https://github.com/googleapis/python-aiplatform/blob/47be102c3d27170fe605e9aec69d9d97d9f305ee/vertexai/_genai/prompts.py#L1145-L1175
**Suggested Fix**
The `Prompt` object should be created from `prompt_version_resource` instead:
```python
# Proposed fix
prompt_dataset_resource = self._get_dataset_resource(name=prompt_id)
prompt_version_resource = self._get_dataset_version_resource(
dataset_id=prompt_id,
dataset_version_id=version_id,
)
prompt = _prompt_management_utils._create_prompt_from_dataset_metadata(
prompt_version_resource, # ← Use version-specific resource
)
prompt._dataset = prompt_dataset_resource
prompt._dataset_version = prompt_version_resource
return prompt
```
**Affected Code**
- `Prompts.get_version` (sync version): lines 1145-1175
- `AsyncPrompts.get_version` (async version): lines 2311-2341
**Environment**
- vertexai SDK version: 1.130.0
- Python version: 3.13.2
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.