TeLLMgramBot 3.2.0__tar.gz → 3.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/PKG-INFO +1 -1
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/TeLLMgramBot.py +7 -4
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/conversation.py +33 -3
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot.egg-info/PKG-INFO +1 -1
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/setup.py +1 -1
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/LICENSE +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/README.md +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/__init__.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/database.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/initialize.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/message_handlers.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/models.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/providers/__init__.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/providers/anthropic_provider.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/providers/base.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/providers/factory.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/providers/openai_provider.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/utils.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot/web_utils.py +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot.egg-info/SOURCES.txt +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot.egg-info/dependency_links.txt +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot.egg-info/requires.txt +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/TeLLMgramBot.egg-info/top_level.txt +0 -0
- {tellmgrambot-3.2.0 → tellmgrambot-3.2.1}/setup.cfg +0 -0
|
@@ -135,8 +135,8 @@ class TelegramBot:
|
|
|
135
135
|
users keep sensitive private exchanges out of shared group contexts.
|
|
136
136
|
|
|
137
137
|
Usage:
|
|
138
|
-
/private —
|
|
139
|
-
/private off —
|
|
138
|
+
/private — enables private mode (idempotent if already on)
|
|
139
|
+
/private off — disables private mode and purges in-session private messages
|
|
140
140
|
|
|
141
141
|
Only available in private chats; sending the command in a group returns an error.
|
|
142
142
|
"""
|
|
@@ -150,10 +150,10 @@ class TelegramBot:
|
|
|
150
150
|
return
|
|
151
151
|
|
|
152
152
|
user_id = user.id
|
|
153
|
+
chat_id = chat.id
|
|
153
154
|
args = (msg.text or "").strip().split()
|
|
154
155
|
force_off = len(args) > 1 and args[1].lower() == 'off'
|
|
155
|
-
|
|
156
|
-
new_state = False if (force_off or current) else True
|
|
156
|
+
new_state = False if force_off else True
|
|
157
157
|
await set_private_mode(user_id, new_state)
|
|
158
158
|
|
|
159
159
|
if new_state:
|
|
@@ -162,6 +162,9 @@ class TelegramBot:
|
|
|
162
162
|
"from group conversation contexts. Use /private off to disable."
|
|
163
163
|
)
|
|
164
164
|
else:
|
|
165
|
+
# Purge in-session private messages so the bot cannot reference them after the toggle.
|
|
166
|
+
if chat_id in self.conversations:
|
|
167
|
+
self.conversations[chat_id].purge_private_messages()
|
|
165
168
|
await msg.reply_text(
|
|
166
169
|
"Private mode is OFF. Future messages in this private chat will be included in group conversation contexts."
|
|
167
170
|
)
|
|
@@ -63,6 +63,11 @@ class Conversation:
|
|
|
63
63
|
# before live messages) rather than at index 1 (before all existing history).
|
|
64
64
|
self._history_end: dict[int, int] = {}
|
|
65
65
|
|
|
66
|
+
# Set of id()s for message dicts added while private mode was ON.
|
|
67
|
+
# Used by purge_private_messages() to remove them from self.messages without
|
|
68
|
+
# touching the database. Cleared on purge or clear_interaction().
|
|
69
|
+
self._private_message_ids: set[int] = set()
|
|
70
|
+
|
|
66
71
|
def set_system_content(self, new_content: str):
|
|
67
72
|
"""
|
|
68
73
|
Replace the system content (bot's personality prompt) in the conversation.
|
|
@@ -85,7 +90,10 @@ class Conversation:
|
|
|
85
90
|
username: Telegram username (display only, may be None).
|
|
86
91
|
is_private: If True, excludes this message from group context loading (used for /forget or private commands).
|
|
87
92
|
"""
|
|
88
|
-
|
|
93
|
+
msg_dict = {"role": "user", "content": content}
|
|
94
|
+
self.messages.append(msg_dict)
|
|
95
|
+
if is_private:
|
|
96
|
+
self._private_message_ids.add(id(msg_dict))
|
|
89
97
|
await insert_message(self.chat_id, user_id, username, "user", content, is_private)
|
|
90
98
|
|
|
91
99
|
async def add_assistant_message(self, content: str, bot_user_id: int, bot_username: str | None, is_private: bool = False):
|
|
@@ -100,7 +108,10 @@ class Conversation:
|
|
|
100
108
|
the is_private flag of the user message it responds to, so that both
|
|
101
109
|
sides of a private-mode exchange are excluded from shared contexts.
|
|
102
110
|
"""
|
|
103
|
-
|
|
111
|
+
msg_dict = {"role": "assistant", "content": content}
|
|
112
|
+
self.messages.append(msg_dict)
|
|
113
|
+
if is_private:
|
|
114
|
+
self._private_message_ids.add(id(msg_dict))
|
|
104
115
|
await insert_message(self.chat_id, bot_user_id, bot_username, "assistant", content, is_private)
|
|
105
116
|
|
|
106
117
|
async def get_message_token_count(self) -> int:
|
|
@@ -138,6 +149,23 @@ class Conversation:
|
|
|
138
149
|
except Exception as e:
|
|
139
150
|
log_error(e, f"{type(e).__name__} pruning under {token_limit} tokens for {self.chat_print}", self.error_log)
|
|
140
151
|
|
|
152
|
+
def purge_private_messages(self):
|
|
153
|
+
"""
|
|
154
|
+
Remove all in-session private-mode messages from the in-memory conversation.
|
|
155
|
+
|
|
156
|
+
Strips any messages added while private mode was ON from self.messages without
|
|
157
|
+
modifying the database. Called when a user disables private mode (/private off)
|
|
158
|
+
so the bot can no longer reference messages sent during the private session.
|
|
159
|
+
|
|
160
|
+
Side Effects:
|
|
161
|
+
- Modifies self.messages in-place, removing tracked private message dicts.
|
|
162
|
+
- Clears self._private_message_ids.
|
|
163
|
+
"""
|
|
164
|
+
if not self._private_message_ids:
|
|
165
|
+
return
|
|
166
|
+
self.messages = [m for m in self.messages if id(m) not in self._private_message_ids]
|
|
167
|
+
self._private_message_ids.clear()
|
|
168
|
+
|
|
141
169
|
async def get_past_interaction(self, token_limit: int, user_id: int, bot_id: int | None = None) -> bool:
|
|
142
170
|
"""
|
|
143
171
|
Load past conversation messages from the database up to a token limit.
|
|
@@ -231,7 +259,7 @@ class Conversation:
|
|
|
231
259
|
label = "Full" if not token_limit_reached and not group_limit_reached else "Partial"
|
|
232
260
|
group_note = f", plus {group_rows_inserted} group message(s)" if group_rows_inserted > 0 else ""
|
|
233
261
|
print(
|
|
234
|
-
f"{label} context loaded for User {user_id} in {self.chat_print}
|
|
262
|
+
f"{label} context loaded for User {user_id} in {self.chat_print} - "
|
|
235
263
|
f"storing {token_count} token(s){group_note}"
|
|
236
264
|
)
|
|
237
265
|
else:
|
|
@@ -314,11 +342,13 @@ class Conversation:
|
|
|
314
342
|
- Clears self.messages to contain only the system message (index 0).
|
|
315
343
|
- Resets self._context_cursor to empty dict.
|
|
316
344
|
- Resets self._history_end to empty dict.
|
|
345
|
+
- Resets self._private_message_ids to empty set.
|
|
317
346
|
- Deletes all messages for this chat (private) or this user (group) from database.
|
|
318
347
|
"""
|
|
319
348
|
self.messages = [self.messages[0]]
|
|
320
349
|
self._context_cursor = {}
|
|
321
350
|
self._history_end = {}
|
|
351
|
+
self._private_message_ids = set()
|
|
322
352
|
if self.chat_type == 'private':
|
|
323
353
|
await delete_messages_for_chat(self.chat_id)
|
|
324
354
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|