diff --git a/providers/anthropic/anthropic.go b/providers/anthropic/anthropic.go index 25ac81dab38230debc3c5ad6fb5d6cb933665a30..5c7b1d4ed3123bbd5c0fad46f3d5b5e9383ab9ac 100644 --- a/providers/anthropic/anthropic.go +++ b/providers/anthropic/anthropic.go @@ -726,16 +726,20 @@ func toPrompt(prompt fantasy.Prompt, sendReasoningData bool) ([]anthropic.TextBl continue } // TODO: handle other file types - if !strings.HasPrefix(file.MediaType, "image/") { - continue - } - - base64Encoded := base64.StdEncoding.EncodeToString(file.Data) - imageBlock := anthropic.NewImageBlockBase64(file.MediaType, base64Encoded) - if cacheControl != nil { - imageBlock.OfImage.CacheControl = anthropic.NewCacheControlEphemeralParam() + switch { + case strings.HasPrefix(file.MediaType, "image/"): + base64Encoded := base64.StdEncoding.EncodeToString(file.Data) + imageBlock := anthropic.NewImageBlockBase64(file.MediaType, base64Encoded) + if cacheControl != nil { + imageBlock.OfImage.CacheControl = anthropic.NewCacheControlEphemeralParam() + } + anthropicContent = append(anthropicContent, imageBlock) + case strings.HasPrefix(file.MediaType, "text/"): + documentBlock := anthropic.NewDocumentBlock(anthropic.PlainTextSourceParam{ + Data: string(file.Data), + }) + anthropicContent = append(anthropicContent, documentBlock) } - anthropicContent = append(anthropicContent, imageBlock) } } } else if msg.Role == fantasy.MessageRoleTool { diff --git a/providers/openai/language_model_hooks.go b/providers/openai/language_model_hooks.go index 10124883572c43391f75358d374a5019d44b639d..b3e94ceef29de859cca682bd31df7a3d6e30b5d5 100644 --- a/providers/openai/language_model_hooks.go +++ b/providers/openai/language_model_hooks.go @@ -363,6 +363,13 @@ func DefaultToPrompt(prompt fantasy.Prompt, _, _ string) ([]openai.ChatCompletio } switch { + case strings.HasPrefix(filePart.MediaType, "text/"): + base64Encoded := base64.StdEncoding.EncodeToString(filePart.Data) + documentBlock := openai.ChatCompletionContentPartFileFileParam{ + FileData: param.NewOpt(base64Encoded), + } + content = append(content, openai.FileContentPart(documentBlock)) + case strings.HasPrefix(filePart.MediaType, "image/"): // Handle image files base64Encoded := base64.StdEncoding.EncodeToString(filePart.Data) diff --git a/providers/openaicompat/language_model_hooks.go b/providers/openaicompat/language_model_hooks.go index d11da4a1b1b09903df192fc74ce20339e5eb0c60..36c847e028504e05c6da3ffc8e8b58c528b59f61 100644 --- a/providers/openaicompat/language_model_hooks.go +++ b/providers/openaicompat/language_model_hooks.go @@ -209,6 +209,13 @@ func ToPromptFunc(prompt fantasy.Prompt, _, _ string) ([]openaisdk.ChatCompletio } switch { + case strings.HasPrefix(filePart.MediaType, "text/"): + base64Encoded := base64.StdEncoding.EncodeToString(filePart.Data) + documentBlock := openaisdk.ChatCompletionContentPartFileFileParam{ + FileData: param.NewOpt(base64Encoded), + } + content = append(content, openaisdk.FileContentPart(documentBlock)) + case strings.HasPrefix(filePart.MediaType, "image/"): // Handle image files base64Encoded := base64.StdEncoding.EncodeToString(filePart.Data)