diff --git a/discord_connector/open-webui_to_discord.py b/discord_connector/open-webui_to_discord.py index a41b817..240b10b 100644 --- a/discord_connector/open-webui_to_discord.py +++ b/discord_connector/open-webui_to_discord.py @@ -75,7 +75,11 @@ async def _query_openwebui(user_text: str, channel_id: int, tools_list: list): # If the response is OK, parse the JSON and return the content response_data = await resp.json() logging.debug(f"Unparsed response from Open-WebUI: {response_data}") - return response_data['choices'][0]['message']['content'] + content = response_data.get('choices', [{}])[0].get('message', {}).get('content') + if content is None: + logging.warning("Open-WebUI returned None content") + return "No response content received from Open-WebUI" + return content async def _query_openwebui_streaming(user_text: str, channel_id: int, tools_list: list, message_to_edit): """ @@ -132,8 +136,9 @@ async def _query_openwebui_streaming(user_text: str, channel_id: int, tools_list if 'choices' in chunk_data and len(chunk_data['choices']) > 0: delta = chunk_data['choices'][0].get('delta', {}) - if 'content' in delta: - accumulated_content += delta['content'] + content = delta.get('content') + if content is not None: + accumulated_content += content # Edit message periodically to avoid rate limits current_time = asyncio.get_event_loop().time()