From 84ac6886664a13bc399cdedaf4076aa4bd598138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20MANSUY?= Date: Thu, 4 Dec 2025 19:14:29 +0800 Subject: [PATCH] cherry-pick 83d99e14 --- lightrag/api/routers/ollama_api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lightrag/api/routers/ollama_api.py b/lightrag/api/routers/ollama_api.py index 52f6f218..ceb068cd 100644 --- a/lightrag/api/routers/ollama_api.py +++ b/lightrag/api/routers/ollama_api.py @@ -505,6 +505,12 @@ class OllamaAPI: if not messages: raise HTTPException(status_code=400, detail="No messages provided") + # Validate that the last message is from a user + if messages[-1].role != "user": + raise HTTPException( + status_code=400, detail="Last message must be from user role" + ) + # Get the last message as query and previous messages as history query = messages[-1].content # Convert OllamaMessage objects to dictionaries