[Bug]: Error occurs when I connect to RAGFlow through MCP(OpenAI compatible endpoint) with VLM models.

用户在 Hyper-V 上的 Linux(trisquel_12)环境中运行 RAGFlow(镜像版本 v0.26.1),通过 MCP(OpenAI 兼容端点)连接时,使用 Qwen3.6-35B-A3B-UD-Q4_K_XL(带 VLM)或 gemma-4-E4B-it-UD-Q4_K_XL(带

[Bug]: Error occurs when I connect to RAGFlow through MCP(OpenAI compatible endpoint) with VLM models.

[Bug]: Error occurs when I connect to RAGFlow through MCP(OpenAI compatible endpoint) with VLM models.

快速结论:该报错发生在通过 MCP(OpenAI 兼容端点)连接 RAGFlow 并使用 VLM(视觉语言模型)时,原因是 images 参数被错误地直接传给了 OpenAI SDK 的 chat.completions.create() 方法。优先排查 rag/llm/chat_model.py_async_chat_async_chat_streamly 函数是否缺少对 images 参数的预处理。

问题场景

用户在 Hyper-V 上的 Linux(trisquel_12)环境中运行 RAGFlow(镜像版本 v0.26.1),通过 MCP(OpenAI 兼容端点)连接时,使用 Qwen3.6-35B-A3B-UD-Q4_K_XL(带 VLM)或 gemma-4-E4B-it-UD-Q4_K_XL(带 VLM)模型触发报错。

报错原文

AUTH_ERROR - AsyncCompletions.create() got an unexpected keyword argument 'images'

原因分析

这是一个已确认的 bug。在 rag/llm/chat_model.py_async_chat_streamly_async_chat 方法中,**kwargs 中的 images 参数被直接传递给了 OpenAI SDK 的 chat.completions.create()。该 SDK 不接受 images 作为顶级参数,而是要求将图片嵌入到 messages 内容结构中(作为 image_url 对象)。RAGFlow 自身的 cv_model.py 中已经实现了正确的模式。

可能原因:用户通过 AI Agent(Hermes Agent)建议的修复方案可能有效,但 Git 提交历史中并未包含正式补丁,因此仍可能是环境或配置问题。

环境排查

  • RAGFlow 版本:v0.26.1(Git commit ID: a3e3bdd38682b5c71c15cc92e8827b6702dcd93e)
  • 操作系统:Linux (trisquel_12)
  • 硬件:Hyper-V 虚拟化环境
  • LLM 模型:Qwen3.6-35B-A3B-UD-Q4_K_XL(带 VLM)或 gemma-4-E4B-it-UD-Q4_K_XL(带 VLM)
  • 前端:OpenCode
  • 确认目标文件:rag/llm/chat_model.py,特别是 _async_chat_streamly_async_chat 方法

解决步骤

注意:以下修复方案源于 Issue 用户提供的 AI Agent 建议,未经官方合并。请谨慎操作,并在修改前备份原文件。

  1. 备份原始文件:
    cp rag/llm/chat_model.py rag/llm/chat_model.py.bak
  2. 修改 _async_chat_streamly 方法(大约 212 行附近):

    • 在函数体中增加:images = kwargs.pop("images", None)
    • 如果 images 不为 None,调用一个辅助方法(例如 self._inject_images_into_history(history, images))将图片注入到消息历史中。
    • 修改后的 request_kwargs 中不再包含 images 字段。
    async def _async_chat_streamly(self, history, gen_conf, **kwargs):
        logging.info("[HISTORY STREAMLY]" + json.dumps(history, ensure_ascii=False, indent=4))
        reasoning_start = False
    
        # Handle images parameter - convert to OpenAI multimodal format
        images = kwargs.pop("images", None)
        if images:
            history = self._inject_images_into_history(history, images)
    
        request_kwargs = {"model": self.model_name, "messages": history, "stream": True, **gen_conf}
        stop = kwargs.get("stop")
        if stop:
            request_kwargs["stop"] = stop
    
        response = await self.async_client.chat.completions.create(**request_kwargs)
  3. 添加 _inject_images_into_history 辅助方法(可添加到类中合适位置,例如 610-645 行附近):

    def _inject_images_into_history(self, history, images):
        if not images:
            return history
        import base64
        
        if isinstance(images, str):
            images = [images]
        
        new_history = []
        for msg in history:
            if msg.get("role") == "user" and images:
                img = images[0]
                images = images[1:]
                if isinstance(img, bytes):
                    img_b64 = base64.b64encode(img).decode("utf-8")
                elif img.startswith("data:"):
                    img_b64 = img
                elif img.startswith("http"):
                    img_b64 = img
                else:
                    img_b64 = "data:image/png;base64," + img
                
                content = msg.get("content", "")
                new_content = [
                    {"type": "text", "text": content},
                    {"type": "image_url", "image_url": {"url": img_b64}}
                ]
                new_msg = dict(msg)
                new_msg["content"] = new_content
                new_history.append(new_msg)
            else:
                new_history.append(msg)
        return new_history
  4. 修改 _async_chat 方法(大约 622 行附近):

    同样需要弹出 images 参数并注入到消息历史中,然后再调用 self.async_client.chat.completions.create()

        _, kwargs = _apply_model_family_policies(
            self.model_name,
            backend="base",
            request_kwargs=kwargs,
        )
    
        images = kwargs.pop("images", None)
        if images:
            history = self._inject_images_into_history(history, images)
    
        response = await self.async_client.chat.completions.create(
            model=self.model_name, messages=history, gen_conf, kwargs
        )
  5. 重启 RAGFlow 服务,使修改生效。

验证方法

修改完成后,重新通过 MCP(OpenAI 兼容端点)连接 RAGFlow 并使用 VLM 模型发送请求。观察是否不再报 AUTH_ERROR 并正常返回模型回答。

参考来源

infiniflow/ragflow #16333

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 10060

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注