mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-30 21:51:45 +00:00
fix: 修复图像URL处理逻辑,确保正确生成base64数据
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user