Skip to content

add file data and file URL support for chat completions responses #2497

Open
Simba98 wants to merge 1 commit into
Wei-Shaw:mainfrom
Simba98:add_file_support
Open

add file data and file URL support for chat completions responses #2497
Simba98 wants to merge 1 commit into
Wei-Shaw:mainfrom
Simba98:add_file_support

Conversation

@Simba98
Copy link
Copy Markdown

@Simba98 Simba98 commented May 15, 2026

feat: add file data and file URL support for chat completions responses

PR Description / 描述

English

Summary

This PR adds support for file content parts when converting Chat Completions requests into Responses API input items.

The conversion now supports:

  • file_data for inline/base64 file payloads
  • file_url for externally hosted file references
  • filename preservation for Responses input_file parts
  • both nested file payloads and flat file fields for broader client compatibility

Changes

  • Extended ChatContentPart in types.go to support file content parts.
  • Added ChatFile metadata/source structure.
  • Extended ResponsesContentPart with file_data, file_url, and filename.
  • Updated conversion logic in chatcompletions_to_responses.go to emit input_file parts.
  • Added tests in chatcompletions_responses_test.go covering both inline file data and file URL inputs.

Testing

Added unit coverage for:

  • Chat Completions file part with file_data
  • Chat Completions file part with file_url

中文

摘要

本 PR 为 Chat Completions 请求转换到 Responses API 输入结构时添加了 file 内容块支持。

现在转换逻辑支持:

  • 使用 file_data 传递内联/base64 文件内容
  • 使用 file_url 传递外部文件引用
  • 保留 filename 并映射到 Responses input_file
  • 同时兼容嵌套 file 对象与扁平文件字段,提升不同客户端 payload 的兼容性

变更内容

  • 在 types.go 中扩展 ChatContentPart,支持 file 类型内容块。
  • 新增 ChatFile 结构用于描述文件名、文件数据和文件 URL。
  • ResponsesContentPart 增加 file_datafile_urlfilename 字段。
  • 更新 chatcompletions_to_responses.go 中的转换逻辑,生成 input_file 内容块。
  • 在 chatcompletions_responses_test.go 中新增测试,覆盖文件数据和文件 URL 两种输入场景。

测试

新增单元测试覆盖:

  • file_data 的 Chat Completions file 内容块转换
  • file_url 的 Chat Completions file 内容块转换

Commit / 提交

1720b2d3f20d1a8b96964a58c61b2cefcfc1ca92
feat: add support for file data and file URLs in chat completions responses

Copilot AI review requested due to automatic review settings May 15, 2026 13:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds file content support to the API compatibility layer by extending chat content parts and mapping "file" chat parts into Responses "input_file" parts.

Changes:

  • Extend ChatContentPart / ResponsesContentPart types to include file metadata and sources (file_data, file_url, filename).
  • Convert chat "file" content parts into Responses "input_file" parts, supporting both nested and flat payload shapes.
  • Add tests for file conversion via nested file object using file_data and file_url.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
backend/internal/pkg/apicompat/types.go Adds file-related fields/types for chat and responses content parts.
backend/internal/pkg/apicompat/chatcompletions_to_responses.go Implements conversion of "file" chat parts to "input_file" response parts.
backend/internal/pkg/apicompat/chatcompletions_responses_test.go Adds tests validating file conversion for file_data and file_url.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +349 to +371
case "file":
fileData := p.FileData
fileURL := p.FileURL
filename := p.Filename
if p.File != nil {
if fileData == "" {
fileData = p.File.FileData
}
if fileURL == "" {
fileURL = p.File.FileURL
}
if filename == "" {
filename = p.File.Filename
}
}
if fileData != "" || fileURL != "" {
responseParts = append(responseParts, ResponsesContentPart{
Type: "input_file",
FileData: fileData,
FileURL: fileURL,
Filename: filename,
})
}
Comment on lines +350 to +363
fileData := p.FileData
fileURL := p.FileURL
filename := p.Filename
if p.File != nil {
if fileData == "" {
fileData = p.File.FileData
}
if fileURL == "" {
fileURL = p.File.FileURL
}
if filename == "" {
filename = p.File.Filename
}
}
Comment on lines +350 to +363
fileData := p.FileData
fileURL := p.FileURL
filename := p.Filename
if p.File != nil {
if fileData == "" {
fileData = p.File.FileData
}
if fileURL == "" {
fileURL = p.File.FileURL
}
if filename == "" {
filename = p.File.Filename
}
}
@Simba98
Copy link
Copy Markdown
Author

Simba98 commented May 15, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants