|
29 | 29 | from telegram.constants import ChatAction
|
30 | 30 | from telegram.error import TimedOut
|
31 | 31 |
|
| 32 | +# time & date handling |
| 33 | +from timedate_handler import ( |
| 34 | + get_ordinal_suffix, |
| 35 | + get_english_timestamp_str, |
| 36 | + get_finnish_timestamp_str |
| 37 | +) |
| 38 | + |
32 | 39 | # reminder handling
|
33 | 40 | from reminder_handler import handle_add_reminder, handle_delete_reminder, handle_edit_reminder, handle_view_reminders
|
34 | 41 |
|
@@ -259,16 +266,31 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
259 | 266 | # Debug: Print before token limit checks
|
260 | 267 | bot.logger.info(f"[Debug] is_no_limit: {is_no_limit}, user_token_count: {user_token_count}, max_tokens_config: {max_tokens_config}")
|
261 | 268 |
|
262 |
| - # get date & time for timestamps |
| 269 | + # ~~~~~~~~~~~~~~~ |
| 270 | + # Make timestamp |
| 271 | + # ~~~~~~~~~~~~~~~ |
263 | 272 | now_utc = datetime.datetime.utcnow()
|
264 |
| - current_time = now_utc |
265 |
| - # utc_timestamp = now_utc.strftime("%Y-%m-%d %H:%M:%S UTC") |
266 |
| - |
267 |
| - # display abbreviated |
268 |
| - utc_timestamp = now_utc.strftime("%Y-%m-%d %H:%M:%S %a UTC") |
269 | 273 |
|
| 274 | + # We'll keep this for session timeout comparisons |
| 275 | + current_time = now_utc |
270 | 276 | day_of_week = now_utc.strftime("%A")
|
271 |
| - user_message_with_timestamp = f"[{utc_timestamp}] {user_message}" |
| 277 | + system_timestamp = now_utc.strftime("%Y-%m-%d %H:%M:%S UTC") |
| 278 | + |
| 279 | + english_line = get_english_timestamp_str(now_utc) |
| 280 | + finnish_line = get_finnish_timestamp_str(now_utc) |
| 281 | + |
| 282 | + # Combine them however you like, e.g.: |
| 283 | + # |
| 284 | + # Monday, April 9th, 2025 | Time (UTC): 12:34:56 |
| 285 | + # maanantai, 9. huhtikuuta 2025, klo 15:34:56 Suomen aikaa |
| 286 | + # |
| 287 | + current_timestamp_str = f"{english_line}\n{finnish_line}" |
| 288 | + |
| 289 | + # We'll put that into a system message |
| 290 | + timestamp_system_msg = { |
| 291 | + "role": "system", |
| 292 | + "content": current_timestamp_str |
| 293 | + } |
272 | 294 |
|
273 | 295 | # Add the user's tokens to the total usage (JSON style)
|
274 | 296 | bot.total_token_usage += user_token_count
|
@@ -316,12 +338,24 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
316 | 338 | # Initialize chat_history as an empty list if it doesn't exist
|
317 | 339 | chat_history = context.chat_data.get('chat_history', [])
|
318 | 340 |
|
| 341 | + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 342 | + # Insert the new system msg |
| 343 | + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 344 | + # logger info on the appended system message |
| 345 | + logger.info(f"Inserting timestamp system message: {current_timestamp_str}") |
| 346 | + |
| 347 | + chat_history.append(timestamp_system_msg) |
| 348 | + |
319 | 349 | # Append the new user message to the chat history
|
320 |
| - chat_history.append({"role": "user", "content": user_message_with_timestamp}) |
| 350 | + chat_history.append({"role": "user", "content": user_message}) |
321 | 351 |
|
322 | 352 | # Prepare the conversation history to send to the OpenAI API
|
323 |
| - system_timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") |
324 |
| - system_message = {"role": "system", "content": f"System time+date: {system_timestamp}, {day_of_week}): {bot.system_instructions}"} |
| 353 | + |
| 354 | + # # // old method that included the timestamp in the original system message |
| 355 | + # system_timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") |
| 356 | + # system_message = {"role": "system", "content": f"System time+date: {system_timestamp}, {day_of_week}): {bot.system_instructions}"} |
| 357 | + |
| 358 | + system_message = {"role": "system", "content": f"Instructions: {bot.system_instructions}"} |
325 | 359 |
|
326 | 360 | chat_history_with_system_message = [system_message] + chat_history
|
327 | 361 |
|
@@ -1319,12 +1353,6 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
1319 | 1353 | model_info=model_info
|
1320 | 1354 | )
|
1321 | 1355 |
|
1322 |
| - # # Log the bot's response |
1323 |
| - # bot.log_message( |
1324 |
| - # message_type='Bot', |
1325 |
| - # message=bot_reply, |
1326 |
| - # ) |
1327 |
| - |
1328 | 1356 | # # # send the response
|
1329 | 1357 | # # await context.bot.send_message(
|
1330 | 1358 | # # chat_id=chat_id,
|
|
0 commit comments