From 99d3974e171e1c86085fc836f9c6e9edd324e1f5 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 18 Aug 2024 10:44:09 +0200 Subject: [PATCH] feat: update bot info and deprecate stats command Updated bot info command to display model info specific to room. Removed the now unsupported stats command from help and privacy. Retired the 'stats' command, informing users of its deprecation. Updated version to 0.3.18 to reflect these changes. --- pyproject.toml | 2 +- src/gptbot/commands/botinfo.py | 17 ++++++----------- src/gptbot/commands/help.py | 1 - src/gptbot/commands/privacy.py | 4 ++-- src/gptbot/commands/stats.py | 22 ++++++++++++++++++---- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3a61cdb..0166e99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "matrix-gptbot" -version = "0.3.17" +version = "0.3.18" authors = [ { name = "Kumi", email = "gptbot@kumi.email" }, diff --git a/src/gptbot/commands/botinfo.py b/src/gptbot/commands/botinfo.py index b306162..bde733e 100644 --- a/src/gptbot/commands/botinfo.py +++ b/src/gptbot/commands/botinfo.py @@ -5,19 +5,14 @@ from nio.rooms import MatrixRoom async def command_botinfo(room: MatrixRoom, event: RoomMessageText, bot): bot.logger.log("Showing bot info...") - body = f"""GPT Info: + body = f"""GPT Room info: -Model: {bot.model} -Maximum context tokens: {bot.max_tokens} -Maximum context messages: {bot.max_messages} - -Room info: - -Bot user ID: {bot.matrix_client.user_id} -Current room ID: {room.room_id} +Model: {await bot.get_room_model(room)}\n +Maximum context tokens: {bot.chat_api.max_tokens}\n +Maximum context messages: {bot.chat_api.max_messages}\n +Bot user ID: {bot.matrix_client.user_id}\n +Current room ID: {room.room_id}\n System message: {bot.get_system_message(room)} - -For usage statistics, run !gptbot stats """ await bot.send_message(room, body, True) diff --git a/src/gptbot/commands/help.py b/src/gptbot/commands/help.py index 5a6e175..a4cf8ef 100644 --- a/src/gptbot/commands/help.py +++ b/src/gptbot/commands/help.py @@ -9,7 +9,6 @@ async def command_help(room: MatrixRoom, event: RoomMessageText, bot): - !gptbot botinfo - Show information about the bot - !gptbot privacy - Show privacy information - !gptbot newroom - Create a new room and invite yourself to it -- !gptbot stats - Show usage statistics for this room - !gptbot systemmessage - Get or set the system message for this room - !gptbot space [enable|disable|update|invite] - Enable, disable, force update, or invite yourself to your space - !gptbot coin - Flip a coin (heads or tails) diff --git a/src/gptbot/commands/privacy.py b/src/gptbot/commands/privacy.py index 7b0b0dd..773f525 100644 --- a/src/gptbot/commands/privacy.py +++ b/src/gptbot/commands/privacy.py @@ -11,7 +11,7 @@ async def command_privacy(room: MatrixRoom, event: RoomMessageText, bot): body += "- For chat requests: " + f"{bot.chat_api.operator}" + "\n" if bot.image_api: body += "- For image generation requests (!gptbot imagine): " + f"{bot.image_api.operator}" + "\n" - if bot.calculate_api: - body += "- For calculation requests (!gptbot calculate): " + f"{bot.calculate_api.operator}" + "\n" + if bot.calculation_api: + body += "- For calculation requests (!gptbot calculate): " + f"{bot.calculation_api.operator}" + "\n" await bot.send_message(room, body, True) \ No newline at end of file diff --git a/src/gptbot/commands/stats.py b/src/gptbot/commands/stats.py index 4022dc3..f9d81db 100644 --- a/src/gptbot/commands/stats.py +++ b/src/gptbot/commands/stats.py @@ -5,16 +5,30 @@ from contextlib import closing async def command_stats(room: MatrixRoom, event: RoomMessageText, bot): + await bot.send_message( + room, + "The `stats` command is no longer supported. Sorry for the inconvenience.", + True, + ) + return + + # Yes, the code below is unreachable, but it's kept here for reference. + bot.logger.log("Showing stats...") if not bot.database: bot.logger.log("No database connection - cannot show stats") - bot.send_message(room, "Sorry, I'm not connected to a database, so I don't have any statistics on your usage.", True) - return + await bot.send_message( + room, + "Sorry, I'm not connected to a database, so I don't have any statistics on your usage.", + True, + ) + return with closing(bot.database.cursor()) as cursor: cursor.execute( - "SELECT SUM(tokens) FROM token_usage WHERE room_id = ?", (room.room_id,)) + "SELECT SUM(tokens) FROM token_usage WHERE room_id = ?", (room.room_id,) + ) total_tokens = cursor.fetchone()[0] or 0 - bot.send_message(room, f"Total tokens used: {total_tokens}", True) + await bot.send_message(room, f"Total tokens used: {total_tokens}", True)