Improve error handling for Open-WebUI responses in query functions
This commit is contained in:
@@ -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
|
# If the response is OK, parse the JSON and return the content
|
||||||
response_data = await resp.json()
|
response_data = await resp.json()
|
||||||
logging.debug(f"Unparsed response from Open-WebUI: {response_data}")
|
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):
|
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:
|
if 'choices' in chunk_data and len(chunk_data['choices']) > 0:
|
||||||
delta = chunk_data['choices'][0].get('delta', {})
|
delta = chunk_data['choices'][0].get('delta', {})
|
||||||
if 'content' in delta:
|
content = delta.get('content')
|
||||||
accumulated_content += delta['content']
|
if content is not None:
|
||||||
|
accumulated_content += content
|
||||||
|
|
||||||
# Edit message periodically to avoid rate limits
|
# Edit message periodically to avoid rate limits
|
||||||
current_time = asyncio.get_event_loop().time()
|
current_time = asyncio.get_event_loop().time()
|
||||||
|
|||||||
Reference in New Issue
Block a user