Skip to content

Add file part support to chat message structure #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

alejandrojnm
Copy link

@alejandrojnm alejandrojnm commented Jul 26, 2025

Introduces ChatMessageFile struct and ChatMessageTypeFile constant to support file attachments in chat messages. Updates ChatMessagePart to include file parts and adds comprehensive tests for serialization, deserialization, and constant definitions.

A similar PR may already be submitted!
Please search among the Pull request before creating one.
There is one https://github.com/sashabaranov/go-openai/pull/1053/files but this have the test

Describe the change
This PR is to add file to the message

Provide OpenAI documentation link
https://platform.openai.com/docs/api-reference/chat/create

Describe your solution
The solution is simple, there is not much to explain

Tests
Test are include

Introduces ChatMessagePartFile struct and ChatMessagePartTypeFile constant to support file attachments in chat messages. Updates ChatMessagePart to include file parts and adds comprehensive tests for serialization, deserialization, and constant definitions.
Refactored struct name for file parts in chat messages from ChatMessagePartFile to ChatMessageFile for consistency and clarity.
Corrected the indentation of the File field in the ChatMessagePart struct for improved code readability and consistency.
Replaces usage of ChatMessagePartFile with ChatMessageFile in chat_test.go to reflect updated type naming in the openai package. Also renames related test function for consistency.
Split a long conditional statement in TestMultipartChatMessageSerialization for improved readability.
@alejandrojnm
Copy link
Author

HI @sashabaranov you think we can put this one in the next release ?

@sashabaranov sashabaranov requested a review from Copilot July 30, 2025 10:40
Copy link
Contributor

@Copilot 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

This PR adds support for file attachments in chat messages by introducing a new ChatMessageFile struct and ChatMessagePartTypeFile constant. This enables the OpenAI Go client to handle file parts within chat message structures.

  • Introduces ChatMessageFile struct with fields for file ID, filename, and base64-encoded file data
  • Adds ChatMessagePartTypeFile constant and updates ChatMessagePart to include file support
  • Comprehensive test coverage for serialization, deserialization, and constant validation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
chat.go Defines ChatMessageFile struct, adds ChatMessagePartTypeFile constant, and updates ChatMessagePart to include File field
chat_test.go Adds comprehensive tests for file part functionality including serialization/deserialization and constant validation

Co-authored-by: Copilot <[email protected]>
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (c4273cb) to head (fa78712).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1056   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files          34       34           
  Lines        2205     2205           
=======================================
  Hits         2196     2196           
  Misses          6        6           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant