Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ import math
|
|
14 |
import langchain_gigachat
|
15 |
import logging
|
16 |
from langchain.schema import SystemMessage
|
|
|
17 |
|
18 |
from langchain_gigachat.chat_models import GigaChat
|
19 |
|
@@ -604,28 +605,39 @@ def generate_personalized_sms_wrapper(selected_product, description, product_nam
|
|
604 |
|
605 |
# Выполняем проверки sms_1
|
606 |
cut_sms_1 = cut_message(sms_1)
|
607 |
-
|
608 |
-
|
609 |
print("[DEBUG B] final check for SMS_1")
|
610 |
print("[DEBUG B] text going into perform_checks:", repr(cut_sms_1))
|
611 |
print("[DEBUG B] key_message:", repr(key_message))
|
|
|
612 |
print("[DEBUG B] exceptions_dict word_repetitions:", exceptions_dict.get("word_repetitions", None))
|
613 |
-
|
|
|
614 |
|
|
|
|
|
615 |
checks_formatted_1 = format_checks(checks_1)
|
616 |
|
|
|
|
|
|
|
617 |
yield(sms_1, "", final_prompt_1, "", checks_formatted_1, "")
|
618 |
|
619 |
sms_2 = generate_sms_with_timer(final_prompt_2, product_name, key_message)
|
620 |
|
621 |
# Выполняем проверки sms_2
|
622 |
cut_sms_2 = cut_message(sms_2)
|
623 |
-
checks_2 = perform_checks(cut_sms_2, key_message, exceptions_dict)
|
624 |
|
625 |
print("[DEBUG B] final check for SMS_2")
|
626 |
print("[DEBUG B] text going into perform_checks:", repr(cut_sms_2))
|
627 |
print("[DEBUG B] key_message:", repr(key_message))
|
|
|
628 |
print("[DEBUG B] exceptions_dict word_repetitions:", exceptions_dict.get("word_repetitions", None))
|
|
|
|
|
|
|
|
|
|
|
629 |
print("[DEBUG B] checks_2 =", checks_2)
|
630 |
|
631 |
checks_formatted_2 = format_checks(checks_2)
|
@@ -1891,6 +1903,10 @@ def attempt_generate_sms_with_checks(model_prompt: str, product_name: str, key_m
|
|
1891 |
sms = generate_message(model_prompt, product_name)
|
1892 |
cut_sms = cut_message(sms)
|
1893 |
|
|
|
|
|
|
|
|
|
1894 |
all_critical_ok, failed_non_crit = run_checks_critical_and_non_critical(cut_sms, key_message)
|
1895 |
|
1896 |
print("[DEBUG A] attempt_generate_sms_with_checks => sms full:", repr(sms))
|
@@ -2007,6 +2023,11 @@ def perform_checks(message, key_message, exceptions_dict=None):
|
|
2007 |
"dates_written_out": safe_check(lambda msg, km: check_no_dates_written_out(msg, exceptions_dict), message),
|
2008 |
"no_word_repetitions": safe_check(lambda msg, km: check_no_word_repetitions(msg, km, exceptions_dict), message, key_message),
|
2009 |
}
|
|
|
|
|
|
|
|
|
|
|
2010 |
return checks
|
2011 |
|
2012 |
def format_checks(checks):
|
|
|
14 |
import langchain_gigachat
|
15 |
import logging
|
16 |
from langchain.schema import SystemMessage
|
17 |
+
import pprint
|
18 |
|
19 |
from langchain_gigachat.chat_models import GigaChat
|
20 |
|
|
|
605 |
|
606 |
# Выполняем проверки sms_1
|
607 |
cut_sms_1 = cut_message(sms_1)
|
608 |
+
|
|
|
609 |
print("[DEBUG B] final check for SMS_1")
|
610 |
print("[DEBUG B] text going into perform_checks:", repr(cut_sms_1))
|
611 |
print("[DEBUG B] key_message:", repr(key_message))
|
612 |
+
print("[DEBUG B] exceptions_dict:", exceptions_dict)
|
613 |
print("[DEBUG B] exceptions_dict word_repetitions:", exceptions_dict.get("word_repetitions", None))
|
614 |
+
|
615 |
+
checks_1 = perform_checks(cut_sms_1, key_message, exceptions_dict)
|
616 |
|
617 |
+
print("[DEBUG B] checks_1 =", checks_1)
|
618 |
+
|
619 |
checks_formatted_1 = format_checks(checks_1)
|
620 |
|
621 |
+
print("[DEBUG B] final checks_1 =>", checks_1)
|
622 |
+
print("[DEBUG B] final checks_formatted_1 =>", checks_formatted_1)
|
623 |
+
|
624 |
yield(sms_1, "", final_prompt_1, "", checks_formatted_1, "")
|
625 |
|
626 |
sms_2 = generate_sms_with_timer(final_prompt_2, product_name, key_message)
|
627 |
|
628 |
# Выполняем проверки sms_2
|
629 |
cut_sms_2 = cut_message(sms_2)
|
|
|
630 |
|
631 |
print("[DEBUG B] final check for SMS_2")
|
632 |
print("[DEBUG B] text going into perform_checks:", repr(cut_sms_2))
|
633 |
print("[DEBUG B] key_message:", repr(key_message))
|
634 |
+
print("[DEBUG B] exceptions_dict:", exceptions_dict)
|
635 |
print("[DEBUG B] exceptions_dict word_repetitions:", exceptions_dict.get("word_repetitions", None))
|
636 |
+
|
637 |
+
pprint.pprint(exceptions_dict, width=120)
|
638 |
+
|
639 |
+
checks_2 = perform_checks(cut_sms_2, key_message, exceptions_dict)
|
640 |
+
|
641 |
print("[DEBUG B] checks_2 =", checks_2)
|
642 |
|
643 |
checks_formatted_2 = format_checks(checks_2)
|
|
|
1903 |
sms = generate_message(model_prompt, product_name)
|
1904 |
cut_sms = cut_message(sms)
|
1905 |
|
1906 |
+
print("[DEBUG CYCLE] about to run checks on iteration / generation")
|
1907 |
+
print("[DEBUG CYCLE] text to check:", repr(cut_sms))
|
1908 |
+
print("[DEBUG CYCLE] key_message:", repr(key_message))
|
1909 |
+
|
1910 |
all_critical_ok, failed_non_crit = run_checks_critical_and_non_critical(cut_sms, key_message)
|
1911 |
|
1912 |
print("[DEBUG A] attempt_generate_sms_with_checks => sms full:", repr(sms))
|
|
|
2023 |
"dates_written_out": safe_check(lambda msg, km: check_no_dates_written_out(msg, exceptions_dict), message),
|
2024 |
"no_word_repetitions": safe_check(lambda msg, km: check_no_word_repetitions(msg, km, exceptions_dict), message, key_message),
|
2025 |
}
|
2026 |
+
|
2027 |
+
print(f"[DEBUG perform_checks] message={repr(message)} key_message={repr(key_message)}\n"
|
2028 |
+
f" => checks={checks}\n"
|
2029 |
+
f" => exceptions_dict={exceptions_dict}")
|
2030 |
+
|
2031 |
return checks
|
2032 |
|
2033 |
def format_checks(checks):
|