Method: projects.locations.collections.engines.sessions.addContextFile

上传一个上下文文件,用作会话中辅助调用的来源。

HTTP 请求

POST https://discoveryengine.googleapis.com/v1alpha/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}:addContextFile

网址采用 gRPC 转码语法。

路径参数

参数
name

string

必需。会话的资源名称。格式:projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}

如果指定 - 作为会话 ID,则系统会创建一个具有自动生成 ID 的新会话。

请求正文

请求正文中包含结构如下的数据:

JSON 表示法
{
  "fileName": string,
  "mimeType": string,

  // Union field file can be only one of the following:
  "fileContents": string,
  "document": string
  // End of list of possible types for union field file.
}
字段
fileName

string

必需。相应文件的名称。

mimeType

string

可选。相应文件的内容类型,请参阅 https://www.iana.org/assignments/media-types/media-types.xhtml

如果数据源未提供内容类型,则这是必需字段。

联合字段 file。文件的内容。file 只能是下列其中一项:
fileContents

string (bytes format)

内嵌提供的文件内容。

使用 base64 编码的字符串。

document

string

Document 的资源名称。调用方需要有权访问 Document,否则会返回 PERMISSION_DENIED 错误。

格式:projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}/branches/{branch}/documents/{document}

响应正文

AssistantService.AddContextFile 方法的响应。

如果成功,响应正文将包含结构如下的数据:

JSON 表示法
{
  "session": string,
  "fileId": string,
  "tokenCount": string,
  "mimeType": string,
  "byteCount": string,
  "fileName": string
}
字段
session

string

会话的名称,可以是提供的名称,也可以是新创建的名称。

格式:projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/sessions/{session}

fileId

string

上传文件的 ID。

tokenCount
(deprecated)

string (int64 format)

已弃用:此字段不会针对所有文件类型进行设置,最终将被移除。

文件长度(以 token 为单位)。

mimeType

string

仅限输出。已解析的上传文件内容类型,请参阅 https://www.iana.org/assignments/media-types/media-types.xhtml

与调用方提供的可选 AddContextFileRequest.mime_type 不同,这是服务实际为文件解析的内容类型。

byteCount

string (int64 format)

仅限输出。上传文件的大小(以字节为单位)。

fileName

string

仅限输出。已解析的上传文件名称,包括文件扩展名。

与调用方提供的 AddContextFileRequest.file_name 不同,当调用方提供的名称没有扩展名时,服务会附加与已解析的 mimeType 匹配的扩展名,因此,即使是通用名称的 AI 生成文件,使用情况审核日志也会捕获文件类型。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/discoveryengine.assist.readwrite
  • https://www.googleapis.com/auth/discoveryengine.readwrite
  • https://www.googleapis.com/auth/discoveryengine.serving.readwrite

如需了解详情,请参阅 Authentication Overview

IAM 权限

需要拥有 name 资源的以下 IAM 权限:

  • discoveryengine.sessions.addContextFile

如需了解详情,请参阅 IAM 文档