Преглед изворни кода

Handle key upload errors and refine tool flow responses

- Introduce error handling for the keys upload process, logging failures to assist with troubleshooting.
- Improve exception handling in the OpenAI class by returning a more informative response based on the exception arguments if available.
- Replace a return statement in the Newroom tool with an exception raise to standardize tool action termination and provide clearer flow control.

Resolves issue with silent key upload failures. Refines response and control flow for better clarity and debugging.
Kumi пре 1 година
родитељ
комит
670667567e
3 измењених фајлова са 9 додато и 6 уклоњено
  1. 5 2
      src/gptbot/callbacks/roommember.py
  2. 2 2
      src/gptbot/classes/openai.py
  3. 2 2
      src/gptbot/tools/newroom.py

+ 5 - 2
src/gptbot/callbacks/roommember.py

@@ -1,7 +1,10 @@
-from nio import RoomMemberEvent, MatrixRoom
+from nio import RoomMemberEvent, MatrixRoom, KeysUploadError
 
 async def roommember_callback(room: MatrixRoom, event: RoomMemberEvent, bot):
-    await bot.matrix_client.keys_upload()
+    try:
+        await bot.matrix_client.keys_upload()
+    except KeysUploadError as e:
+        bot.logger.log(f"Failed to upload keys: {e.message}")
 
     if event.membership == "leave":
         bot.logger.log(f"User {event.state_key} left room {room.room_id} - am I alone now?")

+ 2 - 2
src/gptbot/classes/openai.py

@@ -294,8 +294,8 @@ class OpenAI:
                             "tool_call_id": tool_call.id,
                             "content": str(tool_response)
                         })
-                except StopProcessing:
-                    return False, 0
+                except StopProcessing as e:
+                    return (e.args[0] if e.args else False), 0
                 except Handover:
                     return await self.generate_chat_response(original_messages, user, room, allow_override=False, use_tools=False)
 

+ 2 - 2
src/gptbot/tools/newroom.py

@@ -1,4 +1,4 @@
-from .base import BaseTool
+from .base import BaseTool, StopProcessing
 
 from nio import RoomCreateError, RoomInviteError
 
@@ -54,4 +54,4 @@ class Newroom(BaseTool):
         await self.bot.matrix_client.room_put_state(
             new_room.room_id, "m.room.power_levels", {"users": {self.user: 100, self.bot.matrix_client.user_id: 100}})
 
-        return "Created new Matrix room with ID " + new_room.room_id + " and invited user."
+        raise StopProcessing("Created new Matrix room with ID " + new_room.room_id + " and invited user.")