Skip to content

Conversation

@kabirkhan
Copy link

Update to the most recent sashabaranov/master changes.
Also merge the commits from this currently Open PR: sashabaranov#1056

This change adds support for the File input parameters to the Chat Completions API and supports the Document input work in ai-guide.

alejandrojnm and others added 9 commits July 26, 2025 13:52
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.
Co-authored-by: Copilot <[email protected]>
@kabirkhan kabirkhan changed the title Release/v1.41.2 Add file input support to Chat Completion types Oct 28, 2025
Comment on lines +74 to +78
// only 3.5 models have the "." stripped in their names
if strings.Contains(model, "3.5") {
return regexp.MustCompile(`[.:]`).ReplaceAllString(model, "")
}
return strings.ReplaceAll(model, ":", "")
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the latest from upstream main. No worries from me about this.

Comment on lines +84 to +103
// ChatMessageFile is a placeholder for file parts in chat messages.
type ChatMessageFile struct {
FileID string `json:"file_id,omitempty"`
FileName string `json:"filename,omitempty"`
FileData string `json:"file_data,omitempty"` // Base64 encoded file data
}

type ChatMessagePartType string

const (
ChatMessagePartTypeText ChatMessagePartType = "text"
ChatMessagePartTypeImageURL ChatMessagePartType = "image_url"
ChatMessagePartTypeFile ChatMessagePartType = "file"
)

type ChatMessagePart struct {
Type ChatMessagePartType `json:"type,omitempty"`
Text string `json:"text,omitempty"`
ImageURL *ChatMessageImageURL `json:"image_url,omitempty"`
File *ChatMessageFile `json:"file,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Assuming these all checkout to what OpenAI expects, LGTM. Alas, I'm failing to find where this API is documented in their chat completion API documentation.

Choose a reason for hiding this comment

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

Copy link

@matthewmorgan matthewmorgan left a comment

Choose a reason for hiding this comment

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

Thanks @kabirkhan ! I feel good about this knowing you and @rjcorwin have both looked at it. Looks correct to me.

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.

6 participants