rasa-pro 3.13.0.dev20250612__py3-none-any.whl → 3.13.0.dev20250613__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 rasa-pro might be problematic. Click here for more details.

Files changed (156) hide show
  1. rasa/__main__.py +0 -3
  2. rasa/api.py +1 -1
  3. rasa/cli/dialogue_understanding_test.py +1 -1
  4. rasa/cli/e2e_test.py +1 -1
  5. rasa/cli/evaluate.py +1 -1
  6. rasa/cli/export.py +1 -1
  7. rasa/cli/llm_fine_tuning.py +12 -11
  8. rasa/cli/project_templates/defaults.py +133 -0
  9. rasa/cli/run.py +1 -1
  10. rasa/cli/studio/link.py +53 -0
  11. rasa/cli/studio/pull.py +78 -0
  12. rasa/cli/studio/push.py +78 -0
  13. rasa/cli/studio/studio.py +12 -0
  14. rasa/cli/studio/upload.py +8 -0
  15. rasa/cli/train.py +1 -1
  16. rasa/cli/utils.py +1 -1
  17. rasa/cli/x.py +1 -1
  18. rasa/constants.py +2 -0
  19. rasa/core/__init__.py +0 -16
  20. rasa/core/actions/action.py +5 -1
  21. rasa/core/actions/action_repeat_bot_messages.py +18 -22
  22. rasa/core/actions/action_run_slot_rejections.py +0 -1
  23. rasa/core/agent.py +16 -1
  24. rasa/core/available_endpoints.py +146 -0
  25. rasa/core/brokers/pika.py +1 -2
  26. rasa/core/channels/botframework.py +2 -2
  27. rasa/core/channels/channel.py +2 -2
  28. rasa/core/channels/hangouts.py +8 -5
  29. rasa/core/channels/mattermost.py +1 -1
  30. rasa/core/channels/rasa_chat.py +2 -4
  31. rasa/core/channels/rest.py +5 -4
  32. rasa/core/channels/studio_chat.py +3 -2
  33. rasa/core/channels/vier_cvg.py +1 -2
  34. rasa/core/channels/voice_ready/audiocodes.py +1 -8
  35. rasa/core/channels/voice_stream/audiocodes.py +7 -4
  36. rasa/core/channels/voice_stream/genesys.py +2 -2
  37. rasa/core/channels/voice_stream/twilio_media_streams.py +10 -5
  38. rasa/core/channels/voice_stream/voice_channel.py +33 -22
  39. rasa/core/http_interpreter.py +3 -7
  40. rasa/core/jobs.py +2 -1
  41. rasa/core/nlg/contextual_response_rephraser.py +38 -11
  42. rasa/core/nlg/generator.py +0 -1
  43. rasa/core/nlg/interpolator.py +2 -3
  44. rasa/core/nlg/summarize.py +39 -5
  45. rasa/core/policies/enterprise_search_policy.py +290 -66
  46. rasa/core/policies/enterprise_search_prompt_with_relevancy_check_and_citation_template.jinja2 +63 -0
  47. rasa/core/policies/flow_policy.py +1 -1
  48. rasa/core/policies/flows/flow_executor.py +96 -17
  49. rasa/core/policies/intentless_policy.py +24 -16
  50. rasa/core/processor.py +104 -51
  51. rasa/core/run.py +33 -11
  52. rasa/core/tracker_stores/tracker_store.py +1 -1
  53. rasa/core/training/interactive.py +1 -1
  54. rasa/core/utils.py +24 -97
  55. rasa/dialogue_understanding/coexistence/intent_based_router.py +2 -1
  56. rasa/dialogue_understanding/coexistence/llm_based_router.py +8 -3
  57. rasa/dialogue_understanding/commands/can_not_handle_command.py +2 -0
  58. rasa/dialogue_understanding/commands/cancel_flow_command.py +2 -0
  59. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +2 -0
  60. rasa/dialogue_understanding/commands/clarify_command.py +5 -1
  61. rasa/dialogue_understanding/commands/command_syntax_manager.py +1 -0
  62. rasa/dialogue_understanding/commands/human_handoff_command.py +2 -0
  63. rasa/dialogue_understanding/commands/knowledge_answer_command.py +2 -0
  64. rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +2 -0
  65. rasa/dialogue_understanding/commands/set_slot_command.py +11 -1
  66. rasa/dialogue_understanding/commands/skip_question_command.py +2 -0
  67. rasa/dialogue_understanding/commands/start_flow_command.py +4 -0
  68. rasa/dialogue_understanding/commands/utils.py +26 -2
  69. rasa/dialogue_understanding/generator/__init__.py +7 -1
  70. rasa/dialogue_understanding/generator/command_generator.py +4 -2
  71. rasa/dialogue_understanding/generator/command_parser.py +2 -2
  72. rasa/dialogue_understanding/generator/command_parser_validator.py +63 -0
  73. rasa/dialogue_understanding/generator/constants.py +2 -2
  74. rasa/dialogue_understanding/generator/prompt_templates/command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +78 -0
  75. rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +28 -463
  76. rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +147 -0
  77. rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +477 -0
  78. rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +8 -58
  79. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +37 -25
  80. rasa/dialogue_understanding/patterns/domain_for_patterns.py +190 -0
  81. rasa/dialogue_understanding/processor/command_processor.py +3 -3
  82. rasa/dialogue_understanding/processor/command_processor_component.py +3 -3
  83. rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +17 -4
  84. rasa/dialogue_understanding/utils.py +68 -12
  85. rasa/dialogue_understanding_test/du_test_case.py +1 -1
  86. rasa/dialogue_understanding_test/du_test_runner.py +4 -22
  87. rasa/dialogue_understanding_test/test_case_simulation/test_case_tracker_simulator.py +2 -6
  88. rasa/e2e_test/e2e_test_runner.py +1 -1
  89. rasa/engine/constants.py +1 -1
  90. rasa/engine/recipes/default_recipe.py +26 -2
  91. rasa/engine/validation.py +3 -2
  92. rasa/hooks.py +0 -28
  93. rasa/llm_fine_tuning/annotation_module.py +39 -9
  94. rasa/llm_fine_tuning/conversations.py +3 -0
  95. rasa/llm_fine_tuning/llm_data_preparation_module.py +66 -49
  96. rasa/llm_fine_tuning/paraphrasing/conversation_rephraser.py +4 -2
  97. rasa/llm_fine_tuning/paraphrasing/rephrase_validator.py +52 -44
  98. rasa/llm_fine_tuning/paraphrasing_module.py +10 -12
  99. rasa/llm_fine_tuning/storage.py +4 -4
  100. rasa/llm_fine_tuning/utils.py +63 -1
  101. rasa/model_manager/model_api.py +88 -0
  102. rasa/model_manager/trainer_service.py +4 -4
  103. rasa/plugin.py +1 -11
  104. rasa/privacy/__init__.py +0 -0
  105. rasa/privacy/constants.py +83 -0
  106. rasa/privacy/event_broker_utils.py +77 -0
  107. rasa/privacy/privacy_config.py +281 -0
  108. rasa/privacy/privacy_config_schema.json +86 -0
  109. rasa/privacy/privacy_filter.py +340 -0
  110. rasa/privacy/privacy_manager.py +576 -0
  111. rasa/server.py +23 -2
  112. rasa/shared/constants.py +6 -0
  113. rasa/shared/core/constants.py +4 -3
  114. rasa/shared/core/domain.py +7 -0
  115. rasa/shared/core/events.py +37 -7
  116. rasa/shared/core/flows/flow.py +1 -2
  117. rasa/shared/core/flows/flows_yaml_schema.json +3 -0
  118. rasa/shared/core/flows/steps/collect.py +46 -2
  119. rasa/shared/core/slots.py +28 -0
  120. rasa/shared/exceptions.py +4 -0
  121. rasa/shared/providers/_configs/azure_openai_client_config.py +4 -0
  122. rasa/shared/providers/_configs/openai_client_config.py +4 -0
  123. rasa/shared/providers/embedding/_base_litellm_embedding_client.py +3 -0
  124. rasa/shared/providers/llm/_base_litellm_client.py +5 -2
  125. rasa/shared/utils/llm.py +161 -6
  126. rasa/shared/utils/yaml.py +32 -0
  127. rasa/studio/data_handler.py +3 -3
  128. rasa/studio/download/download.py +37 -60
  129. rasa/studio/download/flows.py +23 -31
  130. rasa/studio/link.py +200 -0
  131. rasa/studio/pull.py +94 -0
  132. rasa/studio/push.py +131 -0
  133. rasa/studio/upload.py +117 -67
  134. rasa/telemetry.py +82 -25
  135. rasa/tracing/config.py +3 -4
  136. rasa/tracing/constants.py +19 -1
  137. rasa/tracing/instrumentation/attribute_extractors.py +10 -2
  138. rasa/tracing/instrumentation/instrumentation.py +53 -2
  139. rasa/tracing/instrumentation/metrics.py +98 -15
  140. rasa/tracing/metric_instrument_provider.py +75 -3
  141. rasa/utils/common.py +1 -27
  142. rasa/utils/log_utils.py +1 -45
  143. rasa/validator.py +2 -8
  144. rasa/version.py +1 -1
  145. {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/METADATA +5 -6
  146. {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/RECORD +149 -135
  147. rasa/anonymization/__init__.py +0 -2
  148. rasa/anonymization/anonymisation_rule_yaml_reader.py +0 -91
  149. rasa/anonymization/anonymization_pipeline.py +0 -286
  150. rasa/anonymization/anonymization_rule_executor.py +0 -266
  151. rasa/anonymization/anonymization_rule_orchestrator.py +0 -119
  152. rasa/anonymization/schemas/config.yml +0 -47
  153. rasa/anonymization/utils.py +0 -118
  154. {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/NOTICE +0 -0
  155. {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/WHEEL +0 -0
  156. {rasa_pro-3.13.0.dev20250612.dist-info → rasa_pro-3.13.0.dev20250613.dist-info}/entry_points.txt +0 -0
@@ -1,11 +1,9 @@
1
- from typing import Any, Dict, List, Tuple, Type
1
+ from typing import Any, Dict, List, Tuple
2
2
 
3
3
  import structlog
4
4
  from tqdm import tqdm
5
5
 
6
- from rasa.dialogue_understanding.generator.llm_based_command_generator import (
7
- LLMBasedCommandGenerator,
8
- )
6
+ from rasa.core.agent import Agent
9
7
  from rasa.llm_fine_tuning.conversations import Conversation
10
8
  from rasa.llm_fine_tuning.paraphrasing.conversation_rephraser import (
11
9
  ConversationRephraser,
@@ -28,8 +26,7 @@ async def create_paraphrased_conversations(
28
26
  rephrase_config: Dict[str, Any],
29
27
  num_rephrases: int,
30
28
  flows: FlowsList,
31
- llm_command_generator: Type[LLMBasedCommandGenerator],
32
- llm_command_generator_config: Dict[str, Any],
29
+ agent: Agent,
33
30
  storage_context: StorageContext,
34
31
  ) -> Tuple[List[Conversation], Dict[str, Any]]:
35
32
  """Create paraphrased conversations.
@@ -42,7 +39,7 @@ async def create_paraphrased_conversations(
42
39
  rephrase_config: The path to the rephrase configuration file.
43
40
  num_rephrases: The number of rephrases to produce per user message.
44
41
  flows: All flows.
45
- llm_command_generator_config: The configuration of the trained model.
42
+ agent: The Rasa agent.
46
43
  storage_context: The storage context.
47
44
 
48
45
  Returns:
@@ -50,7 +47,7 @@ async def create_paraphrased_conversations(
50
47
  rephrasing.
51
48
  """
52
49
  rephraser = ConversationRephraser(rephrase_config)
53
- validator = RephraseValidator(llm_command_generator_config, flows)
50
+ validator = RephraseValidator(flows)
54
51
 
55
52
  if num_rephrases <= 0:
56
53
  structlogger.info(
@@ -64,18 +61,19 @@ async def create_paraphrased_conversations(
64
61
  rephrased_conversations: List[Conversation] = []
65
62
  for i in tqdm(range(len(conversations))):
66
63
  current_conversation = conversations[i]
67
-
68
64
  try:
69
65
  # rephrase all user messages even if rephrase=False is set
70
66
  # to not confuse the LLM and get valid output
71
67
  rephrasings = await rephraser.rephrase_conversation(
72
- conversations[i], num_rephrases
68
+ current_conversation, num_rephrases
73
69
  )
74
70
  # filter out the rephrasings for user messages that have rephrase=False set
75
- rephrasings = _filter_rephrasings(rephrasings, conversations[i])
71
+ rephrasings = _filter_rephrasings(rephrasings, current_conversation)
76
72
  # check if the rephrasings are still producing the same commands
77
73
  rephrasings = await validator.validate_rephrasings(
78
- rephrasings, current_conversation, llm_command_generator
74
+ agent,
75
+ rephrasings,
76
+ current_conversation,
79
77
  )
80
78
  except ProviderClientAPIException as e:
81
79
  structlogger.error(
@@ -96,9 +96,9 @@ class FileStorageStrategy(StorageStrategy):
96
96
  file_path = self._get_file_path(storage_location)
97
97
  self._create_output_dir(file_path)
98
98
 
99
- with open(str(file_path), "w") as outfile:
99
+ with open(str(file_path), "w", encoding="utf-8") as outfile:
100
100
  for example in llm_data:
101
- json.dump(example.as_dict(), outfile)
101
+ json.dump(example.as_dict(), outfile, ensure_ascii=False)
102
102
  outfile.write("\n")
103
103
 
104
104
  def write_formatted_finetuning_data(
@@ -110,9 +110,9 @@ class FileStorageStrategy(StorageStrategy):
110
110
  file_path = self._get_file_path(module_storage_location, file_name)
111
111
  self._create_output_dir(file_path)
112
112
 
113
- with open(str(file_path), "w") as file:
113
+ with open(str(file_path), "w", encoding="utf-8") as file:
114
114
  for example in formatted_data:
115
- json.dump(example.as_dict(), file)
115
+ json.dump(example.as_dict(), file, ensure_ascii=False)
116
116
  file.write("\n")
117
117
 
118
118
  def write_e2e_test_suite_to_yaml_file(
@@ -1,7 +1,69 @@
1
- from typing import List
1
+ from contextlib import contextmanager
2
+ from datetime import datetime
3
+ from typing import Callable, Generator, List, Union
4
+
5
+ import structlog
2
6
 
3
7
  from rasa.dialogue_understanding.commands.prompt_command import PromptCommand
8
+ from rasa.dialogue_understanding.generator import LLMBasedCommandGenerator
9
+ from rasa.shared.providers.llm.llm_response import LLMResponse
10
+
11
+ structlogger = structlog.get_logger()
4
12
 
5
13
 
6
14
  def commands_as_string(commands: List[PromptCommand], delimiter: str = "\n") -> str:
7
15
  return delimiter.join([command.to_dsl() for command in commands])
16
+
17
+
18
+ def make_mock_invoke_llm(commands: str) -> Callable:
19
+ """Capture the `commands` in a closure so the resulting async function
20
+ can use it as its response.
21
+
22
+ Args:
23
+ commands: The commands to return from the mock LLM call.
24
+ """
25
+
26
+ async def _mock_invoke_llm(
27
+ self: LLMBasedCommandGenerator, prompt: Union[List[dict], List[str], str]
28
+ ) -> LLMResponse:
29
+ structlogger.debug(
30
+ f"LLM call intercepted, response mocked. "
31
+ f"Responding with the following commands: '{commands}' "
32
+ f"to the prompt: {prompt}"
33
+ )
34
+ fake_response_dict = {
35
+ "id": "",
36
+ "choices": [commands],
37
+ "created": int(datetime.now().timestamp()),
38
+ "model": "mocked-llm",
39
+ }
40
+ return LLMResponse.from_dict(fake_response_dict)
41
+
42
+ return _mock_invoke_llm
43
+
44
+
45
+ @contextmanager
46
+ def patch_invoke_llm_in_generators(mock_impl: Callable) -> Generator:
47
+ """Replace CommandGenerator.invoke_llm in the base class AND in all
48
+ current subclasses (recursively). Everything is restored on exit.
49
+ """
50
+ originals = {}
51
+
52
+ def collect(cls: type[LLMBasedCommandGenerator]) -> None:
53
+ # store current attribute, then recurse
54
+ originals[cls] = cls.invoke_llm
55
+ for sub in cls.__subclasses__():
56
+ collect(sub)
57
+
58
+ # collect every existing subclass of CommandGenerator
59
+ collect(LLMBasedCommandGenerator) # type: ignore[type-abstract]
60
+
61
+ try:
62
+ # apply the monkey-patch everywhere
63
+ for cls in originals:
64
+ cls.invoke_llm = mock_impl # type: ignore[assignment]
65
+ yield
66
+ finally:
67
+ # restore originals (even if an exception happened)
68
+ for cls, orig in originals.items():
69
+ cls.invoke_llm = orig # type: ignore[assignment]
@@ -7,12 +7,16 @@ from typing import Any, Callable, Dict, Optional, Union
7
7
  import dotenv
8
8
  import psutil
9
9
  import structlog
10
+ from ruamel.yaml import YAMLError
10
11
  from sanic import Blueprint, Sanic, response
11
12
  from sanic.exceptions import NotFound
12
13
  from sanic.request import Request
13
14
  from sanic.response import json
14
15
  from socketio import AsyncServer
15
16
 
17
+ import rasa
18
+ from rasa.cli.project_templates.defaults import get_rasa_defaults
19
+ from rasa.cli.scaffold import ProjectTemplateName, scaffold_path
16
20
  from rasa.constants import MODEL_ARCHIVE_EXTENSION
17
21
  from rasa.exceptions import ModelNotFound
18
22
  from rasa.model_manager import config
@@ -45,6 +49,10 @@ from rasa.model_manager.warm_rasa_process import (
45
49
  initialize_warm_rasa_process,
46
50
  shutdown_warm_rasa_processes,
47
51
  )
52
+ from rasa.server import ErrorResponse
53
+ from rasa.shared.exceptions import InvalidConfigException
54
+ from rasa.shared.utils.yaml import dump_obj_as_yaml_to_string
55
+ from rasa.studio.upload import build_calm_import_parts
48
56
 
49
57
  dotenv.load_dotenv()
50
58
 
@@ -476,6 +484,86 @@ def internal_blueprint() -> Blueprint:
476
484
  except ModelNotFound:
477
485
  return response.raw(b"", status=404)
478
486
 
487
+ @bp.post("/defaults")
488
+ async def get_defaults(request: Request) -> response.HTTPResponse:
489
+ """Returns the system defaults like prompts, patterns, etc."""
490
+ body = request.json or {}
491
+ config_yaml = body.get("config")
492
+ if config_yaml is None:
493
+ exc = ErrorResponse(
494
+ HTTPStatus.BAD_REQUEST,
495
+ "BadRequest",
496
+ "Missing `config` key in request body.",
497
+ )
498
+ return response.json(exc.error_info, status=exc.status)
499
+
500
+ endpoints_yaml = body.get("endpoints")
501
+ if endpoints_yaml is None:
502
+ exc = ErrorResponse(
503
+ HTTPStatus.BAD_REQUEST,
504
+ "BadRequest",
505
+ "Missing `endpoints` key in request body.",
506
+ )
507
+ return response.json(exc.error_info, status=exc.status)
508
+
509
+ try:
510
+ defaults = get_rasa_defaults(config_yaml, endpoints_yaml)
511
+ except (YAMLError, InvalidConfigException) as e:
512
+ exc = ErrorResponse(
513
+ HTTPStatus.INTERNAL_SERVER_ERROR,
514
+ "InitDataError",
515
+ f"Failed to load defaults. Error: {e!s}",
516
+ )
517
+ return response.json(exc.error_info, status=exc.status)
518
+ return response.json(defaults.model_dump(exclude_none=True))
519
+
520
+ @bp.get("/project_template")
521
+ async def get_project_template(request: Request) -> response.HTTPResponse:
522
+ """Return initial project template data."""
523
+ template = request.args.get("template", ProjectTemplateName.DEFAULT.value)
524
+
525
+ try:
526
+ template_enum = ProjectTemplateName(template)
527
+ except ValueError:
528
+ valid_templates = ", ".join([t.value for t in ProjectTemplateName])
529
+ exc = ErrorResponse(
530
+ HTTPStatus.BAD_REQUEST,
531
+ "BadRequest",
532
+ f"Unknown template '{template}'. Valid templates: "
533
+ f"{valid_templates}",
534
+ )
535
+ return response.json(exc.error_info, status=exc.status)
536
+
537
+ template_dir = scaffold_path(template_enum)
538
+ if not os.path.isdir(template_dir):
539
+ exc = ErrorResponse(
540
+ HTTPStatus.INTERNAL_SERVER_ERROR,
541
+ "InitDataError",
542
+ f"Template directory '{template_dir}' not found.",
543
+ )
544
+ return response.json(exc.error_info, status=exc.status)
545
+
546
+ assistant_name, parts = build_calm_import_parts(
547
+ data_path=f"{template_dir}/data",
548
+ domain_path=f"{template_dir}/domain",
549
+ config_path=f"{template_dir}/config.yml",
550
+ endpoints_path=f"{template_dir}/endpoints.yml",
551
+ assistant_name=template_enum.value,
552
+ )
553
+
554
+ defaults = get_rasa_defaults(
555
+ config_yaml=dump_obj_as_yaml_to_string(parts.config),
556
+ endpoints_yaml=dump_obj_as_yaml_to_string(parts.endpoints),
557
+ )
558
+ return response.json(
559
+ {
560
+ **parts.model_dump(exclude_none=True),
561
+ "assistantName": assistant_name,
562
+ "defaults": defaults.model_dump(exclude_none=True),
563
+ "version": rasa.__version__,
564
+ }
565
+ )
566
+
479
567
  return bp
480
568
 
481
569
 
@@ -7,7 +7,7 @@ from typing import Any, Dict, Optional
7
7
  import structlog
8
8
  from pydantic import BaseModel, ConfigDict
9
9
 
10
- from rasa.constants import MODEL_ARCHIVE_EXTENSION
10
+ from rasa.constants import MODEL_ARCHIVE_EXTENSION, RASA_DIR_NAME
11
11
  from rasa.model_manager import config
12
12
  from rasa.model_manager.utils import (
13
13
  ensure_base_directory_exists,
@@ -171,7 +171,7 @@ def seed_training_directory_with_rasa_cache(
171
171
  training_base_path=training_base_path,
172
172
  )
173
173
  # copy the cache to the training directory
174
- shutil.copytree(src=cache_path, dst=subpath(training_base_path, ".rasa"))
174
+ shutil.copytree(src=cache_path, dst=subpath(training_base_path, RASA_DIR_NAME))
175
175
 
176
176
 
177
177
  def persist_rasa_cache(assistant_id: str, training_base_path: str) -> None:
@@ -184,12 +184,12 @@ def persist_rasa_cache(assistant_id: str, training_base_path: str) -> None:
184
184
  cache_path = cache_for_assistant_path(assistant_id)
185
185
 
186
186
  # if the training failed and didn't create a cache, skip this step
187
- if not os.path.exists(subpath(training_base_path, ".rasa")):
187
+ if not os.path.exists(subpath(training_base_path, RASA_DIR_NAME)):
188
188
  return
189
189
 
190
190
  # clean up the cache directory first
191
191
  shutil.rmtree(cache_path, ignore_errors=True)
192
- shutil.copytree(src=subpath(training_base_path, ".rasa"), dst=cache_path)
192
+ shutil.copytree(src=subpath(training_base_path, RASA_DIR_NAME), dst=cache_path)
193
193
 
194
194
 
195
195
  def write_training_data_to_files(
rasa/plugin.py CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  import argparse
4
4
  import functools
5
5
  import sys
6
- from typing import TYPE_CHECKING, Any, List, Optional, Text, Union
6
+ from typing import TYPE_CHECKING, List, Optional, Text, Union
7
7
 
8
8
  import pluggy
9
9
 
@@ -69,16 +69,6 @@ def create_tracker_store( # type: ignore[empty-body]
69
69
  """Hook specification for wrapping with AuthRetryTrackerStore."""
70
70
 
71
71
 
72
- @hookspec(firstresult=True) # type: ignore[misc]
73
- def init_anonymization_pipeline(endpoints_file: Optional[Text]) -> None:
74
- """Hook specification for initialising the anonymization pipeline."""
75
-
76
-
77
- @hookspec(firstresult=True) # type: ignore[misc]
78
- def get_anonymization_pipeline() -> Optional[Any]:
79
- """Hook specification for getting the anonymization pipeline."""
80
-
81
-
82
72
  @hookspec # type: ignore[misc]
83
73
  def after_server_stop() -> None:
84
74
  """Hook specification for stopping the server.
File without changes
@@ -0,0 +1,83 @@
1
+ PRIVACY_CONFIG_SCHEMA = "privacy/privacy_config_schema.json"
2
+ REDACTION_CHAR_KEY = "redaction_char"
3
+ KEEP_LEFT_KEY = "keep_left"
4
+ KEEP_RIGHT_KEY = "keep_right"
5
+ DELETION_KEY = "deletion"
6
+ ANONYMIZATION_KEY = "anonymization"
7
+ TRACKER_STORE_SETTINGS = "tracker_store_settings"
8
+ SLOT_KEY = "slot"
9
+ TEXT_KEY = "text"
10
+ ENTITIES_KEY = "entities"
11
+ VALUE_KEY = "value"
12
+ ENTITY_LABEL_KEY = "label"
13
+
14
+ USER_CHAT_INACTIVITY_IN_MINUTES_ENV_VAR_NAME = "USER_CHAT_INACTIVITY_IN_MINUTES"
15
+ GLINER_MODEL_PATH_ENV_VAR_NAME = "GLINER_MODEL_PATH"
16
+ HUGGINGFACE_CACHE_DIR_ENV_VAR_NAME = "HUGGINGFACE_HUB_CACHE_DIR"
17
+
18
+ DEFAULT_PII_MODEL = "urchade/gliner_multi_pii-v1"
19
+ GLINER_LABELS = [
20
+ "person",
21
+ "organization",
22
+ "company",
23
+ "phone number",
24
+ "address",
25
+ "full address",
26
+ "postcode",
27
+ "zip code",
28
+ "passport number",
29
+ "email",
30
+ "credit card number",
31
+ "social security number",
32
+ "health insurance id number",
33
+ "date of birth",
34
+ "mobile phone number",
35
+ "bank account number",
36
+ "medication",
37
+ "cpf",
38
+ "driver's license number",
39
+ "tax identification number",
40
+ "medical condition",
41
+ "identity card number",
42
+ "national id number",
43
+ "ip address",
44
+ "email address",
45
+ "iban",
46
+ "credit card expiration date",
47
+ "username",
48
+ "health insurance number",
49
+ "registration number",
50
+ "student id number",
51
+ "insurance number",
52
+ "membership number",
53
+ "booking number",
54
+ "landline phone number",
55
+ "blood type",
56
+ "cvv",
57
+ "reservation number",
58
+ "digital signature",
59
+ "social media handle",
60
+ "license plate number",
61
+ "cnpj",
62
+ "postal code",
63
+ "passport_number",
64
+ "serial number",
65
+ "vehicle registration number",
66
+ "fax number",
67
+ "visa number",
68
+ "insurance company",
69
+ "identity document number",
70
+ "transaction number",
71
+ "national health insurance number",
72
+ "cvc",
73
+ "birth certificate number",
74
+ "train ticket number",
75
+ "passport expiration date",
76
+ "social_security_number",
77
+ "personally identifiable information",
78
+ "banking routing number",
79
+ "sort code",
80
+ "routing number",
81
+ "tax number",
82
+ "swift code",
83
+ ]
@@ -0,0 +1,77 @@
1
+ from typing import TYPE_CHECKING, List, Optional
2
+
3
+ import structlog
4
+
5
+ from rasa.core.brokers.broker import EventBroker
6
+ from rasa.utils.endpoints import EndpointConfig
7
+
8
+ if TYPE_CHECKING:
9
+ from asyncio import AbstractEventLoop
10
+
11
+ structlogger = structlog.get_logger(__name__)
12
+
13
+
14
+ async def create_event_brokers(
15
+ event_broker_endpoint: Optional[EndpointConfig],
16
+ event_loop: Optional["AbstractEventLoop"] = None,
17
+ ) -> List[EventBroker]:
18
+ """Create EventBroker objects for each anonymization topic or queue."""
19
+ if event_broker_endpoint is None or event_broker_endpoint.type is None:
20
+ structlogger.debug(
21
+ "rasa.privacy_filtering.create_event_broker.no_event_broker_type",
22
+ )
23
+ return []
24
+
25
+ if event_broker_endpoint.type == "kafka":
26
+ event_collection = event_broker_endpoint.kwargs.get("anonymization_topics", [])
27
+ event_collection_type = "topic"
28
+ elif event_broker_endpoint.type == "pika":
29
+ event_collection = event_broker_endpoint.kwargs.get("anonymization_queues", [])
30
+ event_collection_type = "queues"
31
+ else:
32
+ structlogger.debug(
33
+ "rasa.privacy_filtering.create_event_broker.unsupported_event_broker_type",
34
+ event_broker_type=event_broker_endpoint.type,
35
+ )
36
+ return []
37
+
38
+ if not event_collection:
39
+ structlogger.debug(
40
+ f"rasa.privacy_filtering.create_event_broker.no_anonymization_{event_collection_type}",
41
+ event_collection_type=event_collection_type,
42
+ )
43
+ return []
44
+
45
+ return await _create_event_brokers(
46
+ event_broker_endpoint, event_collection, event_collection_type, event_loop
47
+ )
48
+
49
+
50
+ async def _create_event_brokers(
51
+ event_broker_endpoint: EndpointConfig,
52
+ event_collection: List[str],
53
+ event_collection_type: str,
54
+ event_loop: Optional["AbstractEventLoop"] = None,
55
+ ) -> List[EventBroker]:
56
+ """Create event brokers."""
57
+ event_brokers = []
58
+ for item in event_collection:
59
+ event_broker_endpoint.kwargs[event_collection_type] = (
60
+ item if event_collection_type == "topic" else [item]
61
+ )
62
+ structlogger.debug(
63
+ "rasa.privacy_filtering.create_event_broker",
64
+ event_info=f"Setting anonymized event streaming to '{item}'.",
65
+ )
66
+
67
+ event_broker = await EventBroker.create(event_broker_endpoint, event_loop)
68
+ if event_broker is None:
69
+ structlogger.debug(
70
+ "rasa.privacy_filtering.create_event_broker.no_event_broker_created",
71
+ event_info=f"No event broker created for publishing to '{item}'.",
72
+ )
73
+ continue
74
+
75
+ event_brokers.append(event_broker)
76
+
77
+ return event_brokers