diff --git a/navi/llm/ollama.py b/navi/llm/ollama.py index 5f805df..d164fe1 100644 --- a/navi/llm/ollama.py +++ b/navi/llm/ollama.py @@ -11,12 +11,28 @@ from .base import LLMBackend, LLMChunk, LLMResponse, Message, ToolCallRequest, ToolSchema +def _clean_base64_image(img: str) -> str | None: + """Strip data URI prefix and validate that result is non-empty base64.""" + if not img: + return None + s = img.strip() + if s.startswith("data:"): + if "," in s: + s = s.split(",", 1)[1] + else: + return None + return s if s else None + + def _to_ollama_messages(messages: list[Message]) -> list[dict]: result = [] for m in messages: msg: dict = {"role": m.role, "content": m.content or ""} if m.images: - msg["images"] = m.images # list of base64 strings, Ollama format + cleaned = [_clean_base64_image(img) for img in m.images] + cleaned = [img for img in cleaned if img is not None] + if cleaned: + msg["images"] = cleaned if m.tool_calls: msg["tool_calls"] = [ {"function": {"name": tc.name, "arguments": tc.arguments}}