fix(chat): add error handling for failed message saving

This commit is contained in:
The0Mikkel 2024-06-27 14:40:18 +02:00
parent bb8db4f3d7
commit e32d5e41e0

8
bot.py
View File

@ -238,8 +238,12 @@ class Bot:
response_message = ''
data = await self.ollama.chat(model=self.model, keep_alive=-1, stream=False, messages=local_messages, options={'num_ctx': self.ctx})
response_message = data['message']['content']
await self.save_message(channel_id, response_message, 'assistant')
try:
response_message = data['message']['content']
await self.save_message(channel_id, response_message, 'assistant')
except Exception as e:
logging.error('Error saving response: %s', e)
return 'I am sorry, I am unable to respond at the moment.'
return response_message
except Exception as e: