> ## Documentation Index
> Fetch the complete documentation index at: https://docs.geekai.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 文件对话

### 支持的模型

目前仅 Gemini 对话模型、GLM 视觉模型和豆包Seed对话模型支持原生的 PDF 文件对话，包括：

* `gemini-3.1-pro-preview`
* `gemini-3.1-pro-preview:fast-thinking`
* `gemini-3.1-flash-lite-preview`
* `gemini-3-flash-preview`
* `gemini-3-flash-preview:no-thinking`
* `gemini-2.5-pro`
* `gemini-2.5-pro:fast-thinking`
* `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`
* `glm-5v-turbo`
* `glm-4.6v`
* `glm-4.5v`
* `doubao-seed-2.0-mini`
* `doubao-seed-2.0-lite`
* `doubao-seed-2.0-pro`
* `doubao-seed-2.0-code`
* `doubao-seed-1.8`
* `doubao-seed-1.6-flash`
* `doubao-seed-1.6`
* `doubao-seed-1.6-vision`
* `doubao-seed-1.6-lite`
* `doubao-seed-code-preview`

以 Gemini 为例，模型能够处理 PDF 格式的文档，并利用其原生视觉能力理解文档的整体上下文。这不仅仅是简单的文本提取，而是让 Gemini 能够：

* 分析和解读内容，包括文本、图像、图表和表格，支持长达 1000 页的文档
* 将信息提取为结构化输出格式
* 基于文档的视觉和文本元素进行总结并回答问题
* 转录文档内容（例如转录为 HTML），保留其布局和格式，以便在下游应用程序中使用

### PDF 对话

**单文件**

以下是单文件 PDF 文件对话请求示例：

```bash curl theme={null}
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` 列表即可:

```bash curl theme={null}
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"
            }
          }
        ]
      }
    ]
}'
```

<Note>
  仅 Gemini 模型需要传入 `mime_type` 字段来指定文件类型，其他模型不需要传入该字段。
</Note>

需要注意的是，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` 即可：

```bash curl theme={null}
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 文件对话

目前仅部分 GLM 视觉模型支持原生的 Office 文件对话，包括 Word、Excel、PPT：

* `glm-5v-turbo`
* `glm-4.6v`
* `glm-4.5v`

Office 文件对话的使用方法和 PDF 对话类似，只需要把 `mime_type` 替换为对应的 Office 文件类型即可：

```bash curl theme={null}
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": "glm-5v-turbo",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "请总结文档内容"
          },
          {
            "type": "file_url",
            "file_url": {
                "url": "https://static.geekai.co/file/2026/04/30/test.docx"
            }
          }
        ]
      }
    ]
}'
```

### 其他模型

不支持文件对话或者不支持对应格式文件对话的模型，请通过[文件上传/读取接口](https://docs.geekai.co/cn/api/file)先获取文件内容，再将文件内容作为对话上下文进行文件对话，该接口支持多种格式文档，包括 PDF、Office、纯文本等。

下面我们以 DeepSeek-V4-Flash 和 PDF 文件对话为例进行演示。

**文件预处理**

先通过文件上传接口将 PDF 文件上传并获取文件 ID：

```bash curl theme={null}
curl --location --request POST 'https://geekai.co/api/v1/files' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"./test.pdf"' \
--form 'purpose="file-extract"'
```

响应中的 `uuid` 字段就是文件的唯一标识符，然后通过文件读取接口获取 PDF 文件内容：

```bash curl theme={null}
curl --location --request GET 'https://geekai.co/api/v1/file/{uuid}/content' \
--header 'Authorization: Bearer $GEEKAI_API_KEY'
```

当响应字段 `status` 为 `done` 时，响应字段 `content` 就是 PDF 文件的文本内容了。

**LLM文件对话**

将获取到的 PDF 文件内容作为对话上下文进行对话：

```bash curl theme={null}
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": "deepseek-v4-flash",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "请总结以下文档内容\n\nPDF文档内容：{content}" // 将 content 替换为文件读取接口响应的 content 字段内容
                }
            ]
        }
    ]
}'
```
