fruitpicker01
commited on
Commit
•
3338c48
1
Parent(s):
18c46ef
Update app.py
Browse files
app.py
CHANGED
@@ -693,6 +693,9 @@ def clean_prompt_for_display(prompt, prefixes, suffixes):
|
|
693 |
|
694 |
return cleaned_prompt.strip()
|
695 |
|
|
|
|
|
|
|
696 |
# Функция для постепенной генерации всех сообщений через yield
|
697 |
def generate_all_messages(desc, benefits, key_message, gender, generation, psychotype, business_stage, industry, opf, product_name):
|
698 |
standard_prompt = generate_standard_prompt(desc, benefits, key_message)
|
@@ -777,19 +780,38 @@ def generate_all_messages(desc, benefits, key_message, gender, generation, psych
|
|
777 |
selected_approaches_text_content, standard_prompt_for_display, display_personalization_prompt,
|
778 |
non_personalized_messages, personalized_messages
|
779 |
)
|
780 |
-
|
781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
782 |
personalized_length = len(personalized_message)
|
783 |
personalized_display = f"{personalized_message}\n------\nКоличество знаков: {personalized_length}"
|
784 |
if personalized_messages:
|
785 |
personalized_messages += '\n\n' + personalized_display
|
786 |
else:
|
787 |
personalized_messages = personalized_display
|
|
|
788 |
yield (
|
789 |
selected_approaches_text_content, standard_prompt_for_display, display_personalization_prompt,
|
790 |
non_personalized_messages, personalized_messages
|
791 |
)
|
792 |
time.sleep(1)
|
|
|
793 |
save_statistics_to_github(approach_stats)
|
794 |
|
795 |
def rank_messages(non_personalized_messages, personalized_messages):
|
|
|
693 |
|
694 |
return cleaned_prompt.strip()
|
695 |
|
696 |
+
def are_messages_equal(message1, message2):
|
697 |
+
return message1.strip().lower() == message2.strip().lower()
|
698 |
+
|
699 |
# Функция для постепенной генерации всех сообщений через yield
|
700 |
def generate_all_messages(desc, benefits, key_message, gender, generation, psychotype, business_stage, industry, opf, product_name):
|
701 |
standard_prompt = generate_standard_prompt(desc, benefits, key_message)
|
|
|
780 |
selected_approaches_text_content, standard_prompt_for_display, display_personalization_prompt,
|
781 |
non_personalized_messages, personalized_messages
|
782 |
)
|
783 |
+
|
784 |
+
# **Добавляем перегенерацию персонализированного сообщения**
|
785 |
+
personalized_message = None
|
786 |
+
for attempt in range(5): # Максимум 5 попыток
|
787 |
+
personalized_message_candidate = generate_message_mistral_with_retry(
|
788 |
+
f"{personalization_prompt}\n\nТекст для адаптации: {non_personalized_message}",
|
789 |
+
approach_name, desc, key_message, product_name, benefits
|
790 |
+
)
|
791 |
+
if not are_messages_equal(personalized_message_candidate, non_personalized_message):
|
792 |
+
personalized_message = personalized_message_candidate
|
793 |
+
break # Уникальное сообщение найдено
|
794 |
+
else:
|
795 |
+
print(f"Попытка {attempt + 1}: Персонализированное сообщение совпадает со стандартным. Повторная генерация...")
|
796 |
+
time.sleep(1) # Небольшая пауза перед следующей попыткой
|
797 |
+
else:
|
798 |
+
# После 5 попыток использовать последнее сгенерированное сообщение
|
799 |
+
personalized_message = personalized_message_candidate
|
800 |
+
print("Не удалось сгенерировать уникальное персонализированное сообщение после 5 попыток. Используется последнее сообщение.")
|
801 |
+
|
802 |
personalized_length = len(personalized_message)
|
803 |
personalized_display = f"{personalized_message}\n------\nКоличество знаков: {personalized_length}"
|
804 |
if personalized_messages:
|
805 |
personalized_messages += '\n\n' + personalized_display
|
806 |
else:
|
807 |
personalized_messages = personalized_display
|
808 |
+
|
809 |
yield (
|
810 |
selected_approaches_text_content, standard_prompt_for_display, display_personalization_prompt,
|
811 |
non_personalized_messages, personalized_messages
|
812 |
)
|
813 |
time.sleep(1)
|
814 |
+
|
815 |
save_statistics_to_github(approach_stats)
|
816 |
|
817 |
def rank_messages(non_personalized_messages, personalized_messages):
|