add file data and file URL support for chat completions responses #2497
Open
Simba98 wants to merge 1 commit into
Open
add file data and file URL support for chat completions responses #2497Simba98 wants to merge 1 commit into
Simba98 wants to merge 1 commit into
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
Contributor
There was a problem hiding this comment.
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/ResponsesContentParttypes 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
fileobject usingfile_dataandfile_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 | ||
| } | ||
| } |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add file data and file URL support for chat completions responses
PR Description / 描述
English
Summary
This PR adds support for
filecontent parts when converting Chat Completions requests into Responses API input items.The conversion now supports:
file_datafor inline/base64 file payloadsfile_urlfor externally hosted file referencesfilenamepreservation for Responsesinput_filepartsfilepayloads and flat file fields for broader client compatibilityChanges
ChatContentPartin types.go to supportfilecontent parts.ChatFilemetadata/source structure.ResponsesContentPartwithfile_data,file_url, andfilename.input_fileparts.Testing
Added unit coverage for:
filepart withfile_datafilepart withfile_url中文
摘要
本 PR 为 Chat Completions 请求转换到 Responses API 输入结构时添加了
file内容块支持。现在转换逻辑支持:
file_data传递内联/base64 文件内容file_url传递外部文件引用filename并映射到 Responsesinput_filefile对象与扁平文件字段,提升不同客户端 payload 的兼容性变更内容
ChatContentPart,支持file类型内容块。ChatFile结构用于描述文件名、文件数据和文件 URL。ResponsesContentPart增加file_data、file_url和filename字段。input_file内容块。测试
新增单元测试覆盖:
file_data的 Chat Completionsfile内容块转换file_url的 Chat Completionsfile内容块转换Commit / 提交
1720b2d3f20d1a8b96964a58c61b2cefcfc1ca92feat: add support for file data and file URLs in chat completions responses