Explorar o código

fix: 修复图像URL处理逻辑,确保正确生成base64数据

somnifex hai 5 meses
pai
achega
4eeca081fe
Modificáronse 1 ficheiros con 7 adicións e 3 borrados
  1. 7 3
      relay/channel/ollama/relay-ollama.go

+ 7 - 3
relay/channel/ollama/relay-ollama.go

@@ -76,13 +76,17 @@ func openAIChatToOllamaChat(c *gin.Context, r *dto.GeneralOpenAIRequest) (*Ollam
 				if part.Type == dto.ContentTypeImageURL {
 					img := part.GetImageMedia()
 					if img != nil && img.Url != "" {
-						// ensure base64 dataURL
+						var base64Data string
 						if strings.HasPrefix(img.Url, "http") {
 							fileData, err := service.GetFileBase64FromUrl(c, img.Url, "fetch image for ollama chat")
 							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 {
 					textBuilder.WriteString(part.Text)