smart-bot-factory 0.2.5__py3-none-any.whl → 0.2.7__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 +41 -4
- smart_bot_factory/handlers/handlers.py +4 -1
- smart_bot_factory/utils/__init__.py +5 -4
- smart_bot_factory/utils/user_prompt_loader.py +56 -0
- {smart_bot_factory-0.2.5.dist-info → smart_bot_factory-0.2.7.dist-info}/METADATA +1 -1
- {smart_bot_factory-0.2.5.dist-info → smart_bot_factory-0.2.7.dist-info}/RECORD +9 -8
- {smart_bot_factory-0.2.5.dist-info → smart_bot_factory-0.2.7.dist-info}/WHEEL +0 -0
- {smart_bot_factory-0.2.5.dist-info → smart_bot_factory-0.2.7.dist-info}/entry_points.txt +0 -0
- {smart_bot_factory-0.2.5.dist-info → smart_bot_factory-0.2.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -55,6 +55,9 @@ class BotBuilder:
|
|
|
55
55
|
self._response_processors: List = [] # Обработка ответа AI
|
|
56
56
|
self._send_filters: List = [] # Фильтры перед отправкой пользователю
|
|
57
57
|
|
|
58
|
+
# Кастомный PromptLoader
|
|
59
|
+
self._custom_prompt_loader = None
|
|
60
|
+
|
|
58
61
|
# Флаги инициализации
|
|
59
62
|
self._initialized = False
|
|
60
63
|
|
|
@@ -175,10 +178,16 @@ class BotBuilder:
|
|
|
175
178
|
else:
|
|
176
179
|
logger.info(f"✅ Router Manager уже был создан ранее")
|
|
177
180
|
|
|
178
|
-
# Prompt Loader
|
|
179
|
-
self.
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
# Prompt Loader (используем кастомный если установлен)
|
|
182
|
+
if self._custom_prompt_loader:
|
|
183
|
+
self.prompt_loader = self._custom_prompt_loader
|
|
184
|
+
logger.info(f"✅ Используется кастомный Prompt Loader: {type(self.prompt_loader).__name__}")
|
|
185
|
+
else:
|
|
186
|
+
self.prompt_loader = PromptLoader(
|
|
187
|
+
prompts_dir=self.config.PROMT_FILES_DIR
|
|
188
|
+
)
|
|
189
|
+
logger.info(f"✅ Используется стандартный Prompt Loader")
|
|
190
|
+
|
|
182
191
|
await self.prompt_loader.validate_prompts()
|
|
183
192
|
logger.info(f"✅ Prompt Loader инициализирован")
|
|
184
193
|
|
|
@@ -365,6 +374,34 @@ class BotBuilder:
|
|
|
365
374
|
"""Получает список обработчиков on_start"""
|
|
366
375
|
return self._start_handlers.copy()
|
|
367
376
|
|
|
377
|
+
def set_prompt_loader(self, prompt_loader):
|
|
378
|
+
"""
|
|
379
|
+
Устанавливает кастомный PromptLoader
|
|
380
|
+
|
|
381
|
+
Должен быть вызван ДО build()
|
|
382
|
+
|
|
383
|
+
Args:
|
|
384
|
+
prompt_loader: Экземпляр PromptLoader или его наследника (например UserPromptLoader)
|
|
385
|
+
|
|
386
|
+
Example:
|
|
387
|
+
from smart_bot_factory.utils import UserPromptLoader
|
|
388
|
+
|
|
389
|
+
# Использовать UserPromptLoader с автопоиском prompts_dir
|
|
390
|
+
custom_loader = UserPromptLoader("my-bot")
|
|
391
|
+
bot_builder.set_prompt_loader(custom_loader)
|
|
392
|
+
|
|
393
|
+
# Или кастомный наследник
|
|
394
|
+
class MyPromptLoader(UserPromptLoader):
|
|
395
|
+
def __init__(self, bot_id):
|
|
396
|
+
super().__init__(bot_id)
|
|
397
|
+
self.extra_file = self.prompts_dir / 'extra.txt'
|
|
398
|
+
|
|
399
|
+
my_loader = MyPromptLoader("my-bot")
|
|
400
|
+
bot_builder.set_prompt_loader(my_loader)
|
|
401
|
+
"""
|
|
402
|
+
self._custom_prompt_loader = prompt_loader
|
|
403
|
+
logger.info(f"✅ Установлен кастомный PromptLoader: {type(prompt_loader).__name__}")
|
|
404
|
+
|
|
368
405
|
# ========== ХУКИ ДЛЯ КАСТОМИЗАЦИИ ОБРАБОТКИ СООБЩЕНИЙ ==========
|
|
369
406
|
|
|
370
407
|
def validate_message(self, handler):
|
|
@@ -501,7 +501,10 @@ async def process_user_message(message: Message, state: FSMContext, session_id:
|
|
|
501
501
|
validators = message_hooks.get('validators', [])
|
|
502
502
|
for validator in validators:
|
|
503
503
|
try:
|
|
504
|
-
|
|
504
|
+
user_message = message.text
|
|
505
|
+
message_obj = message
|
|
506
|
+
|
|
507
|
+
should_continue = await validator(user_message, message_obj)
|
|
505
508
|
if not should_continue:
|
|
506
509
|
logger.info(f"⛔ Валидатор '{validator.__name__}' прервал обработку")
|
|
507
510
|
return # Прерываем обработку
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Utils модули smart_bot_factory
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from ..integrations.supabase_client import SupabaseClient
|
|
6
|
-
from ..utils.prompt_loader import PromptLoader
|
|
7
|
-
from ..utils.debug_routing import setup_debug_handlers
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
from .user_prompt_loader import UserPromptLoader
|
|
7
|
+
|
|
8
|
+
__all__ = [ # Базовый класс (для библиотеки)
|
|
9
|
+
'UserPromptLoader', # Для пользователей (автопоиск prompts_dir)
|
|
10
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
UserPromptLoader - упрощенный PromptLoader для пользователей библиотеки
|
|
3
|
+
с автоматическим поиском prompts_dir от корня проекта
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from .prompt_loader import PromptLoader
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class UserPromptLoader(PromptLoader):
|
|
14
|
+
"""
|
|
15
|
+
PromptLoader для пользователей библиотеки с автоматическим поиском prompts_dir
|
|
16
|
+
|
|
17
|
+
Автоматически находит папку prompts для указанного бота от корня проекта
|
|
18
|
+
Наследуется от базового PromptLoader - все методы доступны
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, bot_id: str, prompts_subdir: str = "prompts"):
|
|
22
|
+
"""
|
|
23
|
+
Инициализация загрузчика промптов с автоматическим поиском
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
bot_id: Идентификатор бота
|
|
27
|
+
prompts_subdir: Подпапка с промптами (по умолчанию "prompts")
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
# Автоматически найдет bots/my-bot/prompts
|
|
31
|
+
loader = UserPromptLoader("my-bot")
|
|
32
|
+
|
|
33
|
+
# Или кастомную подпапку
|
|
34
|
+
loader = UserPromptLoader("my-bot", "custom_prompts")
|
|
35
|
+
|
|
36
|
+
# Наследование для кастомизации
|
|
37
|
+
class MyLoader(UserPromptLoader):
|
|
38
|
+
def __init__(self, bot_id):
|
|
39
|
+
super().__init__(bot_id)
|
|
40
|
+
# Добавить свою логику
|
|
41
|
+
self.extra_file = self.prompts_dir / 'extra.txt'
|
|
42
|
+
"""
|
|
43
|
+
from project_root_finder import root
|
|
44
|
+
|
|
45
|
+
# Автоматически определяем путь к промптам
|
|
46
|
+
prompts_dir = root / "bots" / bot_id / prompts_subdir
|
|
47
|
+
|
|
48
|
+
if not prompts_dir.exists():
|
|
49
|
+
logger.warning(f"⚠️ Папка промптов не найдена: {prompts_dir}")
|
|
50
|
+
logger.warning(f" Создайте папку или проверьте bot_id")
|
|
51
|
+
|
|
52
|
+
# Вызываем базовую инициализацию
|
|
53
|
+
super().__init__(str(prompts_dir))
|
|
54
|
+
|
|
55
|
+
logger.info(f"✅ UserPromptLoader создан для bot_id '{bot_id}': {prompts_dir}")
|
|
56
|
+
|
|
@@ -33,10 +33,10 @@ 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=Fud-E3J-S7IEjWBfFhRu4YXnJZHbNHG33zqgGk_Cy8I,35585
|
|
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=B2N0yF_dRxSqtnSmXJ6yuy6YGqnZh4BYtMCOsH4Ah5Q,41558
|
|
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
|
|
@@ -45,11 +45,12 @@ smart_bot_factory/supabase/__init__.py,sha256=XmZP6yM9ffERM5ddAWyJnrNzEhCYtMu3Ac
|
|
|
45
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
|
-
smart_bot_factory/utils/__init__.py,sha256=
|
|
48
|
+
smart_bot_factory/utils/__init__.py,sha256=UhsJXEHfrIK8h1AHsroHSwAriijk-LvnqLyvgzi2VYs,273
|
|
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
|
|
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/utils/user_prompt_loader.py,sha256=dk6P0X_3UcNqxjRtuIvb0LcPrp03zIIsstZwdmeCPaE,2519
|
|
52
|
+
smart_bot_factory-0.2.7.dist-info/METADATA,sha256=zCi3KVFYZ8fMucBQ5QXIYfb4rtmpqARFXn7tpeaZ7ps,28224
|
|
53
|
+
smart_bot_factory-0.2.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
54
|
+
smart_bot_factory-0.2.7.dist-info/entry_points.txt,sha256=ybKEAI0WSb7WoRiey7QE-HHfn88UGV7nxLDxXq7b7SU,50
|
|
55
|
+
smart_bot_factory-0.2.7.dist-info/licenses/LICENSE,sha256=OrK3cwdUTzNzIhJvSPtJaVMoYIyC_sSx5EFE_FDMvGs,1092
|
|
56
|
+
smart_bot_factory-0.2.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|