OpenAI GPT Actions 文件传递
发送文件
POST 请求最多可以携带对话中的 10 个文件,包括 DALL·E 生成的图像。文件以 URL 形式发送,URL 有效期为 5 分钟。
要在 POST 请求中加入文件,参数必须命名为 openaiFileIdRefs,并在描述中向模型说明 API 预期接收的文件类型和数量。
openaiFileIdRefs 会被填充为 JSON 对象数组。每个对象包含:
name:文件名。DALL·E 创建的文件会使用自动生成的名称。id:文件的稳定标识符。mime_type:MIME 类型。用户上传的文件按扩展名确定类型。download_link:下载 URL,有效期为 5 分钟。
以下数组包含两个元素:
来源示例 1(json):
中文译释:文件对象数组包含name、id、mime_type和download_link;链接是历史示例,不是本次可用的下载凭证,也不要抓取或复用这些签名URL。
[
{
"name": "dalle-Lh2tg7WuosbyR9hk",
"id": "file-XFlOqJYTPBPwMZE3IopCBv1Z",
"mime_type": "image/webp",
"download_link": "https://files.oaiusercontent.com/file-XFlOqJYTPBPwMZE3IopCBv1Z?se=2024-03-11T20%3A29%3A52Z&sp=r&sv=2021-08-06&sr=b&rscc=max-age%3D31536000%2C%20immutable&rscd=attachment%3B%20filename%3Da580bae6-ea30-478e-a3e2-1f6c06c3e02f.webp&sig=ZPWol5eXACxU1O9azLwRNgKVidCe%2BwgMOc/TdrPGYII%3D"
},
{
"name": "2023 Benefits Booklet.pdf",
"id": "file-s5nX7o4junn2ig0J84r8Q0Ew",
"mime_type": "application/pdf",
"download_link": "https://files.oaiusercontent.com/file-s5nX7o4junn2ig0J84r8Q0Ew?se=2024-03-11T20%3A29%3A52Z&sp=r&sv=2021-08-06&sr=b&rscc=max-age%3D299%2C%20immutable&rscd=attachment%3B%20filename%3D2023%2520Benefits%2520Booklet.pdf&sig=Ivhviy%2BrgoyUjxZ%2BingpwtUwsA4%2BWaRfXy8ru9AfcII%3D"
}
]
Action 可以携带用户上传的文件、DALL·E 生成的图像,以及代码解释器创建的文件。
OpenAPI 示例
来源示例 2(yaml):
## [中文] 发送文件的OpenAPI片段:openaiFileIdRefs在Schema中声明为字符串数组,但运行时由平台填入文件对象;不要自行假定运行时仍是字符串。
/createWidget:
post:
operationId: createWidget
summary: Creates a widget based on an image.
description: Uploads a file reference using its file id. This file should be an image created by DALL·E or uploaded by the user. JPG, WEBP, and PNG are supported for widget creation.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
openaiFileIdRefs:
type: array
items:
type: string
虽然 Schema 将 openaiFileIdRefs 定义为字符串数组,但运行时会填入前述 JSON 对象数组。
返回文件
每次请求最多返回 10 个文件,每个最大 10 MB,不能是图像或视频。
文件会像用户上传的文件一样成为对话的一部分,可能供代码解释器、文件搜索使用,或在后续 Action 调用中再次发送。网页版用户可以看到并下载返回的文件。
响应体必须包含 openaiFileResponse 参数。它必须始终是数组,并通过以下两种方式之一填充。
内联方式
数组中的每个元素是 JSON 对象,包含:
name:用户可以看到的文件名。mime_type:用于判定文件是否符合要求,以及哪些功能可访问该文件的 MIME 类型。content:以 Base64 编码的文件内容。
以下 openaiFileResponse 数组包含两个元素:
来源示例 3(json):
中文译释:内联文件数组用content承载Base64。原文第二项的文件名/MIME与内容签名不一致,按来源保留并在正文提示待核。
[
{
"name": "example_document.pdf",
"mime_type": "application/pdf",
"content": "JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29kZT4+CnN0cmVhbQpHhD93PQplbmRzdHJlYW0KZW5kb2JqCg=="
},
{
"name": "sample_spreadsheet.csv",
"mime_type": "text/csv",
"content": "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
}
]
示例数据提示:原文第二项声明为CSV,但其Base64内容具有PNG文件签名。本稿保留来源字面量作为格式示意,不将其视为有效CSV文件;实际返回时文件内容、文件名与MIME类型必须一致。
OpenAPI 示例:
来源示例 4(yaml):
## [中文] 返回内联文件:name、mime_type、content分别表示文件名、MIME类型及Base64内容,openaiFileResponse必须为数组。
/papers:
get:
operationId: findPapers
summary: Retrieve PDFs of relevant academic papers.
description: Provided an academic topic, up to five relevant papers will be returned as PDFs.
parameters:
- in: query
name: topic
required: true
schema:
type: string
description: The topic the papers should be about.
responses:
"200":
description: Zero to five academic paper PDFs
content:
application/json:
schema:
type: object
properties:
openaiFileResponse:
type: array
items:
type: object
properties:
name:
type: string
description: The name of the file.
mime_type:
type: string
description: The MIME type of the file.
content:
type: string
format: byte
description: The content of the file in base64 encoding.
URL 方式
数组中的每个元素是引用待下载文件的 URL。响应头 Content-Disposition 和 Content-Type 必须能确定文件名及 MIME 类型。文件名对用户可见;MIME 类型决定文件是否符合要求,以及哪些功能可以访问。
获取每个文件的超时为 10 秒。
以下 openaiFileResponse 数组包含两个 URL:
来源示例 5(json):
中文译释:URL方式的文件数组,每项是待下载地址;这里是example.com占位示例,不是实际文件。
[
"https://example.com/f/dca89f18-16d4-4a65-8ea2-ededced01646",
"https://example.com/f/01fad6b0-635b-4803-a583-0f678b2e6153"
]
每个 URL 所需响应头示例:
来源示例 6():
中文译释:这是HTTP响应头示意:Content-Type提供MIME,Content-Disposition提供附件文件名,不是Shell命令。
Content-Type: application/pdf
Content-Disposition: attachment; filename="example_document.pdf"
OpenAPI 示例:
来源示例 7(yaml):
## [中文] URL返回方案的原文Schema;保留来源缩进,items与type的位置疑点仍待核,本注释不表示Schema已通过校验。
/papers:
get:
operationId: findPapers
summary: Retrieve PDFs of relevant academic papers.
description: Provided an academic topic, up to five relevant papers will be returned as PDFs.
parameters:
- in: query
name: topic
required: true
schema:
type: string
description: The topic the papers should be about.
responses:
'200':
description: Zero to five academic paper PDFs
content:
application/json:
schema:
type: object
properties:
openaiFileResponse:
type: array
items:
type: string
format: uri
description: URLs to fetch the files.
来源格式提示:最后一段原文Schema中,
items与type: string的缩进关系存在疑点。本稿保留原示例并列入待核,不能将来源保真等同于OpenAPI校验通过。

TRAE-AI编程


更多建议: