PDF 对话
目前仅 Gemini 系列对话模型支持原生的 PDF 文件对话,以下是 PDF 文件对话请求示例:
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gemini-2.5-pro-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请总结文档内容"
},
{
"type": "file_url",
"file_url": {
"url": "https://static.geekai.co/file/2025/04/22/be96ab26e4941f9e3de8da9d5fc089df.pdf",
"mime_type": "application/pdf"
}
}
]
}
]
}'
支持多文件对话,和图片对话类似,多个 PDF 文件以 file_url
对象传入到 content
列表即可:
"content": [
{
"type": "text",
"text": "请根据文档内容回答XXX问题"
},
{
"type": "file_url",
"file_url": {
"url": "https://static.geekai.co/file/2025/04/22/pdf1.pdf",
"mime_type": "application/pdf"
}
},
{
"type": "file_url",
"file_url": {
"url": "https://static.geekai.co/file/2025/04/22/pdf2.pdf",
"mime_type": "application/pdf"
}
}
]
需要注意的是,Gemini 模型不限制 PDF 文件数量,但是限制 PDF 文档页数,所有 PDF 文档页面不得超过 1000 页。
纯文本文件对话
除了 PDF 文件外,Gemini 模型还支持以下纯文本格式文件对话:
- JavaScript,对应
mime_type
为 text/javascript
- Python,对应
mime_type
为 text/x-python
- TXT,对应
mime_type
为 text/plain
- HTML,对应
mime_type
为 text/html
- CSS,对应
mime_type
为 text/css
- Markdown,对应
mime_type
为 text/markdown
- CSV,对应
mime_type
为 text/csv
- XML,对应
mime_type
为 text/xml
- RTF,对应
mime_type
为 text/rtf
以 Markdown 文件为例,示例代码如下,和 PDF 对话格式一样,只需要替换 url
然后将 mime_type
改为 text/markdown
即可:
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gemini-2.5-pro-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请总结文档内容"
},
{
"type": "file_url",
"file_url": {
"url": "https://static.geekai.co/file/2025/05/15/test.md",
"mime_type": "text/markdown"
}
}
]
}
]
}'
需要注意的是,文件对话不支持低价渠道,会直接调用官方API进行对话,不过对于 Gemini 2.5 及以上版本,会自动开启提示缓存,从而大幅降低对话成本。
其他模型/Office文档
非 Gemini 系列模型要进行文件对话或者想要和 Office 文件对话,请通过文件上传/读取接口先获取文件内容,再将文件内容作为对话上下文进行文件对话,该接口支持多种格式文档,包括 PDF、Office、纯文本等。