Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

文件配置对象结构

概述

fileConfig 对象允许您配置应用程序的文件处理设置,包括大小限制和 MIME 类型限制。本节详细介绍了 fileConfig 对象的结构。

fileConfig 下有 8 个主要字段:

  • endpoints
  • serverFileSizeLimit
  • avatarSizeLimit
  • imageGeneration
  • fileTokenLimit
  • ocr
  • text
  • stt

注意:

  • 在撰写本文时,Assistants endpoint 支持此列表中的文件类型
  • OpenAI、Azure OpenAI、Google 和 Custom endpoint 通过 RAG API 支持文件。
  • OpenAI、Azure OpenAI、Anthropic、Google 和 AWS Bedrock endpoint 支持通过 Upload to Provider 直接上传文件。
  • ocrtextstt 部分用于控制文件处理功能,例如 Upload as TextOCR
  • 任何其他未提及的 endpoint(例如 Plugins)尚不支持文件上传。
  • Assistants endpoint 的定义 endpoint 值为 assistants。所有其他 endpoint 均使用定义的 default 值。
    • 对于非 Assistants 的 endpoint,你可以在 default 下为它们统一调整文件设置。
    • 如果您想调整特定 endpoint 的设置,可以列出它们对应的 endpoint 名称:
      • assistants
        • 不使用 "default",因为它定义了独立于其他项的默认值。
      • openAI
      • azureOpenAI
      • google
      • bedrock
      • YourCustomEndpointName
  • 您可以省略这些值,在这种情况下,应用程序将使用下文针对每种 endpoint 类型所定义的默认值。
  • LibreChat 将 1 兆字节计算为:1 x 1024 x 1024

示例

fileConfig:
  endpoints:
    assistants:
      fileLimit: 5
      fileSizeLimit: 10
      totalSizeLimit: 50
      supportedMimeTypes:
        - "image/.*"
        - "application/pdf"
    openAI:
      disabled: true
    default:
      totalSizeLimit: 20
    YourCustomEndpointName:
      fileLimit: 5
      fileSizeLimit: 1000
      supportedMimeTypes:
        - "image/.*"
  serverFileSizeLimit: 1000
  avatarSizeLimit: 2
  fileTokenLimit: 100000
  imageGeneration:
    percentage: 100
    px: 1024
  ocr:
    supportedMimeTypes:
      - "^image/(jpeg|gif|png|webp|heic|heif)$"
      - "^application/pdf$"
      - "^application/vnd\\.openxmlformats-officedocument\\.(wordprocessingml\\.document|presentationml\\.presentation|spreadsheetml\\.sheet)$"
      - "^application/vnd\\.ms-(word|powerpoint|excel)$"
      - "^application/epub\\+zip$"
  text:
    supportedMimeTypes:
      - "^text/(plain|markdown|csv|json|xml|html|css|javascript|typescript|x-python|x-java|x-csharp|x-php|x-ruby|x-go|x-rust|x-kotlin|x-swift|x-scala|x-perl|x-lua|x-shell|x-sql|x-yaml|x-toml)$"
  stt:
    supportedMimeTypes:
      - "^audio/(mp3|mpeg|mpeg3|wav|wave|x-wav|ogg|vorbis|mp4|x-m4a|flac|x-flac|webm)$"

serverFileSizeLimit

KeyTypeDescriptionExample
serverFileSizeLimitInteger上传至服务器的任何文件的全局最大大小,以兆字节 (MB) 为单位。Acts as an overarching limit for file uploads across all endpoints, ensuring that no file exceeds this size server-wide.
fileConfig:
  serverFileSizeLimit: 1000

avatarSizeLimit

KeyTypeDescriptionExample
avatarSizeLimitInteger头像图片允许的最大尺寸,以兆字节 (MB) 为单位。Specifically tailored for user avatar uploads, allowing for control over image sizes to maintain consistent quality and loading times.
fileConfig:
  avatarSizeLimit: 2

imageGeneration

KeyTypeDescriptionExample
imageGenerationObject与图像生成输出质量和尺寸相关的设置。Allows configuration of either output size as a percentage relative to some base size or as an explicit pixel dimension.

imageGeneration 支持以下参数:

  • percentage (整数)

    • 生成的图像输出大小,以百分比表示(例如,100 表示基础大小的 100%)。
    • 使用此项可相对于默认或原始尺寸缩放输出图像。
  • px (整数)

    • 指定输出图像的尺寸(以像素为单位,例如 1024)。
    • 使用此选项可明确设置生成图像的输出尺寸,而无需考虑基础尺寸。

根据您的使用场景,您可以设置这些参数中的其中一个(percentagepx),但不能同时设置两者。

配置示例:

fileConfig:
  imageGeneration:
    percentage: 100
    px: 1024

fileTokenLimit

KeyTypeDescriptionExample
fileTokenLimitNumber在截断前包含在提示词中的文本文件最大 Token 数。fileTokenLimit: 100000

描述: 当附加文本内容时,LibreChat 会在运行时于提示词构建前,将文本截断至配置的 token 限制。

默认值: 100000

fileConfig:
  fileTokenLimit: 100000

ocr

KeyTypeDescriptionExample
ocrObject用于光学字符识别 (OCR) 文件处理的设置。Configures which file types are processed using OCR.

描述: ocr 部分用于配置哪些文件类型应使用 OCR 功能进行处理,以从视觉文档中提取文本。

注意: 本节控制用于 OCR 处理的文件类型匹配。要启用 Agent 功能并配置 OCR 服务,请参阅:

supportedMimeTypes

KeyTypeDescriptionExample
supportedMimeTypesArray of Strings应使用 OCR 处理的文件 MIME 类型模式列表。Uses regular expressions to match file types.

默认: 图片、PDF 和 Office 文档

fileConfig:
  ocr:
    supportedMimeTypes:
      - "^image/(jpeg|gif|png|webp|heic|heif)$"
      - "^application/pdf$"
      - "^application/vnd\\.openxmlformats-officedocument\\.(wordprocessingml\\.document|presentationml\\.presentation|spreadsheetml\\.sheet)$"
      - "^application/vnd\\.ms-(word|powerpoint|excel)$"
      - "^application/epub\\+zip$"

text

KeyTypeDescriptionExample
textObject无需 OCR 直接解析文本文件的设置。Configures which file types are processed as plain text files for direct content extraction.

Description: text 部分用于配置应使用直接文本提取处理的文件类型。

注意: 文本解析是“作为文本上传”(Upload as Text)功能(由 context 能力控制)所使用的默认方法。它首先尝试使用来自 RAG API 的文本解析库;如果未连接 RAG API,它将回退到一种无需任何外部服务的更简单的文本提取方法。有关更多信息,请参阅 作为文本上传

supportedMimeTypes

KeyTypeDescriptionExample
supportedMimeTypesArray of Strings应解析为纯文本的文件 MIME 类型模式列表。Uses regular expressions to match file types.

默认值: 所有文本文件和常见编程语言

fileConfig:
  text:
    supportedMimeTypes:
      - "^text/(plain|markdown|csv|json|xml|html|css|javascript|typescript|x-python|x-java|x-csharp|x-php|x-ruby|x-go|x-rust|x-kotlin|x-swift|x-scala|x-perl|x-lua|x-shell|x-sql|x-yaml|x-toml)$"

stt

KeyTypeDescriptionExample
sttObject用于语音转文字 (STT) 音频文件处理的设置。Configures which audio file types are processed using STT for transcription.

描述: stt 部分用于配置哪些音频文件类型应使用语音转文字(Speech-to-Text)功能进行处理,以将音频转换为文本。

supportedMimeTypes

KeyTypeDescriptionExample
supportedMimeTypesArray of Strings应使用 STT 进行转录的音频文件 MIME 类型模式列表。Uses regular expressions to match audio file types.

默认: 常见音频格式

fileConfig:
  stt:
    supportedMimeTypes:
      - "^audio/(mp3|mpeg|mpeg3|wav|wave|x-wav|ogg|vorbis|mp4|x-m4a|flac|x-flac|webm)$"

注意:

  • 匹配 text 模式的文件将通过简单的文本提取进行处理
  • 匹配 ocr 模式的文件将使用提供的 OCR 服务进行处理
  • 匹配 stt 模式的文件将通过语音转文字(Speech-to-Text)进行处理
  • 处理优先级:OCR > STT > 文本解析 > 回退
  • 不匹配任何模式的文件将回退到文本解析。

文件处理优先级

LibreChat 根据 MIME 类型匹配,按照以下优先级顺序处理上传的文件:

  1. OCR - 如果文件符合 ocr.supportedMimeTypes 且已配置 OCR
  2. STT - 如果文件符合 stt.supportedMimeTypes 且已配置 STT
  3. 文本解析 - 如果文件匹配 text.supportedMimeTypes
  4. 回退 (Fallback) - 作为最后手段的文本解析

此处理顺序可确保最佳的提取质量,同时在未配置专用服务(OCR/STT)时也能保持功能正常。

处理示例

配置了 OCR 的 PDF 文件:

  • 文件匹配 ocr.supportedMimeTypes
  • 使用 OCR 提取文本
  • 针对扫描版 PDF 和图像提供更好的质量

未配置 OCR 的 PDF 文件:

  • 文件匹配 text.supportedMimeTypes(或使用回退方案)
  • 使用文本解析
  • 适用于具有可选文本的数字 PDF

Python 文件:

  • 文件匹配 text.supportedMimeTypes
  • 使用文本解析(无需 OCR)
  • 直接文本提取

配置了 STT 的音频文件:

  • 文件匹配 stt.supportedMimeTypes
  • 使用 STT 将音频转录为文本

未配置 OCR 的图像文件:

  • 文件匹配 ocr.supportedMimeTypes 但 OCR 不可用
  • 回退至文本解析
  • 在没有 OCR 的情况下提取能力受限

此优先级系统允许诸如“上传为文本 (Upload as Text)”之类的功能在无需配置 OCR 的情况下正常工作,同时在 OCR 可用时仍能利用其来提高提取质量。

endpoints

KeyTypeDescriptionExample
endpointsRecord/Object为各个 endpoint 配置文件处理设置,允许按 endpoint 进行自定义。Specifies file handling configurations for individual endpoints, allowing customization per endpoint basis.

描述: endpoints 下的每个对象都是一条记录,可以包含以下设置:

概述

  • disabled
    • 是否为该 endpoint 禁用文件处理。
  • fileLimit
    • 每次上传请求允许的最大文件数量。
  • fileSizeLimit
    • 单个文件的最大大小。单位为 MB(例如,使用 20 表示 20 兆字节)
  • totalSizeLimit
    • 单次请求中所有文件的总最大大小。单位为 MB(例如,使用 20 表示 20 兆字节)
  • supportedMimeTypes
    • 一个指定允许上传哪些 MIME 类型的 Regular Expressions 列表。可以对其进行自定义以限制文件类型。

disabled

KeyTypeDescriptionExample
disabledBoolean指示是否针对特定 endpoint 禁用文件上传。Setting this to `true` prevents any file uploads to the specified endpoint, overriding any other file-related settings.

默认值: false

openAI:
  disabled: true

fileLimit

密钥:

KeyTypeDescriptionExample
fileLimitInteger单次上传请求中允许的最大文件数量。Helps control the volume of uploads and manage server load.

默认值: 因 endpoint 而异

assistants:
  fileLimit: 5

fileSizeLimit

密钥:

KeyTypeDescriptionExample
fileSizeLimitInteger每个单独文件允许的最大大小,以兆字节 (MB) 为单位。This limit ensures that no single file exceeds the specified size, allowing for better resource allocation and management.

默认值: 因 endpoint 而异

YourCustomEndpointName:
  fileSizeLimit: 1000

totalSizeLimit

密钥:

KeyTypeDescriptionExample
totalSizeLimitInteger单次请求中所有文件允许的总最大大小,以兆字节 (MB) 为单位。This setting is crucial for preventing excessive bandwidth and storage usage by any single upload request.

默认值: 因 endpoint 而异

assistants:
  totalSizeLimit: 50

supportedMimeTypes

密钥:

KeyTypeDescriptionExample
supportedMimeTypesArray of Strings定义允许上传的 MIME 类型的正则表达式列表。This allows for precise control over the types of files that can be uploaded. Invalid regex is ignored.

默认值: 因 endpoint 而异

assistants:
  supportedMimeTypes:
      - "image/.*"
      - "application/pdf"

这篇指南怎么样?