Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

BUG: OpenAIImageTarget uploads edited images under a generated local path instead of their file name

已关闭 适合新手
#3,494 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

已经有一个关联 PR 被合并了。

  • #3496 来自 @ShivamSharma43 —— 已合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
79/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

先阅读 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 .png even when the image is a JPEG or WebP. The MIME type is right (it comes from get_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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/PyRIT 的其他 Issue

查看 microsoft/PyRIT 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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