Skip to content

File#264

Merged
xiaozhou26 merged 4 commits into
mainfrom
file
Jun 6, 2026
Merged

File#264
xiaozhou26 merged 4 commits into
mainfrom
file

Conversation

@xiaozhou26

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings June 6, 2026 11:06
@xiaozhou26 xiaozhou26 merged commit b6cae06 into main Jun 6, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class file upload + file-aware chat requests by introducing a /v1/files endpoint, extending the “official” request schema to support multimodal content/attachments, and updating the ChatGPT upstream request conversion to include attachment metadata.

Changes:

  • Extend typings/official request message content to support text-or-parts JSON and extract referenced files.
  • Add /v1/files upload handler and an internal ChatGPT upload implementation + in-memory lookup for enriching attachment metadata.
  • Update ChatGPT request typings/conversion to send multimodal parts/metadata; document + add an integration test for file QA.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
typings/official/request.go Introduces APIMessage/MessageContent supporting multimodal parts and file extraction helpers.
typings/chatgpt/request.go Allows ChatGPT request parts to be []interface{} and adds multimodal message support.
conversion/requests/chatgpt/convert.go Builds multimodal ChatGPT message payloads with attachments metadata from official messages.
internal/chatgpt/files.go Implements ChatGPT file upload flow and caches uploaded file metadata for later enrichment.
initialize/router.go Adds CORS preflight + authenticated route for /v1/files.
initialize/handlers.go Adds /v1/files handler and routes token selection through a shared helper; updates token counting for multimodal messages.
tests/test_file_qa.py Adds an integration test that uploads a file then queries it via input_file content parts.
README.md Documents file upload + how to reference file_id in chat requests.
.gitignore Ignores chatgpt2api artifact and normalizes .gocache entry.
Comments suppressed due to low confidence (2)

initialize/handlers.go:189

  • When secretFromAuthorization(...) returns nil (notably when the request includes files and no paid/valid access token is available), the handler responds with a generic "Not Account Found." string. This makes it hard for clients to understand they need a ChatGPT access token for file requests, and is inconsistent with the structured errors used elsewhere in this file (including the new /v1/files endpoint).
	secret := h.secretFromAuthorization(c.GetHeader("Authorization"), original_requestHasFiles(original_request), false)
	if secret == nil {
		c.JSON(400, gin.H{"error": "Not Account Found."})
		c.Abort()
		return

initialize/handlers.go:300

  • responses returns a generic "Not Account Found." when secretFromAuthorization(...) is nil (e.g., when the request contains file parts but no paid/valid access token is available). Returning a structured, actionable error (matching /v1/files) will make client behavior and troubleshooting much clearer.
	secret := h.secretFromAuthorization(c.GetHeader("Authorization"), original_requestHasFiles(original_request), false)
	if secret == nil {
		c.JSON(400, gin.H{"error": "Not Account Found."})
		c.Abort()
		return

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

Comment on lines +60 to +65
func (c *ChatGPTRequest) AddMultimodalMessage(role string, parts []interface{}, metadata map[string]interface{}) {
contentType := "text"
if len(parts) > 1 || (len(parts) == 1 && !isStringPart(parts[0])) {
contentType = "multimodal_text"
}
c.Messages = append(c.Messages, chatgpt_message{
Comment thread initialize/handlers.go
Comment on lines +541 to +559
data, err := io.ReadAll(file)
if err != nil {
c.JSON(400, gin.H{"error": gin.H{
"message": err.Error(),
"type": "invalid_request_error",
"param": "file",
"code": "file_read_error",
}})
return
}
if len(data) == 0 {
c.JSON(400, gin.H{"error": gin.H{
"message": "Uploaded file is empty",
"type": "invalid_request_error",
"param": "file",
"code": "empty_file",
}})
return
}
Comment thread README.md
Comment on lines +58 to +65
```bash
curl -X POST http://localhost:8080/v1/files \
-H "Authorization: Bearer <你的key或access token>" \
-F "purpose=assistants" \
-F "file=@./test.pdf"
然后带 file_id 问答:
```

Comment thread internal/chatgpt/files.go
Comment on lines +35 to +48
var uploadedFiles sync.Map

func RegisterUploadedFile(file UploadedFile) {
if file.FileID == "" {
file.FileID = file.ID
}
if file.ID == "" {
file.ID = file.FileID
}
if file.FileID == "" {
return
}
uploadedFiles.Store(file.FileID, file)
}
@xiaozhou26 xiaozhou26 deleted the file branch June 8, 2026 08:13
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