多模态评测数据中的媒体引用与日志配置

介绍在评测中接入图像、音频、视频和PDF等多模态输入的方法,说明固定数据集中的媒体引用为何被视为可信配置,并给出Gemini文件上传与媒体日志开关的配置要点。

## 概览 许多模型现在都支持多模式输入,包括图像、音频、视频和PDF。本文描述了如何创建包含这些数据类型的评价。 下列供应商目前对多式联运投入有支持: | 供应商 | 图像 | 音频 | 视频 | PDF | | --- | --- | --- | --- | --- | | OpenAI | • | • | | • | | 人类 | • | | | • | | 谷歌( G) | • | • | • | • | | 迷雾 | • | • | | • | | 格鲁克 | • | | | | | 贝德洛克 | • | | | | | AzureAI | • | | | | | 格鲁克 | • | | | | 请注意,模型提供者只支持其模型的一个子集的多模式输入。 在下面关于图像、音频和视频的章节中,我们将列举哪些模型可以处理这些输入类型。 检查提供者的文档以了解最新的兼容性矩阵也是个好主意。 一些OpenAI和Google模型额外支持 [多式联运输出](<https://inspect.aisi.org.uk/multimodal.html#multimodal-output>). ## 媒体参考资料和权威 固定任务数据集中的路径和URL——包括a [SampleSource](<https://inspect.aisi.org.uk/reference/inspect_ai.html#samplesource>)’s `initial_samples()` 种子 - 在进入样本的运行时间消息状态之前实现。 因此, 当数据集种子包含非内置介质引用时, 其配置是可信的 。 这是权威决定,而不是安全检查。 固定数据集 HTTP 引用会跟踪重定向, 并且不会被筛选为私有目标地址、 端口或响应大小。 因此, 第三方数据集可以让评估者访问数据集或其重定向所命名的目的地。 审查未信任的数据集或用合适的主机网络和文件系统隔离来运行它们 。硬化此可信任的获取路径与运行时间媒体政策分开跟踪 。 WarningRuntime 媒体必须内置 由工具、 解析器、 动态创建任务引入的媒体, 或 [SampleSource](<https://inspect.aisi.org.uk/reference/inspect_ai.html#samplesource>) (`next_samples()`, `sample_complete()`,或 [enqueue_sample()](<https://inspect.aisi.org.uk/reference/inspect_ai.html#enqueue_sample>))必须已经是数据 URL。 [生成( )](<https://inspect.aisi.org.uk/reference/inspect_ai.solver.html#generate>), `count_tokens()`,以及 `compact()`沙箱代理桥梁也执行同样的规则. 信任的运行时代码可以明确转换授权路径或 URL , 并使用 `await materialize_media(reference)`不调用 [materialize_media()](<https://inspect.aisi.org.uk/reference/inspect_ai.util.html#materialize_media>) 除非有意授权文件系统或网络访问。 在提交模型之前,进程内桥明确实现非内置介质;它们已经共享了评估器的文件系统和网络。信任的运行时代码可以同样的方式实现介质: ``` from inspect_ai.model import ContentImage from inspect_ai.util import materialize_media image = ContentImage( image=await materialize_media("picture.png") ) ``` [materialize_media()](<https://inspect.aisi.org.uk/reference/inspect_ai.util.html#materialize_media>) 可以读取文件,获取 URL,并引用已配置的媒体解析器。模型媒体数据 URL 可以声明一个兼容的 MIME 类型(例如, `data:image/png;base64,...`当它被省略时, Inspect 使用图像签名或 PNG 兼容默认, `format` 音频和视频内容,或文件的 `mime_type`. HTTP 实现化遵循方向调整,在使用其机构前拒绝错误反应。对于无扩展介质,Inspect使用特定响应 MIME 类型,内容元数据,或者对常见图像格式进行边框签名检查. ### 扩展迁移 公众 [agent_bridge()](<https://inspect.aisi.org.uk/reference/inspect_ai.agent.html#agent_bridge>) 上下文管理器继续实现非内置媒体,因为进程内脚手架已经共享主机访问。 [AgentBridge](<https://inspect.aisi.org.uk/reference/inspect_ai.agent.html#agentbridge>) 现在必须直接通过 `allow_remote_media=True` (c) 明确提供同样的赠款。 任务解析帮助默认为 `input_media_policy="inline_only"`。嵌入器调用 `resolve_tasks()` 或 时 间 `eval_resolve_tasks()` 在真实的预运行边界中, 可以通过通过来保存固定的数据集路径和 URL 处理 `input_media_policy="trusted_pre_run"`。对于在电子评估中创建的任务,不要使用此政策。 见 [媒体参考机构](<https://github.com/UKGovernmentBEIS/inspect_ai/blob/main/design/media-authority.md>) 用于完整威胁模型、源表和剩余风险。 ## 图像 请参见提供方支持图像输入的具体文档 : - [OpenAI 图像和视野](<https://platform.openai.com/docs/guides/images-vision>) - [人类的愿景](<https://docs.anthropic.com/en/docs/build-with-claude/vision>) - [Gemni 图像理解](<https://ai.google.dev/gemini-api/docs/image-understanding>) - [迷雾视野](<https://docs.mistral.ai/capabilities/vision/>) - [Grok 图像理解](<https://docs.x.ai/docs/guides/image-understanding>) 将图像包含在 [数据集](<https://inspect.aisi.org.uk/datasets.html>) 您应该使用 JSON 输入格式(标准 JSON 或 JSON 线条)。例如,这里我们包含一个图像,与一些文本内容并列 : ``` "input": [ { "role": "user", "content": [ { "type": "image", "image": "picture.png"}, { "type": "text", "text": "What is this a picture of?"} ] } ] ``` 那个... `"picture.png"` 路径相对于包含数据集文件的目录被解析。图像可以指定为文件路径,也可以指定为已编码的基数64 [数据 URL](<https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs>). 如果您正在按程序构建聊天信息,那么与上述信息等同的将是: ``` input = [ ChatMessageUser(content = [ ContentImage(image="picture.png"), ContentText(text="What is this a picture of?") ]) ] ``` ### 细节 一些供应商支持a `detail` 选项,用于控制模型如何处理图像并生成其文本理解。有效的选项是 `auto` (默认), `low`,以及 `high`。见 [打开 AI 文档](<https://developers.openai.com/api/docs/guides/images-vision#choose-an-image-detail-level>) 对于使用此选项的更多信息, Mistral、 AzureAI 和 Groq APIs 也支持 `detail` 参数。例如,我们在此明确指定图像细节: ``` ContentImage(image="picture.png", detail="low") ``` ## 音频 以下模式目前支持音频输入: - 打开 AI : `gpt-audio-1.5` - Google:所有双子座模型 - Mistral: 所有 Voxtral 模型 将音频包含在 a [数据集](<https://inspect.aisi.org.uk/datasets.html>) 您应该使用 JSON 输入格式(标准 JSON 或 JSON 线)。例如,这里包含一些文本内容的音频: ``` "input": [ { "role": "user", "content": [ { "type": "audio", "audio": "sample.mp3", "format": "mp3" }, { "type": "text", "text": "What words are spoken in this audio sample?"} ] } ] ``` “ sample.mp3” 路径相对于包含数据集文件的目录被解析。 音频文件可以指定为文件路径, 也可以指定为已编码的基数64 [数据 URL](<https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs>). 如果您正在按程序构建聊天信息,那么与上述信息等同的将是: ``` input = [ ChatMessageUser(content = [ ContentAudio(audio="sample.mp3", format="mp3"), ContentText(text="What words are spoken in this audio sample?") ]) ] ``` ### 格式 您可以以两种格式之一提供音频文件: - MP3 - WAV 如上所示,您在包含音频输入时应当明确指定格式. ## 视频 以下模式目前支持视频投入: - Google:所有双子座模型. 将视频包含在 a [数据集](<https://inspect.aisi.org.uk/datasets.html>) 您应该使用 JSON 输入格式( 标准 JSON 或 JSON 线)。 例如, 这里包含一些文本内容的视频 : ``` "input": [ { "role": "user", "content": [ { "type": "video", "video": "video.mp4", "format": "mp4" }, { "type": "text", "text": "Can you please describe the attached video?"} ] } ] ``` “video.mp4”路径相对于包含数据集文件的目录解决。视频文件可以指定为文件路径,也可以指定为已编码的基数64 [数据 URL](<https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs>). 如果您正在按程序构建聊天信息,那么与上述信息等同的将是: ``` input = [ ChatMessageUser(content = [ ContentVideo(video="video.mp4", format="mp4"), ContentText(text="Can you please describe the attached video?") ]) ] ``` ### 格式 您可以以三种格式之一提供视频文件: - MP4 - MPEG - MOV 如上所示,您在包含视频输入时应当明确指定格式. ## PDF 下列模式提供者支持PDF输入: - [OpenAI](<https://platform.openai.com/docs/guides/pdf-files?api-mode=responses>) - [人类](<https://docs.anthropic.com/en/docs/build-with-claude/pdf-support>) - [谷歌( G)](<https://ai.google.dev/api/files>) - [迷雾](<https://docs.mistral.ai/capabilities/document_ai>) 将 PDF 列入 a [数据集](<https://inspect.aisi.org.uk/datasets.html>) 您应该使用 JSON 输入格式( 标准 JSON 或 JSON 线)。 例如, 在这里, 我们把 PDF 与一些文本内容并列 : ``` "input": [ { "role": "user", "content": [ { "type": "text", "text": "Please describe the contents of the attached PDF." }, { "type": "document", "document": "attention.pdf" } ] } ] ``` “ attention. pdf” 路径相对于包含数据集文件的目录解决。 视频文件可以指定为文件路径或已编码的基数64 [数据 URL](<https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs>). 如果您正在按程序构建聊天信息,那么与上述信息等同的将是: ``` input = [ ChatMessageUser(content=[ ContentText(text="Please describe the contents of the attached PDF."), ContentDocument(document="attention.pdf") ]) ] ``` ## 产出 一些模型可随文本一起生成多式联运输出: - 支持响应的 OpenAI 模型 API `image_generation` 工具(例如: `gpt-6-luna`)可以生成图像 - 谷歌模式 `gemini-2.5-flash-image`, `gemini-3-pro-image-preview`,以及 `gemini-3.1-flash-image-preview` 支持图像生成。 通过设置启用图像输出 `modalities=["image"]` 在您的帐号中 [GenerateConfig](<https://inspect.aisi.org.uk/reference/inspect_ai.model.html#generateconfig>): ``` config = GenerateConfig(modalities=["image"]) ``` 文本输出总是含蓄地包含在其中——你只需要在文本之外指定额外的模式. ### OpenAI 图像生成使用响应 API `image_generation` 使用 OpenAI 默认的 GPT 图像模型。要选择一个模型,例如 `gpt-image-2.5-flare` 或 时 间 `gpt-image-2.5-sunburst`设置 `model` 输入 [ImageOutput](<https://inspect.aisi.org.uk/reference/inspect_ai.model.html#imageoutput>) 选项。 ``` model = get_model("openai/gpt-6-luna") output = await model.generate( input=[ChatMessageUser(content="Generate an image of a sunset")], config=GenerateConfig(modalities=["image"]), ) ``` 对于图像生成的更多控制, 使用 [ImageOutput](<https://inspect.aisi.org.uk/reference/inspect_ai.model.html#imageoutput>) 有特定供应商选项: ``` from inspect_ai.model import ImageOutput config = GenerateConfig(modalities=[ ImageOutput(options={ "openai": { "quality": "high", "size": "1024x1024", "output_format": "png", "model": "gpt-image-2.5-flare" } }) ]) ``` ### 谷歌( G) ``` model = get_model("google/gemini-3.1-flash-image-preview") output = await model.generate( input=[ChatMessageUser(content="Generate an image of a sunset")], config=GenerateConfig(modalities=["image"]), ) ``` ### 响应格式 图像输出显示为 [ContentImage](<https://inspect.aisi.org.uk/reference/inspect_ai.model.html#contentimage>) 在助理消息中显示 `content` 列表中,带有 `data:image/png;base64,...` 数据 URI : ``` for content in output.choices[0].message.content: if isinstance(content, ContentImage): # content.image contains a data URI like "data:image/png;base64,..." pass ``` ## 上传 当使用Google双子座 API 的音频和视频时,媒体首先使用 [文件 API](<https://ai.google.dev/gemini-api/docs/files>) ,然后在聊天消息中引用上传文件的 URL 。这导致以后使用媒体文件的性能要快得多。 文件 API 允许您每个项目存储最多20GB的文件,每个文件的最大大小为 2GB. 文件存储时间为 48 小时,可以使用您的 API 密钥访问,但无法从 API 下载. 文件 API 在有 双子 API 的所有地区都是免费提供的. ## 日志 默认情况下, 日志文件中会保留内置媒体字节。 媒体日志不会获取未解决的运行时路径或 URL。 媒体文件日志不会在使用时产生性能问题 。 `.eval` 但是,如果您正在使用日志 `.json` 日志之后,大量媒体文件可能会变得不易操作(即如果您 `.json` 日志文件因此增长到100MB或更大. 您可以禁用所有使用此选项的媒体记录 `--no-log-images` 例如,我们在此启用 `.json` 日志格式和禁用媒体记录 : ``` inspect eval images.py --log-format=json --no-log-images ``` 这只控制保留。 固定任务输入中信任的介质仍然被实现以提交模型, 然后从完成的日志中删除 。 您也可以使用这个 `INSPECT_EVAL_LOG_IMAGES` 设置全局默认值的环境变量 `.env` 配置文件 。

查看原始来源