Improve error handling for Open-WebUI responses in query functions

This commit is contained in:
2026-03-10 21:01:42 +01:00
parent 74bdfd5f69
commit 16f5ddcdce

View File

@@ -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()