![[Bug]: Error occurs when I connect to RAGFlow through MCP(OpenAI compatible endpoint) with VLM models.](https://www.chat-gpts.plus/wp-content/uploads/2026/06/16333-aa954ba1.jpg)
[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 建议,未经官方合并。请谨慎操作,并在修改前备份原文件。
- 备份原始文件:
cp rag/llm/chat_model.py rag/llm/chat_model.py.bak -
修改
_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) - 在函数体中增加:
-
添加
_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 -
修改
_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 ) - 重启 RAGFlow 服务,使修改生效。
验证方法
修改完成后,重新通过 MCP(OpenAI 兼容端点)连接 RAGFlow 并使用 VLM 模型发送请求。观察是否不再报 AUTH_ERROR 并正常返回模型回答。



