smart-bot-factory 1.1.1__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.
- smart_bot_factory/__init__.py +3 -0
- smart_bot_factory/admin/__init__.py +18 -0
- smart_bot_factory/admin/admin_events.py +1223 -0
- smart_bot_factory/admin/admin_logic.py +553 -0
- smart_bot_factory/admin/admin_manager.py +156 -0
- smart_bot_factory/admin/admin_tester.py +157 -0
- smart_bot_factory/admin/timeout_checker.py +547 -0
- smart_bot_factory/aiogram_calendar/__init__.py +14 -0
- smart_bot_factory/aiogram_calendar/common.py +64 -0
- smart_bot_factory/aiogram_calendar/dialog_calendar.py +259 -0
- smart_bot_factory/aiogram_calendar/schemas.py +99 -0
- smart_bot_factory/aiogram_calendar/simple_calendar.py +224 -0
- smart_bot_factory/analytics/analytics_manager.py +414 -0
- smart_bot_factory/cli.py +806 -0
- smart_bot_factory/config.py +258 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/1sales_context.txt +16 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/2product_info.txt +582 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/3objection_handling.txt +66 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/final_instructions.txt +212 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/help_message.txt +28 -0
- smart_bot_factory/configs/growthmed-october-24/prompts/welcome_message.txt +8 -0
- smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064229.txt +818 -0
- smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064335.txt +32 -0
- smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064638.txt +35 -0
- smart_bot_factory/configs/growthmed-october-24/tests/quick_scenarios.yaml +133 -0
- smart_bot_factory/configs/growthmed-october-24/tests/realistic_scenarios.yaml +108 -0
- smart_bot_factory/configs/growthmed-october-24/tests/scenario_examples.yaml +46 -0
- smart_bot_factory/configs/growthmed-october-24/welcome_file/welcome_file_msg.txt +16 -0
- smart_bot_factory/configs/growthmed-october-24/welcome_file//342/225/250/320/267/342/225/250/342/225/241/342/225/250/342/225/221 /342/225/250/342/225/227/342/225/250/342/225/225/342/225/244/320/221/342/225/244/320/222 /342/225/250/342/224/220/342/225/250/342/225/233 152/342/225/250/320/264/342/225/250/320/247 /342/225/250/342/225/225 323/342/225/250/320/264/342/225/250/320/247 /342/225/250/342/224/244/342/225/250/342/225/227/342/225/244/320/237 /342/225/250/342/225/235/342/225/250/342/225/241/342/225/250/342/224/244/342/225/250/342/225/225/342/225/244/320/226/342/225/250/342/225/225/342/225/250/342/225/234/342/225/244/320/233.pdf +0 -0
- smart_bot_factory/core/bot_utils.py +1108 -0
- smart_bot_factory/core/conversation_manager.py +653 -0
- smart_bot_factory/core/decorators.py +2464 -0
- smart_bot_factory/core/message_sender.py +729 -0
- smart_bot_factory/core/router.py +347 -0
- smart_bot_factory/core/router_manager.py +218 -0
- smart_bot_factory/core/states.py +27 -0
- smart_bot_factory/creation/__init__.py +7 -0
- smart_bot_factory/creation/bot_builder.py +1093 -0
- smart_bot_factory/creation/bot_testing.py +1122 -0
- smart_bot_factory/dashboard/__init__.py +3 -0
- smart_bot_factory/event/__init__.py +7 -0
- smart_bot_factory/handlers/handlers.py +2013 -0
- smart_bot_factory/integrations/langchain_openai.py +542 -0
- smart_bot_factory/integrations/openai_client.py +513 -0
- smart_bot_factory/integrations/supabase_client.py +1678 -0
- smart_bot_factory/memory/__init__.py +8 -0
- smart_bot_factory/memory/memory_manager.py +299 -0
- smart_bot_factory/memory/static_memory.py +214 -0
- smart_bot_factory/message/__init__.py +56 -0
- smart_bot_factory/rag/__init__.py +5 -0
- smart_bot_factory/rag/decorators.py +29 -0
- smart_bot_factory/rag/router.py +54 -0
- smart_bot_factory/rag/templates/__init__.py +3 -0
- smart_bot_factory/rag/templates/create_table.sql +7 -0
- smart_bot_factory/rag/templates/create_table_and_function_template.py +94 -0
- smart_bot_factory/rag/templates/match_function.sql +61 -0
- smart_bot_factory/rag/templates/match_services_template.py +82 -0
- smart_bot_factory/rag/vectorstore.py +449 -0
- smart_bot_factory/router/__init__.py +10 -0
- smart_bot_factory/setup_checker.py +512 -0
- smart_bot_factory/supabase/__init__.py +7 -0
- smart_bot_factory/supabase/client.py +631 -0
- smart_bot_factory/utils/__init__.py +11 -0
- smart_bot_factory/utils/debug_routing.py +114 -0
- smart_bot_factory/utils/prompt_loader.py +529 -0
- smart_bot_factory/utils/tool_router.py +68 -0
- smart_bot_factory/utils/user_prompt_loader.py +55 -0
- smart_bot_factory/utm_link_generator.py +123 -0
- smart_bot_factory-1.1.1.dist-info/METADATA +1135 -0
- smart_bot_factory-1.1.1.dist-info/RECORD +73 -0
- smart_bot_factory-1.1.1.dist-info/WHEEL +4 -0
- smart_bot_factory-1.1.1.dist-info/entry_points.txt +2 -0
- smart_bot_factory-1.1.1.dist-info/licenses/LICENSE +24 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Шаблон для генерации SQL создания таблицы и функции match.
|
|
3
|
+
Используйте f-строку для заполнения параметров.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def generate_table_and_function_sql(
|
|
8
|
+
table_name: str,
|
|
9
|
+
embedding_dim: int = 1536,
|
|
10
|
+
) -> str:
|
|
11
|
+
"""
|
|
12
|
+
Генерирует SQL код для создания таблицы и функции match.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
table_name: Название таблицы
|
|
16
|
+
embedding_dim: Размерность вектора embedding (по умолчанию 1536 для text-embedding-3-small)
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
SQL код для создания таблицы и функции
|
|
20
|
+
"""
|
|
21
|
+
function_name = f"match_{table_name}"
|
|
22
|
+
|
|
23
|
+
sql = f"""-- Создание таблицы {table_name}
|
|
24
|
+
CREATE TABLE IF NOT EXISTS {table_name} (
|
|
25
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
26
|
+
content text,
|
|
27
|
+
metadata jsonb,
|
|
28
|
+
embedding vector({embedding_dim})
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
-- Создание функции {function_name}
|
|
32
|
+
CREATE OR REPLACE FUNCTION {function_name}(
|
|
33
|
+
query_embedding vector,
|
|
34
|
+
filter jsonb DEFAULT '{{}}'::jsonb
|
|
35
|
+
)
|
|
36
|
+
RETURNS TABLE(
|
|
37
|
+
id uuid,
|
|
38
|
+
content text,
|
|
39
|
+
metadata jsonb,
|
|
40
|
+
similarity double precision
|
|
41
|
+
)
|
|
42
|
+
LANGUAGE plpgsql
|
|
43
|
+
AS $function$
|
|
44
|
+
DECLARE
|
|
45
|
+
filter_conditions text := '';
|
|
46
|
+
filter_key text;
|
|
47
|
+
filter_value jsonb;
|
|
48
|
+
array_elements text;
|
|
49
|
+
BEGIN
|
|
50
|
+
-- Проверяем, есть ли фильтры
|
|
51
|
+
IF filter IS NOT NULL AND filter != '{{}}'::jsonb THEN
|
|
52
|
+
FOR filter_key, filter_value IN SELECT * FROM jsonb_each(filter)
|
|
53
|
+
LOOP
|
|
54
|
+
-- Строковые значения
|
|
55
|
+
IF jsonb_typeof(filter_value) = 'string' THEN
|
|
56
|
+
filter_conditions := filter_conditions ||
|
|
57
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{{}}');
|
|
58
|
+
|
|
59
|
+
-- Массивы
|
|
60
|
+
ELSIF jsonb_typeof(filter_value) = 'array' THEN
|
|
61
|
+
SELECT string_agg(quote_literal(elem::text), ',')
|
|
62
|
+
INTO array_elements
|
|
63
|
+
FROM jsonb_array_elements_text(filter_value) AS elem;
|
|
64
|
+
|
|
65
|
+
IF array_elements IS NOT NULL THEN
|
|
66
|
+
filter_conditions := filter_conditions ||
|
|
67
|
+
format(' AND metadata->>%L = ANY(ARRAY[%s])', filter_key, array_elements);
|
|
68
|
+
END IF;
|
|
69
|
+
|
|
70
|
+
-- Числа и boolean
|
|
71
|
+
ELSIF jsonb_typeof(filter_value) IN ('number', 'boolean') THEN
|
|
72
|
+
filter_conditions := filter_conditions ||
|
|
73
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{{}}');
|
|
74
|
+
END IF;
|
|
75
|
+
END LOOP;
|
|
76
|
+
END IF;
|
|
77
|
+
|
|
78
|
+
-- Выполняем запрос
|
|
79
|
+
RETURN QUERY EXECUTE format(
|
|
80
|
+
'SELECT
|
|
81
|
+
s.id,
|
|
82
|
+
s.content,
|
|
83
|
+
s.metadata,
|
|
84
|
+
1 - (s.embedding <=> $1) AS similarity
|
|
85
|
+
FROM {table_name} s
|
|
86
|
+
WHERE TRUE %s
|
|
87
|
+
ORDER BY s.embedding <=> $1',
|
|
88
|
+
filter_conditions
|
|
89
|
+
) USING query_embedding;
|
|
90
|
+
END;
|
|
91
|
+
$function$;
|
|
92
|
+
"""
|
|
93
|
+
return sql
|
|
94
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
CREATE FUNCTION {function_name}(
|
|
2
|
+
filter jsonb DEFAULT '{}',
|
|
3
|
+
query_embedding vector({embedding_dim})
|
|
4
|
+
)
|
|
5
|
+
RETURNS TABLE (
|
|
6
|
+
id bigint,
|
|
7
|
+
content text,
|
|
8
|
+
metadata jsonb,
|
|
9
|
+
similarity float
|
|
10
|
+
)
|
|
11
|
+
LANGUAGE plpgsql
|
|
12
|
+
AS $$
|
|
13
|
+
DECLARE
|
|
14
|
+
filter_conditions text := '';
|
|
15
|
+
filter_key text;
|
|
16
|
+
filter_value jsonb;
|
|
17
|
+
array_elements text;
|
|
18
|
+
BEGIN
|
|
19
|
+
-- Проверяем, есть ли фильтры
|
|
20
|
+
IF filter IS NOT NULL AND filter != '{}'::jsonb THEN
|
|
21
|
+
FOR filter_key, filter_value IN SELECT * FROM jsonb_each(filter)
|
|
22
|
+
LOOP
|
|
23
|
+
-- Строковые значения
|
|
24
|
+
IF jsonb_typeof(filter_value) = 'string' THEN
|
|
25
|
+
filter_conditions := filter_conditions ||
|
|
26
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{}');
|
|
27
|
+
|
|
28
|
+
-- Массивы
|
|
29
|
+
ELSIF jsonb_typeof(filter_value) = 'array' THEN
|
|
30
|
+
SELECT string_agg(quote_literal(elem::text), ',')
|
|
31
|
+
INTO array_elements
|
|
32
|
+
FROM jsonb_array_elements_text(filter_value) AS elem;
|
|
33
|
+
|
|
34
|
+
IF array_elements IS NOT NULL THEN
|
|
35
|
+
filter_conditions := filter_conditions ||
|
|
36
|
+
format(' AND metadata->>%L = ANY(ARRAY[%s])', filter_key, array_elements);
|
|
37
|
+
END IF;
|
|
38
|
+
|
|
39
|
+
-- Числа и boolean
|
|
40
|
+
ELSIF jsonb_typeof(filter_value) IN ('number', 'boolean') THEN
|
|
41
|
+
filter_conditions := filter_conditions ||
|
|
42
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{}');
|
|
43
|
+
END IF;
|
|
44
|
+
END LOOP;
|
|
45
|
+
END IF;
|
|
46
|
+
|
|
47
|
+
-- Выполняем запрос
|
|
48
|
+
RETURN QUERY EXECUTE format(
|
|
49
|
+
'SELECT
|
|
50
|
+
s.id,
|
|
51
|
+
s.content,
|
|
52
|
+
s.metadata,
|
|
53
|
+
1 - (s.embedding <=> $1) AS similarity
|
|
54
|
+
FROM {table_name} s
|
|
55
|
+
WHERE TRUE %s
|
|
56
|
+
ORDER BY s.embedding <=> $1',
|
|
57
|
+
filter_conditions
|
|
58
|
+
) USING query_embedding;
|
|
59
|
+
END;
|
|
60
|
+
$$;
|
|
61
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Шаблон для генерации SQL функции match_services.
|
|
3
|
+
Используйте f-строку для заполнения параметров.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def generate_match_services_sql(
|
|
8
|
+
table_name: str,
|
|
9
|
+
function_name: str,
|
|
10
|
+
) -> str:
|
|
11
|
+
"""
|
|
12
|
+
Генерирует SQL код для создания функции match_services.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
table_name: Название таблицы
|
|
16
|
+
function_name: Название функции
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
SQL код для создания функции
|
|
20
|
+
"""
|
|
21
|
+
sql = f"""CREATE OR REPLACE FUNCTION {function_name}(
|
|
22
|
+
query_embedding vector,
|
|
23
|
+
filter jsonb DEFAULT '{{}}'::jsonb
|
|
24
|
+
)
|
|
25
|
+
RETURNS TABLE(
|
|
26
|
+
id uuid,
|
|
27
|
+
content text,
|
|
28
|
+
metadata jsonb,
|
|
29
|
+
similarity double precision
|
|
30
|
+
)
|
|
31
|
+
LANGUAGE plpgsql
|
|
32
|
+
AS $function$
|
|
33
|
+
DECLARE
|
|
34
|
+
filter_conditions text := '';
|
|
35
|
+
filter_key text;
|
|
36
|
+
filter_value jsonb;
|
|
37
|
+
array_elements text;
|
|
38
|
+
BEGIN
|
|
39
|
+
-- Проверяем, есть ли фильтры
|
|
40
|
+
IF filter IS NOT NULL AND filter != '{{}}'::jsonb THEN
|
|
41
|
+
FOR filter_key, filter_value IN SELECT * FROM jsonb_each(filter)
|
|
42
|
+
LOOP
|
|
43
|
+
-- Строковые значения
|
|
44
|
+
IF jsonb_typeof(filter_value) = 'string' THEN
|
|
45
|
+
filter_conditions := filter_conditions ||
|
|
46
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{{}}');
|
|
47
|
+
|
|
48
|
+
-- Массивы
|
|
49
|
+
ELSIF jsonb_typeof(filter_value) = 'array' THEN
|
|
50
|
+
SELECT string_agg(quote_literal(elem::text), ',')
|
|
51
|
+
INTO array_elements
|
|
52
|
+
FROM jsonb_array_elements_text(filter_value) AS elem;
|
|
53
|
+
|
|
54
|
+
IF array_elements IS NOT NULL THEN
|
|
55
|
+
filter_conditions := filter_conditions ||
|
|
56
|
+
format(' AND metadata->>%L = ANY(ARRAY[%s])', filter_key, array_elements);
|
|
57
|
+
END IF;
|
|
58
|
+
|
|
59
|
+
-- Числа и boolean
|
|
60
|
+
ELSIF jsonb_typeof(filter_value) IN ('number', 'boolean') THEN
|
|
61
|
+
filter_conditions := filter_conditions ||
|
|
62
|
+
format(' AND metadata->>%L = %L', filter_key, filter_value #>> '{{}}');
|
|
63
|
+
END IF;
|
|
64
|
+
END LOOP;
|
|
65
|
+
END IF;
|
|
66
|
+
|
|
67
|
+
-- Выполняем запрос
|
|
68
|
+
RETURN QUERY EXECUTE format(
|
|
69
|
+
'SELECT
|
|
70
|
+
s.id,
|
|
71
|
+
s.content,
|
|
72
|
+
s.metadata,
|
|
73
|
+
1 - (s.embedding <=> $1) AS similarity
|
|
74
|
+
FROM {table_name} s
|
|
75
|
+
WHERE TRUE %s
|
|
76
|
+
ORDER BY s.embedding <=> $1',
|
|
77
|
+
filter_conditions
|
|
78
|
+
) USING query_embedding;
|
|
79
|
+
END;
|
|
80
|
+
$function$;
|
|
81
|
+
"""
|
|
82
|
+
return sql
|