发送文件
POST 请求最多可包含对话中的十个文件(包括 DALL-E 生成的图像)。这些文件将以 URL 的形式发送,有效期为五分钟。
若要将文件包含在 POST 请求中,参数必须命名为 openaiFileIdRefs,且其描述应向模型说明 API 所预期的文件类型和数量。
openaiFileIdRefs 参数将由一组 JSON 对象数组填充。每个对象包含:
name文件名。如果是 DALL-E 创建的,将自动生成文件名。id文件的稳定标识符。mime_type文件的 MIME 类型。对于用户上传的文件,此类型基于文件扩展名。download_link获取文件的 URL,有效期为五分钟。
以下是一个包含两个元素的 openaiFileIdRefs 数组示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[
{
"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"
}
]Actions 可以包含用户上传的文件、DALL-E 生成的图像以及代码解释器(Code Interpreter)创建的文件。
OpenAPI 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/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虽然此架构将 openaiFileIdRefs 显示为字符串数组,但在运行时它将如前所示,被填充为 JSON 对象数组。
返回文件
请求最多可返回 10 个文件。每个文件大小不超过 10 MB,且不能为图像或视频格式。
这些文件将成为对话的一部分,类似于用户上传的文件。这意味着它们可能会被提供给代码解释器、文件搜索功能,并作为后续 Action 调用的参数发送。在 Web 应用中,用户将看到返回的文件并可以进行下载。
若要返回文件,响应正文必须包含 openaiFileResponse 参数。此参数必须始终是一个数组,并且必须通过以下两种方式之一进行填充。
内联(Inline)选项
数组的每个元素都是一个 JSON 对象,包含:
name文件名。该名称对用户可见。mime_type文件的 MIME 类型。用于确定文件的合规性以及哪些功能可以访问该文件。content经过 Base64 编码的文件内容。
以下是一个包含两个元素的 openaiFileResponse 数组示例:
1
2
3
4
5
6
7
8
9
10
11
12
[
{
"name": "example_document.pdf",
"mime_type": "application/pdf",
"content": "JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29kZT4+CnN0cmVhbQpHhD93PQplbmRzdHJlYW0KZW5kb2JqCg=="
},
{
"name": "sample_spreadsheet.csv",
"mime_type": "text/csv",
"content": "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
}
]OpenAPI 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/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 数组示例:
1
2
3
4
[
"https://example.com/f/dca89f18-16d4-4a65-8ea2-ededced01646",
"https://example.com/f/01fad6b0-635b-4803-a583-0f678b2e6153"
]以下是每个 URL 所需标头的示例:
Content-Type: application/pdf
Content-Disposition: attachment; filename="example_document.pdf"OpenAPI 示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/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.