smart-bot-factory 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl
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.
Potentially problematic release.
This version of smart-bot-factory might be problematic. Click here for more details.
- smart_bot_factory/creation/bot_builder.py +24 -0
- smart_bot_factory/handlers/handlers.py +14 -1
- smart_bot_factory/supabase/client.py +3 -12
- {smart_bot_factory-0.2.4.dist-info → smart_bot_factory-0.2.5.dist-info}/METADATA +1 -1
- {smart_bot_factory-0.2.4.dist-info → smart_bot_factory-0.2.5.dist-info}/RECORD +8 -8
- {smart_bot_factory-0.2.4.dist-info → smart_bot_factory-0.2.5.dist-info}/WHEEL +0 -0
- {smart_bot_factory-0.2.4.dist-info → smart_bot_factory-0.2.5.dist-info}/entry_points.txt +0 -0
- {smart_bot_factory-0.2.4.dist-info → smart_bot_factory-0.2.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -52,6 +52,7 @@ class BotBuilder:
|
|
|
52
52
|
self._message_validators: List = [] # Валидация ДО обработки
|
|
53
53
|
self._prompt_enrichers: List = [] # Обогащение системного промпта
|
|
54
54
|
self._context_enrichers: List = [] # Обогащение контекста для AI
|
|
55
|
+
self._response_processors: List = [] # Обработка ответа AI
|
|
55
56
|
self._send_filters: List = [] # Фильтры перед отправкой пользователю
|
|
56
57
|
|
|
57
58
|
# Флаги инициализации
|
|
@@ -437,6 +438,28 @@ class BotBuilder:
|
|
|
437
438
|
logger.info(f"✅ Зарегистрирован обогатитель контекста: {handler.__name__}")
|
|
438
439
|
return handler
|
|
439
440
|
|
|
441
|
+
def process_response(self, handler):
|
|
442
|
+
"""
|
|
443
|
+
Регистрирует обработчик ответа AI (ПОСЛЕ получения ответа)
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
handler: async def(response_text: str, ai_metadata: dict, user_id: int) -> tuple[str, dict]
|
|
447
|
+
|
|
448
|
+
Example:
|
|
449
|
+
@bot_builder.process_response
|
|
450
|
+
async def modify_response(response_text, ai_metadata, user_id):
|
|
451
|
+
# Модифицируем ответ
|
|
452
|
+
if "цена" in response_text.lower():
|
|
453
|
+
response_text += "\\n\\n💰 Актуальные цены на сайте"
|
|
454
|
+
return response_text, ai_metadata
|
|
455
|
+
"""
|
|
456
|
+
if not callable(handler):
|
|
457
|
+
raise TypeError(f"Обработчик должен быть callable, получен {type(handler)}")
|
|
458
|
+
|
|
459
|
+
self._response_processors.append(handler)
|
|
460
|
+
logger.info(f"✅ Зарегистрирован обработчик ответа: {handler.__name__}")
|
|
461
|
+
return handler
|
|
462
|
+
|
|
440
463
|
def filter_send(self, handler):
|
|
441
464
|
"""
|
|
442
465
|
Регистрирует фильтр отправки (может блокировать отправку пользователю)
|
|
@@ -466,6 +489,7 @@ class BotBuilder:
|
|
|
466
489
|
'validators': self._message_validators.copy(),
|
|
467
490
|
'prompt_enrichers': self._prompt_enrichers.copy(),
|
|
468
491
|
'context_enrichers': self._context_enrichers.copy(),
|
|
492
|
+
'response_processors': self._response_processors.copy(),
|
|
469
493
|
'send_filters': self._send_filters.copy()
|
|
470
494
|
}
|
|
471
495
|
|
|
@@ -624,6 +624,19 @@ async def process_user_message(message: Message, state: FSMContext, session_id:
|
|
|
624
624
|
|
|
625
625
|
logger.info(f"✅ Финальный текст для отправки: {len(response_text)} символов")
|
|
626
626
|
|
|
627
|
+
# ============ ХУК 4: ОБРАБОТКА ОТВЕТА ============
|
|
628
|
+
response_processors = message_hooks.get('response_processors', [])
|
|
629
|
+
for processor in response_processors:
|
|
630
|
+
try:
|
|
631
|
+
response_text, ai_metadata = await processor(
|
|
632
|
+
response_text,
|
|
633
|
+
ai_metadata,
|
|
634
|
+
message.from_user.id
|
|
635
|
+
)
|
|
636
|
+
logger.info(f"✅ Ответ обработан '{processor.__name__}'")
|
|
637
|
+
except Exception as e:
|
|
638
|
+
logger.error(f"❌ Ошибка в обработчике ответа '{processor.__name__}': {e}")
|
|
639
|
+
|
|
627
640
|
# Обновляем этап сессии и качество лида
|
|
628
641
|
if ai_metadata:
|
|
629
642
|
logger.info("🔍 Анализ метаданных от ИИ:")
|
|
@@ -732,7 +745,7 @@ async def process_user_message(message: Message, state: FSMContext, session_id:
|
|
|
732
745
|
|
|
733
746
|
logger.info(f"📱 Отправляем пользователю: {len(final_response)} символов")
|
|
734
747
|
|
|
735
|
-
# ============ ХУК
|
|
748
|
+
# ============ ХУК 5: ФИЛЬТРЫ ОТПРАВКИ ============
|
|
736
749
|
send_filters = message_hooks.get('send_filters', [])
|
|
737
750
|
for filter_func in send_filters:
|
|
738
751
|
try:
|
|
@@ -32,10 +32,10 @@ class SupabaseClient:
|
|
|
32
32
|
# Автоматически загружаем настройки из .env
|
|
33
33
|
self._load_env_config()
|
|
34
34
|
|
|
35
|
-
# Инициализируем клиент
|
|
36
|
-
self.client
|
|
35
|
+
# Инициализируем клиент СИНХРОННО прямо в __init__
|
|
36
|
+
self.client = create_client(self.url, self.key)
|
|
37
37
|
|
|
38
|
-
logger.info(f"
|
|
38
|
+
logger.info(f"✅ SupabaseClient инициализирован для bot_id: {self.bot_id}")
|
|
39
39
|
|
|
40
40
|
def _load_env_config(self):
|
|
41
41
|
"""Загружает конфигурацию из .env файла"""
|
|
@@ -80,15 +80,6 @@ class SupabaseClient:
|
|
|
80
80
|
logger.error(f" Искали в: {bot_env_path}")
|
|
81
81
|
return None
|
|
82
82
|
|
|
83
|
-
async def initialize(self):
|
|
84
|
-
"""Инициализация клиента Supabase"""
|
|
85
|
-
try:
|
|
86
|
-
self.client = create_client(self.url, self.key)
|
|
87
|
-
logger.info(f"✅ Supabase client инициализирован{f' для bot_id: {self.bot_id}' if self.bot_id else ''}")
|
|
88
|
-
except Exception as e:
|
|
89
|
-
logger.error(f"❌ Ошибка инициализации Supabase client: {e}")
|
|
90
|
-
raise
|
|
91
|
-
|
|
92
83
|
# =============================================================================
|
|
93
84
|
# МЕТОДЫ ДЛЯ РАБОТЫ С ПОЛЬЗОВАТЕЛЯМИ
|
|
94
85
|
# =============================================================================
|
|
@@ -33,23 +33,23 @@ smart_bot_factory/core/router_manager.py,sha256=dUwesog-oHk1U2EDdS8p0e4MTSkwtx5_
|
|
|
33
33
|
smart_bot_factory/core/states.py,sha256=AOc19_yAsDW_8md-2oiowjBhuW3bwcsmMxszCXWZZTQ,355
|
|
34
34
|
smart_bot_factory/core/telegram_router.py,sha256=LcPLOd87Y4Y4YN6TBXVAtmpSp8gAK2otgMI4YS5f5tk,2091
|
|
35
35
|
smart_bot_factory/creation/__init__.py,sha256=IgDk8GDS3pg7Pw_Et41J33ZmeZIU5dRwQdTmYKXfJfE,128
|
|
36
|
-
smart_bot_factory/creation/bot_builder.py,sha256=
|
|
36
|
+
smart_bot_factory/creation/bot_builder.py,sha256=VjRPlar6xgul7QpG57od--uS-juWrlW9-YYNnFN_Yx4,33828
|
|
37
37
|
smart_bot_factory/creation/bot_testing.py,sha256=JDWXyJfZmbgo-DLdAPk8Sd9FiehtHHa4sLD17lBrTOc,55669
|
|
38
38
|
smart_bot_factory/event/__init__.py,sha256=hPL449RULIOB-OXv1ZbGNiHctAYaOMUqhSWGPrDHYBM,212
|
|
39
|
-
smart_bot_factory/handlers/handlers.py,sha256=
|
|
39
|
+
smart_bot_factory/handlers/handlers.py,sha256=jtCf8XiJD3pIjcd7vqT8uG8Q-qiHd1W-ZLZiVPK8YR4,41458
|
|
40
40
|
smart_bot_factory/integrations/openai_client.py,sha256=aMcDrKO0GEx3ZSVEOGDeDtFCDWSXs6biUfgrbRK8yTU,23180
|
|
41
41
|
smart_bot_factory/integrations/supabase_client.py,sha256=AfALLZdDYeMWHLJw6POTGiBd-sH3i03oT6tT7m9C28I,44644
|
|
42
42
|
smart_bot_factory/message/__init__.py,sha256=8XWEEl3J0l1xDeEPmXPwFbHbnQelGApCwnicUkcBbOg,391
|
|
43
43
|
smart_bot_factory/router/__init__.py,sha256=QrfO5u8H2uVzWGMtBvNKunsJAv7UrKtvt2f_D5xSFWE,270
|
|
44
44
|
smart_bot_factory/supabase/__init__.py,sha256=XmZP6yM9ffERM5ddAWyJnrNzEhCYtMu3AcjVCi1rOf8,179
|
|
45
|
-
smart_bot_factory/supabase/client.py,sha256=
|
|
45
|
+
smart_bot_factory/supabase/client.py,sha256=lWIzfOgoSvU7xPhYLoJtM5GnbWdoWsvHcRFC22sFBMU,25637
|
|
46
46
|
smart_bot_factory/table/database_structure.sql,sha256=26gFtMC2jdQGQF7Zb_F4Br56rMd4hUDTk9FkNZYneLo,2789
|
|
47
47
|
smart_bot_factory/table/schema.sql,sha256=-6kOmA9QnSkUtmGI2iQRbTvbdiqOhEOQcuz1lJn79mU,28059
|
|
48
48
|
smart_bot_factory/utils/__init__.py,sha256=5zNjw491bj5VkOhoEAwh2hjmv8nldyDOTrG7pbGpz6A,285
|
|
49
49
|
smart_bot_factory/utils/debug_routing.py,sha256=BOoDhKBg7UXe5uHQxRk3TSfPfLPOFqt0N7lAo6kjCOo,4719
|
|
50
50
|
smart_bot_factory/utils/prompt_loader.py,sha256=JSn7CsWnToSbHYtURdeuZn7ectyDqQGrPGHN2ixIGkw,19930
|
|
51
|
-
smart_bot_factory-0.2.
|
|
52
|
-
smart_bot_factory-0.2.
|
|
53
|
-
smart_bot_factory-0.2.
|
|
54
|
-
smart_bot_factory-0.2.
|
|
55
|
-
smart_bot_factory-0.2.
|
|
51
|
+
smart_bot_factory-0.2.5.dist-info/METADATA,sha256=ysK6yC4uZMOeB0p9YOAJRcyiBhOGhG82KnolWrv2QNc,28224
|
|
52
|
+
smart_bot_factory-0.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
53
|
+
smart_bot_factory-0.2.5.dist-info/entry_points.txt,sha256=ybKEAI0WSb7WoRiey7QE-HHfn88UGV7nxLDxXq7b7SU,50
|
|
54
|
+
smart_bot_factory-0.2.5.dist-info/licenses/LICENSE,sha256=OrK3cwdUTzNzIhJvSPtJaVMoYIyC_sSx5EFE_FDMvGs,1092
|
|
55
|
+
smart_bot_factory-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|