diff --git a/core/providers/anthropic.go b/core/providers/anthropic.go index fedd65ce5f..eaa81cd07b 100644 --- a/core/providers/anthropic.go +++ b/core/providers/anthropic.go @@ -335,8 +335,11 @@ func buildAnthropicImageSourceMap(imgContent *schemas.ImageURLStruct) map[string urlTypeInfo := ExtractURLTypeInfo(sanitizedURL) formattedImgContent := AnthropicImageContent{ - Type: urlTypeInfo.Type, - MediaType: *urlTypeInfo.MediaType, + Type: urlTypeInfo.Type, + } + + if urlTypeInfo.MediaType != nil { + formattedImgContent.MediaType = *urlTypeInfo.MediaType } if urlTypeInfo.DataURLWithoutPrefix != nil { diff --git a/core/providers/bedrock.go b/core/providers/bedrock.go index c59677f8f1..60dc145da0 100644 --- a/core/providers/bedrock.go +++ b/core/providers/bedrock.go @@ -522,8 +522,11 @@ func (provider *BedrockProvider) prepareChatCompletionMessages(messages []schema urlTypeInfo := ExtractURLTypeInfo(sanitizedURL) formattedImgContent := AnthropicImageContent{ - Type: urlTypeInfo.Type, - MediaType: *urlTypeInfo.MediaType, + Type: urlTypeInfo.Type, + } + + if urlTypeInfo.MediaType != nil { + formattedImgContent.MediaType = *urlTypeInfo.MediaType } if urlTypeInfo.DataURLWithoutPrefix != nil { diff --git a/core/providers/cohere.go b/core/providers/cohere.go index 1467f5e387..5d6445890d 100644 --- a/core/providers/cohere.go +++ b/core/providers/cohere.go @@ -459,9 +459,12 @@ func processImageContent(imageContent *schemas.ImageURLStruct) map[string]interf urlTypeInfo := ExtractURLTypeInfo(sanitizedURL) formattedImgContent := AnthropicImageContent{ - Type: urlTypeInfo.Type, - URL: sanitizedURL, - MediaType: *urlTypeInfo.MediaType, + Type: urlTypeInfo.Type, + URL: sanitizedURL, + } + + if urlTypeInfo.MediaType != nil { + formattedImgContent.MediaType = *urlTypeInfo.MediaType } return map[string]interface{}{ diff --git a/core/providers/openai.go b/core/providers/openai.go index 78c563487e..d146472236 100644 --- a/core/providers/openai.go +++ b/core/providers/openai.go @@ -212,7 +212,7 @@ func prepareOpenAIChatRequest(messages []schemas.BifrostMessage, params *schemas if msg.Role == schemas.ModelChatMessageRoleAssistant { assistantMessage := map[string]interface{}{ "role": msg.Role, - "content": coalesceString(msg.Content.ContentStr), + "content": msg.Content, } if msg.AssistantMessage != nil && msg.AssistantMessage.ToolCalls != nil { assistantMessage["tool_calls"] = *msg.AssistantMessage.ToolCalls diff --git a/core/providers/utils.go b/core/providers/utils.go index 54a215d624..64331f62f4 100644 --- a/core/providers/utils.go +++ b/core/providers/utils.go @@ -338,15 +338,6 @@ func StrPtr(s string) *string { return &s } -// coalesceString returns the string value of a pointer to a string, or an empty string if the pointer is nil. -// This is a helper function for safely handling pointer-to-string values. -func coalesceString(s *string) string { - if s == nil { - return "" - } - return *s -} - //* IMAGE UTILS *// // SanitizeImageURL sanitizes and validates an image URL.