|
@@ -76,13 +76,17 @@ func openAIChatToOllamaChat(c *gin.Context, r *dto.GeneralOpenAIRequest) (*Ollam
|
|
|
if part.Type == dto.ContentTypeImageURL {
|
|
if part.Type == dto.ContentTypeImageURL {
|
|
|
img := part.GetImageMedia()
|
|
img := part.GetImageMedia()
|
|
|
if img != nil && img.Url != "" {
|
|
if img != nil && img.Url != "" {
|
|
|
- // ensure base64 dataURL
|
|
|
|
|
|
|
+ var base64Data string
|
|
|
if strings.HasPrefix(img.Url, "http") {
|
|
if strings.HasPrefix(img.Url, "http") {
|
|
|
fileData, err := service.GetFileBase64FromUrl(c, img.Url, "fetch image for ollama chat")
|
|
fileData, err := service.GetFileBase64FromUrl(c, img.Url, "fetch image for ollama chat")
|
|
|
if err != nil { return nil, err }
|
|
if err != nil { return nil, err }
|
|
|
- img.Url = fmt.Sprintf("data:%s;base64,%s", fileData.MimeType, fileData.Base64Data)
|
|
|
|
|
|
|
+ base64Data = fileData.Base64Data
|
|
|
|
|
+ } else if strings.HasPrefix(img.Url, "data:") {
|
|
|
|
|
+ if idx := strings.Index(img.Url, ","); idx != -1 && idx+1 < len(img.Url) { base64Data = img.Url[idx+1:] }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ base64Data = img.Url
|
|
|
}
|
|
}
|
|
|
- images = append(images, img.Url)
|
|
|
|
|
|
|
+ if base64Data != "" { images = append(images, base64Data) }
|
|
|
}
|
|
}
|
|
|
} else if part.Type == dto.ContentTypeText {
|
|
} else if part.Type == dto.ContentTypeText {
|
|
|
textBuilder.WriteString(part.Text)
|
|
textBuilder.WriteString(part.Text)
|