fix: add room check to prevent processing errors
Updated the method to include a room parameter, ensuring that message processing functions only when a room is provided. This prevents errors when trying to download and process media files, improving stability and avoiding unnecessary exceptions.
This commit is contained in:
parent
40f28b9f0b
commit
179005a562
1 changed files with 11 additions and 6 deletions
|
@ -19,6 +19,7 @@ from nio import (
|
||||||
RoomMessageFile,
|
RoomMessageFile,
|
||||||
RoomMessageImage,
|
RoomMessageImage,
|
||||||
RoomMessageVideo,
|
RoomMessageVideo,
|
||||||
|
Event,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ..logging import Logger
|
from ..logging import Logger
|
||||||
|
@ -169,7 +170,11 @@ class OpenAI(BaseAI):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def prepare_messages(
|
async def prepare_messages(
|
||||||
self, event, messages: List[Dict[str, str]], system_message=None
|
self,
|
||||||
|
event: Event,
|
||||||
|
messages: List[Dict[str, str]],
|
||||||
|
system_message=None,
|
||||||
|
room=None,
|
||||||
) -> List[Any]:
|
) -> List[Any]:
|
||||||
chat_messages = []
|
chat_messages = []
|
||||||
|
|
||||||
|
@ -201,7 +206,7 @@ class OpenAI(BaseAI):
|
||||||
else "user"
|
else "user"
|
||||||
)
|
)
|
||||||
if message == event or (not message.event_id == event.event_id):
|
if message == event or (not message.event_id == event.event_id):
|
||||||
if self.room_uses_stt(event.room_id):
|
if room and self.room_uses_stt(room):
|
||||||
try:
|
try:
|
||||||
download = await self.bot.download_file(
|
download = await self.bot.download_file(
|
||||||
message.url, raise_error=True
|
message.url, raise_error=True
|
||||||
|
@ -319,9 +324,9 @@ class OpenAI(BaseAI):
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, DownloadException):
|
if room and isinstance(e, DownloadException):
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
event.room_id,
|
room,
|
||||||
f"Could not process image due to download error: {e.args[0]}",
|
f"Could not process image due to download error: {e.args[0]}",
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -379,9 +384,9 @@ class OpenAI(BaseAI):
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, DownloadException):
|
if room and isinstance(e, DownloadException):
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
event.room_id,
|
room,
|
||||||
f"Could not process video due to download error: {e.args[0]}",
|
f"Could not process video due to download error: {e.args[0]}",
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue