From 8a62e987894dc6b0b083d23acfcfad9547fa1106 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 24 Nov 2025 12:00:46 +0300 Subject: Fix: apilinks rotation --- llm.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'llm.go') diff --git a/llm.go b/llm.go index a63317e..d22ede2 100644 --- a/llm.go +++ b/llm.go @@ -205,7 +205,6 @@ func (op OpenAIer) FormMsg(msg, role string, resume bool) (io.Reader, error) { newMsg = models.NewRoleMsg(role, msg) } chatBody.Messages = append(chatBody.Messages, newMsg) - // if rag - add as system message to avoid conflicts with tool usage if cfg.RAGEnabled { ragResp, err := chatRagUse(newMsg.Content) @@ -485,7 +484,28 @@ func (or OpenRouterChat) FormMsg(msg, role string, resume bool) (io.Reader, erro chatBody.Messages = append(chatBody.Messages, models.RoleMsg{Role: cfg.ToolRole, Content: toolSysMsg}) } if msg != "" { // otherwise let the bot continue - newMsg := models.RoleMsg{Role: role, Content: msg} + var newMsg models.RoleMsg + // Check if we have an image to add to this message + if imageAttachmentPath != "" { + // Create a multimodal message with both text and image + newMsg = models.NewMultimodalMsg(role, []interface{}{}) + // Add the text content + newMsg.AddTextPart(msg) + // Add the image content + imageURL, err := models.CreateImageURLFromPath(imageAttachmentPath) + if err != nil { + logger.Error("failed to create image URL from path", "error", err, "path", imageAttachmentPath) + // If image processing fails, fall back to simple text message + newMsg = models.NewRoleMsg(role, msg) + imageAttachmentPath = "" // Clear the attachment + } else { + newMsg.AddImagePart(imageURL) + imageAttachmentPath = "" // Clear the attachment after use + } + } else { + // Create a simple text message + newMsg = models.NewRoleMsg(role, msg) + } chatBody.Messages = append(chatBody.Messages, newMsg) // if rag - add as system message to avoid conflicts with tool usage if cfg.RAGEnabled { -- cgit v1.2.3