From 77f1569357ede34b3ddf5b1b062ea9a905f3ba8e Mon Sep 17 00:00:00 2001 From: zolezzi1775 Date: Tue, 14 Oct 2025 22:49:45 -0700 Subject: [PATCH 1/2] Check for content in ollama response ollama returns a "content" dict, checking for content dict before falling back to response. --- api/websocket_wiki.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/websocket_wiki.py b/api/websocket_wiki.py index 2a7cce9e3..e9c280211 100644 --- a/api/websocket_wiki.py +++ b/api/websocket_wiki.py @@ -546,8 +546,20 @@ async def handle_websocket_chat(websocket: WebSocket): response = await model.acall(api_kwargs=api_kwargs, model_type=ModelType.LLM) # Handle streaming response from Ollama async for chunk in response: - text = getattr(chunk, 'response', None) or getattr(chunk, 'text', None) or str(chunk) + message = getattr(chunk, 'message', None) + text = None + + if message: + # message might be a Message object or a dict-like object + text = getattr(message, 'content', None) or message.get('content', None) + + # Fallbacks + if not text: + text = getattr(chunk, 'response', None) or getattr(chunk, 'text', None) or str(chunk) + + # Optional: ignore metadata lines starting with model= or created_at= if text and not text.startswith('model=') and not text.startswith('created_at='): + # clean up thinking tags text = text.replace('', '').replace('', '') await websocket.send_text(text) # Explicitly close the WebSocket connection after the response is complete From 7903a476f38b4e876aaec50e0cef4be8ce7ab18e Mon Sep 17 00:00:00 2001 From: zolezzi1775 Date: Wed, 15 Oct 2025 19:58:58 -0700 Subject: [PATCH 2/2] Update api/websocket_wiki.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- api/websocket_wiki.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/websocket_wiki.py b/api/websocket_wiki.py index e9c280211..c102656ed 100644 --- a/api/websocket_wiki.py +++ b/api/websocket_wiki.py @@ -548,13 +548,14 @@ async def handle_websocket_chat(websocket: WebSocket): async for chunk in response: message = getattr(chunk, 'message', None) text = None - if message: # message might be a Message object or a dict-like object - text = getattr(message, 'content', None) or message.get('content', None) - + if hasattr(message, 'get') and callable(message.get): + text = message.get('content') + else: + text = getattr(message, 'content', None) # Fallbacks - if not text: + if text is None: text = getattr(chunk, 'response', None) or getattr(chunk, 'text', None) or str(chunk) # Optional: ignore metadata lines starting with model= or created_at=