跳转到主要内容

支持的模型

目前仅 Gemini 对话模型支持原生的 PDF 文件对话,包括:
  • gemini-2.5-pro
  • gemini-2.5-pro:fast
  • gemini-2.5-flash
  • gemini-2.5-flash:no-thinking
  • gemini-2.5-flash-lite
  • gemini-2.5-flash-lite:no-thinking
  • gemini-2.0-flash
  • gemini-2.0-flash-lite
  • gemini-2.5-flash-preview-09-2025
  • gemini-2.5-flash-lite-preview-09-2025
其他 Gemini 预览版也支持文件对话,不过考虑到后面可能会废弃,所以这里不再列举老的预览版。 Gemini 模型能够处理 PDF 格式的文档,并利用其原生视觉能力理解文档的整体上下文。这不仅仅是简单的文本提取,而是让 Gemini 能够:
  • 分析和解读内容,包括文本、图像、图表和表格,支持长达 1000 页的文档
  • 将信息提取为结构化输出格式
  • 基于文档的视觉和文本元素进行总结并回答问题
  • 转录文档内容(例如转录为 HTML),保留其布局和格式,以便在下游应用程序中使用

PDF 对话

单文件 以下是单文件 PDF 文件对话请求示例:
curl
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-2.5-flash",
    "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 列表即可:
curl
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-2.5-flash",
    "messages": [
      {
        "role": "user",
        "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_typetext/javascript
  • Python,对应 mime_typetext/x-python
  • TXT,对应 mime_typetext/plain
  • HTML,对应 mime_typetext/html
  • CSS,对应 mime_typetext/css
  • Markdown,对应 mime_typetext/markdown
  • CSV,对应 mime_typetext/csv
  • XML,对应 mime_typetext/xml
  • RTF,对应 mime_typetext/rtf
以 Markdown 文件为例,示例代码如下,和 PDF 对话格式一样,只需要替换 url 然后将 mime_type 改为 text/markdown 即可:
curl
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-2.5-flash",
    "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"
            }
          }
        ]
      }
    ]
}'

其他模型/Office文档

非 Gemini 系列模型要进行文件对话或者想要和 Office 文件对话,请通过文件上传/读取接口先获取文件内容,再将文件内容作为对话上下文进行文件对话,该接口支持多种格式文档,包括 PDF、Office、纯文本等。