BUG: OpenAIImageTarget uploads edited images under a generated local path instead of their file name
维护者通常 2 天内回复
已经有一个关联 PR 被合并了。
- #3496 来自 @ShivamSharma43 —— 已合并
评估
调研方向
先阅读 OpenAIImageTarget._send_edit_request_async,并将其上传时的命名方式与 OpenAIVideoTarget 进行比较;issue 指出后者使用 Path(image_path).name。检查现有的图像编辑测试,并运行相关测试。完成标准是:编辑后的图像以原始文件名上传,同时保留 get_mime_type(image_path) 返回的 MIME 类型。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
OpenAIImageTarget._send_edit_request_async builds the file name for each uploaded image like this:
img_serializer = data_serializer_factory(
category="prompt-memory-entries", value=image_path, data_type="image_path"
)
image_name = str(await img_serializer.get_data_filename_async())
get_data_filename_async() does not return the name of the image in image_path. It generates a new storage path for saving data: a full path under the results directory with a random UUID and the serializer's default .png extension. The edit request then sends that as the multipart file name:
- The name is never the image's real name, and it ends in
.pngeven when the image is a JPEG or WebP. The MIME type is right (it comes fromget_mime_type(image_path)), so only the name is wrong. - The name is a full local path, so every edit request sends the provider the local results directory, which can include the user's name (
C:\Users\<name>\...).
OpenAIVideoTarget already uses Path(image_path).name for its image upload.
Steps/Code to Reproduce
import asyncio
import os
import tempfile
from unittest.mock import AsyncMock, MagicMock, patch
from pyrit.setup import IN_MEMORY, initialize_pyrit_async
async def main():
await initialize_pyrit_async(memory_db_type=IN_MEMORY)
from pyrit.models import Message, MessagePiece
from pyrit.prompt_target import OpenAIImageTarget
image_path = os.path.join(tempfile.mkdtemp(), "cat_photo.jpg")
with open(image_path, "wb") as f:
f.write(b"\xff\xd8\xff\xe0 jpeg bytes")
target = OpenAIImageTarget(model_name="gpt-image-1", endpoint="https://api.openai.com/v1", api_key="test-key")
response = MagicMock(data=[MagicMock(b64_json="aGVsbG8=")])
message = Message(
message_pieces=[
MessagePiece(role="user", original_value="make the cat blue", conversation_id="c1"),
MessagePiece(
role="user",
original_value=image_path,
original_value_data_type="image_path",
converted_value_data_type="image_path",
conversation_id="c1",
),
]
)
with patch.object(target._async_client.images, "edit", AsyncMock(return_value=response)) as edit:
await target.send_prompt_async(message=message)
name, _, mime_type = edit.await_args.kwargs["image"]
print("input image :", image_path)
print("uploaded name:", name)
print("uploaded mime:", mime_type)
asyncio.run(main())
Expected Results
The image is uploaded under its own file name:
input image : C:\Users\<name>\AppData\Local\Temp\tmpxl9ab2tr\cat_photo.jpg
uploaded name: cat_photo.jpg
uploaded mime: image/jpeg
Actual Results
The name is a newly generated local path with a .png extension:
input image : C:\Users\<name>\AppData\Local\Temp\tmpe5ggjo3f\cat_photo.jpg
uploaded name: C:\Users\<name>\...\dbdata\prompt-memory-entries\images\36f183a4-8ec4-4ffd-b676-f341d469f72c.png
uploaded mime: image/jpeg
Screenshots
N/A
Versions
- OS: Windows 11
- Python version: 3.11.9
- PyRIT version: installed from main (eeb9ba9d) in editable mode
- 主要语言
- Python
- 星标
- 4.7k
- 派生
- 980
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 422
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/PyRIT 的其他 Issue
-
Conversation drawer shows the previous attack's conversations after switching attacks可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
相似的 Issue
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 72/100
Ikalus1988/MisakaNet#3956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
aws-samples/sample-per-model-bedrock#574 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
521xueweihan/HelloGitHub#4133 ·
-
plot_components fails for logistic models with minmax scaling and no floor可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
Update migen未关闭
难度 2/5 1-3 小时 新手友好度 70/100
YosysHQ/oss-cad-suite-build#220 ·