googleapis / googleapis/python-aiplatform
`get_version` returns latest prompt content instead of specified version content
- 主要语言
- Python
- 星标
- 905
- 派生
- 465
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 44
描述
### 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
贡献指南
调研方向
从 vertexai/_genai/prompts.py 中的 Prompts.get_version 和 AsyncPrompts.get_version 开始,使用所引用的行范围和复现步骤比较 dataset 资源和版本资源。完成标准是:请求较旧版本时,在同步和异步方法中都会返回该版本自身的 prompt 内容,而不是最新内容。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 58/100