bibibi12345 commited on
Commit
35867dc
·
verified ·
1 Parent(s): 3f1c280

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +27 -27
app/main.py CHANGED
@@ -579,29 +579,29 @@ Ready for your request."""
579
  )
580
  ]
581
 
582
- # --- Find the index of the single assistant message to encrypt ---
583
- target_assistant_index = -1
584
- num_messages = len(messages)
585
- for i in range(num_messages - 1, -1, -1): # Iterate backwards
586
- if messages[i].role == 'assistant':
587
- # Condition 1: Is assistant message - met.
588
- # Condition 2: Not the last message overall?
589
- is_last_overall = (i == num_messages - 1)
590
- if is_last_overall:
591
- continue # Cannot be the target if it's the last message
592
-
593
- # Condition 3: Has a user/system message after it?
594
- has_user_system_after = False
595
- for k in range(i + 1, num_messages):
596
- if messages[k].role in ['user', 'system']:
597
- has_user_system_after = True
598
- break
599
 
600
- if has_user_system_after:
601
- # This is the last assistant message meeting all criteria
602
- target_assistant_index = i
603
- print(f"DEBUG: Identified target assistant message for encoding at index {target_assistant_index}")
604
- break # Found the target, stop searching
605
 
606
  # --- Create the new message list with specific encoding ---
607
  new_messages = []
@@ -618,13 +618,13 @@ Ready for your request."""
618
 
619
  if message.role == "user":
620
  encode_this_message = True
621
- print(f"DEBUG: Encoding user message (index {i})")
622
- elif message.role == "assistant" and i == target_assistant_index:
623
- encode_this_message = True
624
- print(f"DEBUG: Encoding target assistant message (index {i})")
625
  else:
626
  # Keep system, other assistant, tool messages as is
627
- print(f"DEBUG: Passing through message (index {i}, role {message.role}) without encoding")
628
  new_messages.append(message)
629
  continue # Skip encoding logic below for this message
630
 
 
579
  )
580
  ]
581
 
582
+ # # --- Find the index of the single assistant message to encrypt ---
583
+ # target_assistant_index = -1
584
+ # num_messages = len(messages)
585
+ # for i in range(num_messages - 1, -1, -1): # Iterate backwards
586
+ # if messages[i].role == 'assistant':
587
+ # # Condition 1: Is assistant message - met.
588
+ # # Condition 2: Not the last message overall?
589
+ # is_last_overall = (i == num_messages - 1)
590
+ # if is_last_overall:
591
+ # continue # Cannot be the target if it's the last message
592
+
593
+ # # Condition 3: Has a user/system message after it?
594
+ # has_user_system_after = False
595
+ # for k in range(i + 1, num_messages):
596
+ # if messages[k].role in ['user', 'system']:
597
+ # has_user_system_after = True
598
+ # break
599
 
600
+ # if has_user_system_after:
601
+ # # This is the last assistant message meeting all criteria
602
+ # target_assistant_index = i
603
+ # print(f"DEBUG: Identified target assistant message for encoding at index {target_assistant_index}")
604
+ # break # Found the target, stop searching
605
 
606
  # --- Create the new message list with specific encoding ---
607
  new_messages = []
 
618
 
619
  if message.role == "user":
620
  encode_this_message = True
621
+ # print(f"DEBUG: Encoding user message (index {i})")
622
+ # elif message.role == "assistant" and i == target_assistant_index:
623
+ # encode_this_message = True
624
+ # print(f"DEBUG: Encoding target assistant message (index {i})")
625
  else:
626
  # Keep system, other assistant, tool messages as is
627
+ # print(f"DEBUG: Passing through message (index {i}, role {message.role}) without encoding")
628
  new_messages.append(message)
629
  continue # Skip encoding logic below for this message
630