rasa-pro 3.14.0.dev20250922__py3-none-any.whl → 3.14.0rc2__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 (304) hide show
  1. rasa/__main__.py +15 -3
  2. rasa/agents/__init__.py +0 -0
  3. rasa/agents/agent_factory.py +122 -0
  4. rasa/agents/agent_manager.py +211 -0
  5. rasa/agents/constants.py +43 -0
  6. rasa/agents/core/__init__.py +0 -0
  7. rasa/agents/core/agent_protocol.py +107 -0
  8. rasa/agents/core/types.py +81 -0
  9. rasa/agents/exceptions.py +38 -0
  10. rasa/agents/protocol/__init__.py +5 -0
  11. rasa/agents/protocol/a2a/__init__.py +0 -0
  12. rasa/agents/protocol/a2a/a2a_agent.py +879 -0
  13. rasa/agents/protocol/mcp/__init__.py +0 -0
  14. rasa/agents/protocol/mcp/mcp_base_agent.py +726 -0
  15. rasa/agents/protocol/mcp/mcp_open_agent.py +327 -0
  16. rasa/agents/protocol/mcp/mcp_task_agent.py +522 -0
  17. rasa/agents/schemas/__init__.py +13 -0
  18. rasa/agents/schemas/agent_input.py +38 -0
  19. rasa/agents/schemas/agent_output.py +26 -0
  20. rasa/agents/schemas/agent_tool_result.py +65 -0
  21. rasa/agents/schemas/agent_tool_schema.py +186 -0
  22. rasa/agents/templates/__init__.py +0 -0
  23. rasa/agents/templates/mcp_open_agent_prompt_template.jinja2 +20 -0
  24. rasa/agents/templates/mcp_task_agent_prompt_template.jinja2 +22 -0
  25. rasa/agents/utils.py +206 -0
  26. rasa/agents/validation.py +485 -0
  27. rasa/api.py +24 -9
  28. rasa/builder/config.py +6 -2
  29. rasa/builder/copilot/constants.py +4 -1
  30. rasa/builder/copilot/copilot.py +155 -79
  31. rasa/builder/copilot/models.py +304 -108
  32. rasa/builder/copilot/prompts/copilot_training_error_handler_prompt.jinja2 +53 -0
  33. rasa/builder/guardrails/{lakera.py → clients.py} +55 -5
  34. rasa/builder/guardrails/constants.py +3 -0
  35. rasa/builder/guardrails/models.py +45 -10
  36. rasa/builder/guardrails/policy_checker.py +324 -0
  37. rasa/builder/guardrails/utils.py +42 -276
  38. rasa/builder/jobs.py +182 -12
  39. rasa/builder/llm_service.py +32 -5
  40. rasa/builder/models.py +13 -3
  41. rasa/builder/project_generator.py +6 -1
  42. rasa/builder/service.py +31 -15
  43. rasa/builder/training_service.py +18 -24
  44. rasa/builder/validation_service.py +1 -1
  45. rasa/cli/arguments/default_arguments.py +12 -0
  46. rasa/cli/arguments/run.py +2 -0
  47. rasa/cli/arguments/train.py +2 -0
  48. rasa/cli/data.py +10 -8
  49. rasa/cli/dialogue_understanding_test.py +10 -7
  50. rasa/cli/e2e_test.py +9 -6
  51. rasa/cli/evaluate.py +4 -2
  52. rasa/cli/export.py +5 -2
  53. rasa/cli/inspect.py +8 -4
  54. rasa/cli/interactive.py +5 -4
  55. rasa/cli/llm_fine_tuning.py +11 -6
  56. rasa/cli/project_templates/finance/domain/general/help.yml +0 -0
  57. rasa/cli/project_templates/tutorial/credentials.yml +10 -0
  58. rasa/cli/run.py +12 -10
  59. rasa/cli/scaffold.py +4 -4
  60. rasa/cli/shell.py +9 -5
  61. rasa/cli/studio/studio.py +1 -1
  62. rasa/cli/test.py +34 -14
  63. rasa/cli/train.py +41 -28
  64. rasa/cli/utils.py +1 -393
  65. rasa/cli/validation/__init__.py +0 -0
  66. rasa/cli/validation/bot_config.py +223 -0
  67. rasa/cli/validation/config_path_validation.py +257 -0
  68. rasa/cli/x.py +8 -4
  69. rasa/constants.py +7 -1
  70. rasa/core/actions/action.py +51 -10
  71. rasa/core/actions/grpc_custom_action_executor.py +1 -1
  72. rasa/core/agent.py +19 -2
  73. rasa/core/available_agents.py +229 -0
  74. rasa/core/brokers/kafka.py +5 -1
  75. rasa/core/channels/__init__.py +82 -35
  76. rasa/core/channels/development_inspector.py +3 -3
  77. rasa/core/channels/inspector/README.md +25 -13
  78. rasa/core/channels/inspector/dist/assets/{arc-35222594.js → arc-6177260a.js} +1 -1
  79. rasa/core/channels/inspector/dist/assets/{blockDiagram-38ab4fdb-a0efbfd3.js → blockDiagram-38ab4fdb-b054f038.js} +1 -1
  80. rasa/core/channels/inspector/dist/assets/{c4Diagram-3d4e48cf-0584c0f2.js → c4Diagram-3d4e48cf-f25427d5.js} +1 -1
  81. rasa/core/channels/inspector/dist/assets/channel-bf9cbb34.js +1 -0
  82. rasa/core/channels/inspector/dist/assets/{classDiagram-70f12bd4-39f40dbe.js → classDiagram-70f12bd4-c7a2af53.js} +1 -1
  83. rasa/core/channels/inspector/dist/assets/{classDiagram-v2-f2320105-1ad755f3.js → classDiagram-v2-f2320105-58db65c0.js} +1 -1
  84. rasa/core/channels/inspector/dist/assets/clone-8f9083bb.js +1 -0
  85. rasa/core/channels/inspector/dist/assets/{createText-2e5e7dd3-b0f4f0fe.js → createText-2e5e7dd3-088372e2.js} +1 -1
  86. rasa/core/channels/inspector/dist/assets/{edges-e0da2a9e-9039bff9.js → edges-e0da2a9e-58676240.js} +1 -1
  87. rasa/core/channels/inspector/dist/assets/{erDiagram-9861fffd-65c9b127.js → erDiagram-9861fffd-0c14d7c6.js} +1 -1
  88. rasa/core/channels/inspector/dist/assets/{flowDb-956e92f1-4f08b38e.js → flowDb-956e92f1-ea63f85c.js} +1 -1
  89. rasa/core/channels/inspector/dist/assets/{flowDiagram-66a62f08-e95c362a.js → flowDiagram-66a62f08-a2af48cd.js} +1 -1
  90. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-9ecd5b59.js +1 -0
  91. rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-4a651766-703c3015.js → flowchart-elk-definition-4a651766-6937abe7.js} +1 -1
  92. rasa/core/channels/inspector/dist/assets/{ganttDiagram-c361ad54-699328ea.js → ganttDiagram-c361ad54-7473f357.js} +1 -1
  93. rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-72cf32ee-04cf4b05.js → gitGraphDiagram-72cf32ee-d0c9405e.js} +1 -1
  94. rasa/core/channels/inspector/dist/assets/{graph-ee94449e.js → graph-0a6f8466.js} +1 -1
  95. rasa/core/channels/inspector/dist/assets/{index-3862675e-940162b4.js → index-3862675e-7610671a.js} +1 -1
  96. rasa/core/channels/inspector/dist/assets/index-74e01d94.js +1354 -0
  97. rasa/core/channels/inspector/dist/assets/{infoDiagram-f8f76790-c79c2866.js → infoDiagram-f8f76790-be397dc7.js} +1 -1
  98. rasa/core/channels/inspector/dist/assets/{journeyDiagram-49397b02-84489d30.js → journeyDiagram-49397b02-4cefbf62.js} +1 -1
  99. rasa/core/channels/inspector/dist/assets/{layout-a9aa9858.js → layout-e7fbc2bf.js} +1 -1
  100. rasa/core/channels/inspector/dist/assets/{line-eb73cf26.js → line-a8aa457c.js} +1 -1
  101. rasa/core/channels/inspector/dist/assets/{linear-b3399f9a.js → linear-3351e0d2.js} +1 -1
  102. rasa/core/channels/inspector/dist/assets/{mindmap-definition-fc14e90a-b095bf1a.js → mindmap-definition-fc14e90a-b8cbf605.js} +1 -1
  103. rasa/core/channels/inspector/dist/assets/{pieDiagram-8a3498a8-07644b66.js → pieDiagram-8a3498a8-f327f774.js} +1 -1
  104. rasa/core/channels/inspector/dist/assets/{quadrantDiagram-120e2f19-573a3f9c.js → quadrantDiagram-120e2f19-2854c591.js} +1 -1
  105. rasa/core/channels/inspector/dist/assets/{requirementDiagram-deff3bca-d457e1e1.js → requirementDiagram-deff3bca-964985d5.js} +1 -1
  106. rasa/core/channels/inspector/dist/assets/{sankeyDiagram-04a897e0-9d26e1a2.js → sankeyDiagram-04a897e0-edeb4f33.js} +1 -1
  107. rasa/core/channels/inspector/dist/assets/{sequenceDiagram-704730f1-3a9cde10.js → sequenceDiagram-704730f1-fcf70125.js} +1 -1
  108. rasa/core/channels/inspector/dist/assets/{stateDiagram-587899a1-4f3e8cec.js → stateDiagram-587899a1-0e770395.js} +1 -1
  109. rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-d93cdb3a-e617e5bf.js → stateDiagram-v2-d93cdb3a-af8dcd22.js} +1 -1
  110. rasa/core/channels/inspector/dist/assets/{styles-6aaf32cf-eab30d2f.js → styles-6aaf32cf-36a9e70d.js} +1 -1
  111. rasa/core/channels/inspector/dist/assets/{styles-9a916d00-09994be2.js → styles-9a916d00-884a8b5b.js} +1 -1
  112. rasa/core/channels/inspector/dist/assets/{styles-c10674c1-b7110364.js → styles-c10674c1-dc097813.js} +1 -1
  113. rasa/core/channels/inspector/dist/assets/{svgDrawCommon-08f97a94-3ebc92ad.js → svgDrawCommon-08f97a94-5a2c7eed.js} +1 -1
  114. rasa/core/channels/inspector/dist/assets/{timeline-definition-85554ec2-7d13d2f2.js → timeline-definition-85554ec2-e89c4f6e.js} +1 -1
  115. rasa/core/channels/inspector/dist/assets/{xychartDiagram-e933f94c-488385e1.js → xychartDiagram-e933f94c-afb6fe56.js} +1 -1
  116. rasa/core/channels/inspector/dist/index.html +1 -1
  117. rasa/core/channels/inspector/package.json +18 -18
  118. rasa/core/channels/inspector/src/App.tsx +29 -4
  119. rasa/core/channels/inspector/src/components/DialogueAgentStack.tsx +108 -0
  120. rasa/core/channels/inspector/src/components/{DialogueStack.tsx → DialogueHistoryStack.tsx} +4 -2
  121. rasa/core/channels/inspector/src/helpers/audio/audiostream.ts +7 -4
  122. rasa/core/channels/inspector/src/helpers/formatters.test.ts +4 -0
  123. rasa/core/channels/inspector/src/helpers/formatters.ts +24 -3
  124. rasa/core/channels/inspector/src/helpers/utils.test.ts +127 -0
  125. rasa/core/channels/inspector/src/helpers/utils.ts +66 -1
  126. rasa/core/channels/inspector/src/theme/base/styles.ts +19 -1
  127. rasa/core/channels/inspector/src/types.ts +21 -0
  128. rasa/core/channels/inspector/yarn.lock +336 -189
  129. rasa/core/channels/studio_chat.py +6 -6
  130. rasa/core/channels/telegram.py +4 -9
  131. rasa/core/channels/voice_stream/genesys.py +1 -1
  132. rasa/core/channels/voice_stream/tts/deepgram.py +140 -0
  133. rasa/core/channels/voice_stream/twilio_media_streams.py +5 -1
  134. rasa/core/channels/voice_stream/voice_channel.py +3 -0
  135. rasa/core/concurrent_lock_store.py +38 -21
  136. rasa/core/config/__init__.py +0 -0
  137. rasa/core/{available_endpoints.py → config/available_endpoints.py} +51 -16
  138. rasa/core/config/configuration.py +260 -0
  139. rasa/core/config/credentials.py +19 -0
  140. rasa/core/config/message_procesing_config.py +34 -0
  141. rasa/core/constants.py +10 -0
  142. rasa/core/iam_credentials_providers/aws_iam_credentials_providers.py +69 -4
  143. rasa/core/iam_credentials_providers/credentials_provider_protocol.py +2 -1
  144. rasa/core/lock_store.py +4 -0
  145. rasa/core/policies/enterprise_search_policy.py +5 -3
  146. rasa/core/policies/flow_policy.py +4 -4
  147. rasa/core/policies/flows/agent_executor.py +632 -0
  148. rasa/core/policies/flows/flow_executor.py +136 -75
  149. rasa/core/policies/flows/mcp_tool_executor.py +298 -0
  150. rasa/core/policies/intentless_policy.py +1 -1
  151. rasa/core/policies/ted_policy.py +20 -12
  152. rasa/core/policies/unexpected_intent_policy.py +6 -0
  153. rasa/core/processor.py +68 -44
  154. rasa/core/redis_connection_factory.py +7 -2
  155. rasa/core/run.py +37 -8
  156. rasa/core/test.py +4 -0
  157. rasa/core/tracker_stores/redis_tracker_store.py +4 -0
  158. rasa/core/tracker_stores/sql_tracker_store.py +3 -1
  159. rasa/core/tracker_stores/tracker_store.py +3 -7
  160. rasa/core/train.py +1 -1
  161. rasa/core/training/interactive.py +20 -18
  162. rasa/core/training/story_conflict.py +5 -5
  163. rasa/core/utils.py +22 -23
  164. rasa/dialogue_understanding/commands/__init__.py +8 -0
  165. rasa/dialogue_understanding/commands/cancel_flow_command.py +19 -5
  166. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +21 -2
  167. rasa/dialogue_understanding/commands/clarify_command.py +20 -2
  168. rasa/dialogue_understanding/commands/continue_agent_command.py +91 -0
  169. rasa/dialogue_understanding/commands/knowledge_answer_command.py +21 -2
  170. rasa/dialogue_understanding/commands/restart_agent_command.py +162 -0
  171. rasa/dialogue_understanding/commands/start_flow_command.py +68 -7
  172. rasa/dialogue_understanding/commands/utils.py +124 -2
  173. rasa/dialogue_understanding/generator/command_parser.py +4 -0
  174. rasa/dialogue_understanding/generator/llm_based_command_generator.py +50 -12
  175. rasa/dialogue_understanding/generator/llm_command_generator.py +1 -1
  176. rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +1 -1
  177. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_claude_3_5_sonnet_20240620_template.jinja2 +66 -0
  178. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v2_gpt_4o_2024_11_20_template.jinja2 +66 -0
  179. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_claude_3_5_sonnet_20240620_template.jinja2 +89 -0
  180. rasa/dialogue_understanding/generator/prompt_templates/agent_command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +88 -0
  181. rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +42 -7
  182. rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +40 -3
  183. rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +20 -3
  184. rasa/dialogue_understanding/patterns/cancel.py +27 -6
  185. rasa/dialogue_understanding/patterns/clarify.py +3 -14
  186. rasa/dialogue_understanding/patterns/continue_interrupted.py +239 -6
  187. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +46 -8
  188. rasa/dialogue_understanding/processor/command_processor.py +136 -15
  189. rasa/dialogue_understanding/stack/dialogue_stack.py +98 -2
  190. rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +57 -0
  191. rasa/dialogue_understanding/stack/utils.py +57 -3
  192. rasa/dialogue_understanding/utils.py +24 -4
  193. rasa/dialogue_understanding_test/du_test_runner.py +8 -3
  194. rasa/e2e_test/e2e_test_runner.py +13 -3
  195. rasa/engine/caching.py +2 -2
  196. rasa/engine/constants.py +1 -1
  197. rasa/engine/recipes/default_components.py +138 -49
  198. rasa/engine/recipes/default_recipe.py +108 -11
  199. rasa/engine/runner/dask.py +8 -5
  200. rasa/engine/validation.py +19 -6
  201. rasa/graph_components/validators/default_recipe_validator.py +86 -28
  202. rasa/hooks.py +5 -5
  203. rasa/llm_fine_tuning/utils.py +2 -2
  204. rasa/model_training.py +60 -47
  205. rasa/nlu/classifiers/diet_classifier.py +198 -98
  206. rasa/nlu/classifiers/logistic_regression_classifier.py +1 -4
  207. rasa/nlu/classifiers/mitie_intent_classifier.py +3 -0
  208. rasa/nlu/classifiers/sklearn_intent_classifier.py +1 -3
  209. rasa/nlu/extractors/crf_entity_extractor.py +9 -10
  210. rasa/nlu/extractors/mitie_entity_extractor.py +3 -0
  211. rasa/nlu/extractors/spacy_entity_extractor.py +3 -0
  212. rasa/nlu/featurizers/dense_featurizer/convert_featurizer.py +4 -0
  213. rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py +5 -0
  214. rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +2 -0
  215. rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +3 -0
  216. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +4 -2
  217. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +4 -0
  218. rasa/nlu/selectors/response_selector.py +10 -2
  219. rasa/nlu/tokenizers/jieba_tokenizer.py +3 -4
  220. rasa/nlu/tokenizers/mitie_tokenizer.py +3 -2
  221. rasa/nlu/tokenizers/spacy_tokenizer.py +3 -2
  222. rasa/nlu/utils/mitie_utils.py +3 -0
  223. rasa/nlu/utils/spacy_utils.py +3 -2
  224. rasa/plugin.py +8 -8
  225. rasa/privacy/privacy_manager.py +12 -3
  226. rasa/server.py +15 -3
  227. rasa/shared/agents/__init__.py +0 -0
  228. rasa/shared/agents/auth/__init__.py +0 -0
  229. rasa/shared/agents/auth/agent_auth_factory.py +105 -0
  230. rasa/shared/agents/auth/agent_auth_manager.py +92 -0
  231. rasa/shared/agents/auth/auth_strategy/__init__.py +19 -0
  232. rasa/shared/agents/auth/auth_strategy/agent_auth_strategy.py +52 -0
  233. rasa/shared/agents/auth/auth_strategy/api_key_auth_strategy.py +42 -0
  234. rasa/shared/agents/auth/auth_strategy/bearer_token_auth_strategy.py +28 -0
  235. rasa/shared/agents/auth/auth_strategy/oauth2_auth_strategy.py +167 -0
  236. rasa/shared/agents/auth/constants.py +12 -0
  237. rasa/shared/agents/auth/types.py +12 -0
  238. rasa/shared/agents/utils.py +35 -0
  239. rasa/shared/constants.py +8 -0
  240. rasa/shared/core/constants.py +16 -1
  241. rasa/shared/core/domain.py +0 -7
  242. rasa/shared/core/events.py +327 -0
  243. rasa/shared/core/flows/constants.py +5 -0
  244. rasa/shared/core/flows/flows_list.py +21 -5
  245. rasa/shared/core/flows/flows_yaml_schema.json +119 -184
  246. rasa/shared/core/flows/steps/call.py +49 -5
  247. rasa/shared/core/flows/steps/collect.py +98 -13
  248. rasa/shared/core/flows/validation.py +372 -8
  249. rasa/shared/core/flows/yaml_flows_io.py +3 -2
  250. rasa/shared/core/slots.py +2 -2
  251. rasa/shared/core/trackers.py +5 -2
  252. rasa/shared/exceptions.py +16 -0
  253. rasa/shared/importers/rasa.py +1 -1
  254. rasa/shared/importers/utils.py +9 -3
  255. rasa/shared/providers/llm/_base_litellm_client.py +41 -9
  256. rasa/shared/providers/llm/litellm_router_llm_client.py +8 -4
  257. rasa/shared/providers/llm/llm_client.py +7 -3
  258. rasa/shared/providers/llm/llm_response.py +66 -0
  259. rasa/shared/providers/llm/self_hosted_llm_client.py +8 -4
  260. rasa/shared/utils/common.py +24 -0
  261. rasa/shared/utils/health_check/health_check.py +7 -3
  262. rasa/shared/utils/llm.py +39 -16
  263. rasa/shared/utils/mcp/__init__.py +0 -0
  264. rasa/shared/utils/mcp/server_connection.py +247 -0
  265. rasa/shared/utils/mcp/utils.py +20 -0
  266. rasa/shared/utils/schemas/events.py +42 -0
  267. rasa/shared/utils/yaml.py +3 -1
  268. rasa/studio/pull/pull.py +3 -2
  269. rasa/studio/train.py +8 -7
  270. rasa/studio/upload.py +3 -6
  271. rasa/telemetry.py +69 -5
  272. rasa/tracing/config.py +45 -12
  273. rasa/tracing/constants.py +14 -0
  274. rasa/tracing/instrumentation/attribute_extractors.py +142 -9
  275. rasa/tracing/instrumentation/instrumentation.py +626 -21
  276. rasa/tracing/instrumentation/intentless_policy_instrumentation.py +4 -4
  277. rasa/tracing/instrumentation/metrics.py +32 -0
  278. rasa/tracing/metric_instrument_provider.py +68 -0
  279. rasa/utils/common.py +92 -1
  280. rasa/utils/endpoints.py +11 -2
  281. rasa/utils/log_utils.py +96 -5
  282. rasa/utils/ml_utils.py +1 -1
  283. rasa/utils/tensorflow/__init__.py +7 -0
  284. rasa/utils/tensorflow/callback.py +136 -101
  285. rasa/utils/tensorflow/crf.py +1 -1
  286. rasa/utils/tensorflow/data_generator.py +21 -8
  287. rasa/utils/tensorflow/layers.py +21 -11
  288. rasa/utils/tensorflow/metrics.py +7 -3
  289. rasa/utils/tensorflow/models.py +56 -8
  290. rasa/utils/tensorflow/rasa_layers.py +8 -6
  291. rasa/utils/tensorflow/transformer.py +2 -3
  292. rasa/utils/train_utils.py +54 -24
  293. rasa/validator.py +5 -5
  294. rasa/version.py +1 -1
  295. {rasa_pro-3.14.0.dev20250922.dist-info → rasa_pro-3.14.0rc2.dist-info}/METADATA +47 -41
  296. {rasa_pro-3.14.0.dev20250922.dist-info → rasa_pro-3.14.0rc2.dist-info}/RECORD +299 -238
  297. rasa/builder/scrape_rasa_docs.py +0 -97
  298. rasa/core/channels/inspector/dist/assets/channel-8e08bed9.js +0 -1
  299. rasa/core/channels/inspector/dist/assets/clone-78c82dea.js +0 -1
  300. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-2b08f601.js +0 -1
  301. rasa/core/channels/inspector/dist/assets/index-c941dcb3.js +0 -1336
  302. {rasa_pro-3.14.0.dev20250922.dist-info → rasa_pro-3.14.0rc2.dist-info}/NOTICE +0 -0
  303. {rasa_pro-3.14.0.dev20250922.dist-info → rasa_pro-3.14.0rc2.dist-info}/WHEEL +0 -0
  304. {rasa_pro-3.14.0.dev20250922.dist-info → rasa_pro-3.14.0rc2.dist-info}/entry_points.txt +0 -0
rasa/model_training.py CHANGED
@@ -15,6 +15,10 @@ import rasa.shared.utils.common
15
15
  import rasa.shared.utils.io
16
16
  import rasa.utils.common
17
17
  from rasa import telemetry
18
+ from rasa.core.config.configuration import (
19
+ Configuration,
20
+ MessageProcessingConfigPath,
21
+ )
18
22
  from rasa.core.persistor import StorageType
19
23
  from rasa.engine.caching import LocalTrainingCache
20
24
  from rasa.engine.recipes.recipe import Recipe
@@ -115,58 +119,32 @@ def get_unresolved_slots(domain: Domain, stories: StoryGraph) -> List[Text]:
115
119
  )
116
120
 
117
121
 
118
- def _check_unresolved_slots(domain: Domain, stories: StoryGraph) -> None:
119
- """Checks if there are any unresolved slots.
120
-
121
- Args:
122
- domain: The domain.
123
- stories: The story graph.
124
-
125
- Raises:
126
- `Sys exit` if there are any unresolved slots.
127
-
128
- Returns:
129
- `None` if there are no unresolved slots.
130
- """
131
- unresolved_slots = get_unresolved_slots(domain, stories)
132
- if unresolved_slots:
133
- structlogger.error(
134
- "model.training.check_unresolved_slots.not_in_domain",
135
- slots=unresolved_slots,
136
- event_info=(
137
- f"Unresolved slots found in stories/rules🚨 \n"
138
- f'Tried to set slots "{unresolved_slots}" that are not present in'
139
- f"your domain.\n Check whether they need to be added to the domain or "
140
- f"whether there is a spelling error."
141
- ),
142
- )
143
- rasa.shared.utils.common.display_research_study_prompt()
144
- sys.exit(1)
145
-
146
-
147
122
  async def train(
148
123
  domain: Text,
149
124
  config: Text,
150
125
  training_files: Optional[Union[Text, List[Text]]],
126
+ endpoints: Text = rasa.shared.constants.DEFAULT_ENDPOINTS_PATH,
151
127
  output: Text = rasa.shared.constants.DEFAULT_MODELS_PATH,
152
128
  dry_run: bool = False,
153
129
  force_training: bool = False,
154
- fixed_model_name: Optional[Text] = None,
130
+ fixed_model_name: Optional[str] = None,
155
131
  persist_nlu_training_data: bool = False,
156
132
  core_additional_arguments: Optional[Dict] = None,
157
133
  nlu_additional_arguments: Optional[Dict] = None,
158
- model_to_finetune: Optional[Text] = None,
134
+ model_to_finetune: Optional[str] = None,
159
135
  finetuning_epoch_fraction: float = 1.0,
160
136
  remote_storage: Optional[StorageType] = None,
161
137
  file_importer: Optional[TrainingDataImporter] = None,
162
138
  keep_local_model_copy: bool = False,
163
139
  remote_root_only: bool = False,
140
+ sub_agents: Optional[str] = None,
164
141
  ) -> TrainingResult:
165
142
  """Trains a Rasa model (Core and NLU).
166
143
 
167
144
  Args:
168
145
  domain: Path to the domain file.
169
146
  config: Path to the config file.
147
+ endpoints: Path to the endpoints file.
170
148
  training_files: List of paths to training data files.
171
149
  output: Output directory for the trained model.
172
150
  dry_run: If `True` then no training will be done, and the information about
@@ -190,10 +168,17 @@ async def train(
190
168
  remote storage is configured.
191
169
  remote_root_only: If `True`, the model will be stored in the root of the
192
170
  remote model storage.
171
+ sub_agents: Path to sub-agents directory.
193
172
 
194
173
  Returns:
195
174
  An instance of `TrainingResult`.
196
175
  """
176
+ Configuration.initialise_message_processing(
177
+ message_processing_config_path=MessageProcessingConfigPath.validate(
178
+ Path(config)
179
+ )
180
+ ).initialise_endpoints(endpoints_path=Path(endpoints))
181
+
197
182
  if not file_importer:
198
183
  file_importer = TrainingDataImporter.load_from_config(
199
184
  config, domain, training_files, core_additional_arguments
@@ -278,6 +263,35 @@ async def train(
278
263
  )
279
264
 
280
265
 
266
+ def _check_unresolved_slots(domain: Domain, stories: StoryGraph) -> None:
267
+ """Checks if there are any unresolved slots.
268
+
269
+ Args:
270
+ domain: The domain.
271
+ stories: The story graph.
272
+
273
+ Raises:
274
+ `Sys exit` if there are any unresolved slots.
275
+
276
+ Returns:
277
+ `None` if there are no unresolved slots.
278
+ """
279
+ unresolved_slots = get_unresolved_slots(domain, stories)
280
+ if unresolved_slots:
281
+ structlogger.error(
282
+ "model.training.check_unresolved_slots.not_in_domain",
283
+ slots=unresolved_slots,
284
+ event_info=(
285
+ f"Unresolved slots found in stories/rules🚨 \n"
286
+ f'Tried to set slots "{unresolved_slots}" that are not present in'
287
+ f"your domain.\n Check whether they need to be added to the domain or "
288
+ f"whether there is a spelling error."
289
+ ),
290
+ )
291
+ rasa.shared.utils.common.display_research_study_prompt()
292
+ sys.exit(1)
293
+
294
+
281
295
  async def _train_graph(
282
296
  file_importer: TrainingDataImporter,
283
297
  training_type: TrainingType,
@@ -292,24 +306,19 @@ async def _train_graph(
292
306
  **kwargs: Any,
293
307
  ) -> TrainingResult:
294
308
  if model_to_finetune:
295
- model_to_finetune = rasa.model.get_model_for_finetuning(model_to_finetune)
296
- if not model_to_finetune:
297
- structlogger.error(
298
- "model_training.train.finetuning_model_not_found",
299
- event_info=(
300
- f"No model for finetuning found. Please make sure to either "
301
- f"specify a path to a previous model or to have a finetunable "
302
- f"model within the directory '{output_path}'."
303
- ),
304
- )
305
- rasa.shared.utils.common.display_research_study_prompt()
306
- sys.exit(1)
307
-
308
- rasa.shared.utils.common.mark_as_experimental_feature(
309
- "Incremental Training feature"
309
+ structlogger.error(
310
+ "model_training.train.incremental_training_not_supported",
311
+ event_info=(
312
+ "Incremental training (--finetune) is "
313
+ "not supported in Rasa 3.14.0 onwards. "
314
+ "Please retrain your model from scratch "
315
+ "if you have updated your configuration. "
316
+ ),
310
317
  )
318
+ rasa.shared.utils.common.display_research_study_prompt()
319
+ sys.exit(1)
311
320
 
312
- is_finetuning = model_to_finetune is not None
321
+ is_finetuning = False # Incremental training is not supported in Rasa 3.14.0+
313
322
 
314
323
  config = file_importer.get_config()
315
324
  recipe = Recipe.recipe_for_name(config.get(CONFIG_RECIPE_KEY))
@@ -573,6 +582,10 @@ async def train_nlu(
573
582
  )
574
583
  return None
575
584
 
585
+ Configuration.initialise_message_processing(
586
+ message_processing_config_path=Path(config),
587
+ ).initialise_empty_endpoints()
588
+
576
589
  return (
577
590
  await _train_graph(
578
591
  file_importer,
@@ -8,7 +8,13 @@ from typing import Any, Dict, List, Optional, Text, Tuple, Type, TypeVar, Union
8
8
 
9
9
  import numpy as np
10
10
  import scipy.sparse
11
- import tensorflow as tf
11
+
12
+ from rasa.utils.tensorflow import TENSORFLOW_AVAILABLE
13
+
14
+ if TENSORFLOW_AVAILABLE:
15
+ import tensorflow as tf
16
+ else:
17
+ tf = None
12
18
 
13
19
  import rasa.nlu.utils.bilou_utils as bilou_utils
14
20
  import rasa.shared.utils.io
@@ -16,7 +22,6 @@ from rasa.engine.graph import ExecutionContext, GraphComponent
16
22
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
17
23
  from rasa.engine.storage.resource import Resource
18
24
  from rasa.engine.storage.storage import ModelStorage
19
- from rasa.exceptions import ModelNotFound
20
25
  from rasa.nlu.classifiers import LABEL_RANKING_LENGTH
21
26
  from rasa.nlu.classifiers.classifier import IntentClassifier
22
27
  from rasa.nlu.constants import DEFAULT_TRANSFORMER_SIZE, TOKENS_NAMES
@@ -38,77 +43,155 @@ from rasa.shared.nlu.constants import (
38
43
  )
39
44
  from rasa.shared.nlu.training_data.message import Message
40
45
  from rasa.shared.nlu.training_data.training_data import TrainingData
46
+ from rasa.shared.utils.io import raise_deprecation_warning
41
47
  from rasa.utils import train_utils
42
- from rasa.utils.tensorflow import rasa_layers
43
- from rasa.utils.tensorflow.constants import (
44
- AUTO,
45
- BALANCED,
46
- BATCH_SIZES,
47
- BATCH_STRATEGY,
48
- BILOU_FLAG,
49
- CHECKPOINT_MODEL,
50
- CONCAT_DIMENSION,
51
- CONNECTION_DENSITY,
52
- CONSTRAIN_SIMILARITIES,
53
- CROSS_ENTROPY,
54
- DENSE_DIMENSION,
55
- DENSE_INPUT_DROPOUT,
56
- DROP_RATE,
57
- DROP_RATE_ATTENTION,
58
- DROP_SMALL_LAST_BATCH,
59
- EMBEDDING_DIMENSION,
60
- ENTITY_RECOGNITION,
61
- EPOCHS,
62
- EVAL_NUM_EPOCHS,
63
- EVAL_NUM_EXAMPLES,
64
- FEATURIZERS,
65
- HIDDEN_LAYERS_SIZES,
66
- IDS,
67
- INTENT_CLASSIFICATION,
68
- KEY_RELATIVE_ATTENTION,
69
- LABEL,
70
- LEARNING_RATE,
71
- LOSS_TYPE,
72
- MASK,
73
- MASKED_LM,
74
- MAX_NEG_SIM,
75
- MAX_POS_SIM,
76
- MAX_RELATIVE_POSITION,
77
- MODEL_CONFIDENCE,
78
- NEGATIVE_MARGIN_SCALE,
79
- NUM_HEADS,
80
- NUM_NEG,
81
- NUM_TRANSFORMER_LAYERS,
82
- RANDOM_SEED,
83
- RANKING_LENGTH,
84
- REGULARIZATION_CONSTANT,
85
- RENORMALIZE_CONFIDENCES,
86
- RUN_EAGERLY,
87
- SCALE_LOSS,
88
- SENTENCE,
89
- SEQUENCE,
90
- SEQUENCE_LENGTH,
91
- SHARE_HIDDEN_LAYERS,
92
- SIMILARITY_TYPE,
93
- SOFTMAX,
94
- SPARSE_INPUT_DROPOUT,
95
- TENSORBOARD_LOG_DIR,
96
- TENSORBOARD_LOG_LEVEL,
97
- TRANSFORMER_SIZE,
98
- UNIDIRECTIONAL_ENCODER,
99
- USE_MAX_NEG_SIM,
100
- VALUE_RELATIVE_ATTENTION,
101
- )
102
- from rasa.utils.tensorflow.feature_array import (
103
- FeatureArray,
104
- deserialize_nested_feature_arrays,
105
- serialize_nested_feature_arrays,
106
- )
107
- from rasa.utils.tensorflow.model_data import (
108
- FeatureSignature,
109
- RasaModelData,
110
- )
111
- from rasa.utils.tensorflow.models import RasaModel, TransformerRasaModel
48
+
49
+ if TENSORFLOW_AVAILABLE:
50
+ from rasa.utils.tensorflow import rasa_layers
51
+ else:
52
+ rasa_layers = None # type: ignore
53
+ if TENSORFLOW_AVAILABLE:
54
+ from rasa.utils.tensorflow.constants import (
55
+ AUTO,
56
+ BALANCED,
57
+ BATCH_SIZES,
58
+ BATCH_STRATEGY,
59
+ BILOU_FLAG,
60
+ CHECKPOINT_MODEL,
61
+ CONCAT_DIMENSION,
62
+ CONNECTION_DENSITY,
63
+ CONSTRAIN_SIMILARITIES,
64
+ CROSS_ENTROPY,
65
+ DENSE_DIMENSION,
66
+ DENSE_INPUT_DROPOUT,
67
+ DROP_RATE,
68
+ DROP_RATE_ATTENTION,
69
+ DROP_SMALL_LAST_BATCH,
70
+ EMBEDDING_DIMENSION,
71
+ ENTITY_RECOGNITION,
72
+ EPOCHS,
73
+ EVAL_NUM_EPOCHS,
74
+ EVAL_NUM_EXAMPLES,
75
+ FEATURIZERS,
76
+ HIDDEN_LAYERS_SIZES,
77
+ IDS,
78
+ INTENT_CLASSIFICATION,
79
+ KEY_RELATIVE_ATTENTION,
80
+ LABEL,
81
+ LEARNING_RATE,
82
+ LOSS_TYPE,
83
+ MASK,
84
+ MASKED_LM,
85
+ MAX_NEG_SIM,
86
+ MAX_POS_SIM,
87
+ MAX_RELATIVE_POSITION,
88
+ MODEL_CONFIDENCE,
89
+ NEGATIVE_MARGIN_SCALE,
90
+ NUM_HEADS,
91
+ NUM_NEG,
92
+ NUM_TRANSFORMER_LAYERS,
93
+ RANDOM_SEED,
94
+ RANKING_LENGTH,
95
+ REGULARIZATION_CONSTANT,
96
+ RENORMALIZE_CONFIDENCES,
97
+ RUN_EAGERLY,
98
+ SCALE_LOSS,
99
+ SENTENCE,
100
+ SEQUENCE,
101
+ SEQUENCE_LENGTH,
102
+ SHARE_HIDDEN_LAYERS,
103
+ SIMILARITY_TYPE,
104
+ SOFTMAX,
105
+ SPARSE_INPUT_DROPOUT,
106
+ TENSORBOARD_LOG_DIR,
107
+ TENSORBOARD_LOG_LEVEL,
108
+ TRANSFORMER_SIZE,
109
+ UNIDIRECTIONAL_ENCODER,
110
+ USE_MAX_NEG_SIM,
111
+ VALUE_RELATIVE_ATTENTION,
112
+ )
113
+ else:
114
+ # Placeholder values when TensorFlow is not available
115
+ AUTO = "auto"
116
+ BALANCED = "balanced"
117
+ BATCH_SIZES = "batch_sizes"
118
+ BATCH_STRATEGY = "batch_strategy"
119
+ BILOU_FLAG = "bilou_flag"
120
+ CHECKPOINT_MODEL = "checkpoint_model"
121
+ CONCAT_DIMENSION = "concat_dimension"
122
+ CONNECTION_DENSITY = "connection_density"
123
+ CONSTRAIN_SIMILARITIES = "constrain_similarities"
124
+ CROSS_ENTROPY = "cross_entropy"
125
+ DENSE_DIMENSION = "dense_dimension"
126
+ DENSE_INPUT_DROPOUT = "dense_input_dropout"
127
+ DROP_RATE = "drop_rate"
128
+ DROP_RATE_ATTENTION = "drop_rate_attention"
129
+ DROP_SMALL_LAST_BATCH = "drop_small_last_batch"
130
+ EMBEDDING_DIMENSION = "embedding_dimension"
131
+ ENTITY_RECOGNITION = "entity_recognition"
132
+ EPOCHS = "epochs"
133
+ EVAL_NUM_EPOCHS = "eval_num_epochs"
134
+ EVAL_NUM_EXAMPLES = "eval_num_examples"
135
+ FEATURIZERS = "featurizers"
136
+ HIDDEN_LAYERS_SIZES = "hidden_layers_sizes"
137
+ IDS = "ids"
138
+ INTENT_CLASSIFICATION = "intent_classification"
139
+ KEY_RELATIVE_ATTENTION = "key_relative_attention"
140
+ LABEL = "label"
141
+ LEARNING_RATE = "learning_rate"
142
+ LOSS_TYPE = "loss_type"
143
+ MASK = "mask"
144
+ MASKED_LM = "masked_lm"
145
+ MAX_NEG_SIM = "max_neg_sim"
146
+ MAX_POS_SIM = "max_pos_sim"
147
+ MAX_RELATIVE_POSITION = "max_relative_position"
148
+ MODEL_CONFIDENCE = "model_confidence"
149
+ NEGATIVE_MARGIN_SCALE = "negative_margin_scale"
150
+ NUM_HEADS = "num_heads"
151
+ NUM_NEG = "num_neg"
152
+ NUM_TRANSFORMER_LAYERS = "num_transformer_layers"
153
+ RANDOM_SEED = "random_seed"
154
+ RANKING_LENGTH = "ranking_length"
155
+ REGULARIZATION_CONSTANT = "regularization_constant"
156
+ RENORMALIZE_CONFIDENCES = "renormalize_confidences"
157
+ RUN_EAGERLY = "run_eagerly"
158
+ SCALE_LOSS = "scale_loss"
159
+ SENTENCE = "sentence"
160
+ SEQUENCE = "sequence"
161
+ SEQUENCE_LENGTH = "sequence_length"
162
+ SHARE_HIDDEN_LAYERS = "share_hidden_layers"
163
+ SIMILARITY_TYPE = "similarity_type"
164
+ SOFTMAX = "softmax"
165
+ SPARSE_INPUT_DROPOUT = "sparse_input_dropout"
166
+ TENSORBOARD_LOG_DIR = "tensorboard_log_dir"
167
+ TENSORBOARD_LOG_LEVEL = "tensorboard_log_level"
168
+ TRANSFORMER_SIZE = "transformer_size"
169
+ UNIDIRECTIONAL_ENCODER = "unidirectional_encoder"
170
+ USE_MAX_NEG_SIM = "use_max_neg_sim"
171
+ VALUE_RELATIVE_ATTENTION = "value_relative_attention"
172
+ if TENSORFLOW_AVAILABLE:
173
+ from rasa.utils.tensorflow.feature_array import (
174
+ FeatureArray,
175
+ deserialize_nested_feature_arrays,
176
+ serialize_nested_feature_arrays,
177
+ )
178
+ else:
179
+ FeatureArray = None # type: ignore
180
+ deserialize_nested_feature_arrays = None # type: ignore
181
+ serialize_nested_feature_arrays = None # type: ignore
182
+ if TENSORFLOW_AVAILABLE:
183
+ from rasa.utils.tensorflow.model_data import (
184
+ FeatureSignature,
185
+ RasaModelData,
186
+ )
187
+ else:
188
+ FeatureSignature = None # type: ignore
189
+ RasaModelData = None # type: ignore
190
+ if TENSORFLOW_AVAILABLE:
191
+ from rasa.utils.tensorflow.models import RasaModel, TransformerRasaModel
192
+ else:
193
+ RasaModel = None # type: ignore
194
+ TransformerRasaModel = None # type: ignore
112
195
 
113
196
  logger = logging.getLogger(__name__)
114
197
 
@@ -306,6 +389,9 @@ class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin):
306
389
  sparse_feature_sizes: Optional[Dict[Text, Dict[Text, List[int]]]] = None,
307
390
  ) -> None:
308
391
  """Declare instance variables with default values."""
392
+ raise_deprecation_warning(
393
+ "DIETClassifier is deprecated and will be removed in a future version."
394
+ )
309
395
  if EPOCHS not in config:
310
396
  rasa.shared.utils.io.raise_warning(
311
397
  f"Please configure the number of '{EPOCHS}' in your configuration file."
@@ -906,24 +992,16 @@ class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin):
906
992
  # keep one example for persisting and loading
907
993
  self._data_example = model_data.first_data_example()
908
994
 
909
- if not self.finetune_mode:
910
- # No pre-trained model to load from. Create a new instance of the model.
911
- self.model = self._instantiate_model_class(model_data)
912
- self.model.compile(
913
- optimizer=tf.keras.optimizers.Adam(
914
- self.component_config[LEARNING_RATE]
915
- ),
916
- run_eagerly=self.component_config[RUN_EAGERLY],
917
- )
918
- else:
919
- if self.model is None:
920
- raise ModelNotFound("Model could not be found. ")
995
+ # as the keras 2.15 does not allow updating a compiled model anymore,
996
+ # we cannot support finetune mode anymore
997
+
998
+ # Create a new instance of the model.
999
+ self.model = self._instantiate_model_class(model_data)
1000
+ self.model.compile(
1001
+ optimizer=tf.keras.optimizers.Adam(self.component_config[LEARNING_RATE]),
1002
+ run_eagerly=self.component_config[RUN_EAGERLY],
1003
+ )
921
1004
 
922
- self.model.adjust_for_incremental_training(
923
- data_example=self._data_example,
924
- new_sparse_feature_sizes=model_data.get_sparse_feature_sizes(),
925
- old_sparse_feature_sizes=self._sparse_feature_sizes,
926
- )
927
1005
  self._sparse_feature_sizes = model_data.get_sparse_feature_sizes()
928
1006
 
929
1007
  data_generator, validation_data_generator = train_utils.create_data_generators(
@@ -1070,12 +1148,14 @@ class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin):
1070
1148
 
1071
1149
  with self._model_storage.write_to(self._resource) as model_path:
1072
1150
  file_name = self.__class__.__name__
1073
- tf_model_file = model_path / f"{file_name}.tf_model"
1151
+ tf_model_file = model_path / f"{file_name}.weights.h5"
1074
1152
 
1075
1153
  rasa.shared.utils.io.create_directory_for_file(tf_model_file)
1076
1154
 
1077
1155
  if self.component_config[CHECKPOINT_MODEL] and self.tmp_checkpoint_dir:
1078
- self.model.load_weights(self.tmp_checkpoint_dir / "checkpoint.tf_model")
1156
+ self.model.load_weights(
1157
+ self.tmp_checkpoint_dir / "checkpoint.weights.h5"
1158
+ )
1079
1159
  # Save an empty file to flag that this model has been
1080
1160
  # produced using checkpointing
1081
1161
  checkpoint_marker = model_path / f"{file_name}.from_checkpoint.pkl"
@@ -1247,7 +1327,7 @@ class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin):
1247
1327
  finetune_mode: bool = False,
1248
1328
  ) -> "RasaModel":
1249
1329
  file_name = cls.__name__
1250
- tf_model_file = model_path / f"{file_name}.tf_model"
1330
+ tf_model_file = model_path / f"{file_name}.weights.h5"
1251
1331
 
1252
1332
  label_key = LABEL_KEY if config[INTENT_CLASSIFICATION] else None
1253
1333
  label_sub_key = LABEL_SUB_KEY if config[INTENT_CLASSIFICATION] else None
@@ -1306,7 +1386,7 @@ class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin):
1306
1386
  )
1307
1387
 
1308
1388
 
1309
- class DIET(TransformerRasaModel):
1389
+ class DIET(TransformerRasaModel if TENSORFLOW_AVAILABLE else object): # type: ignore[misc]
1310
1390
  def __init__(
1311
1391
  self,
1312
1392
  data_signature: Dict[Text, Dict[Text, List[FeatureSignature]]],
@@ -1314,6 +1394,8 @@ class DIET(TransformerRasaModel):
1314
1394
  entity_tag_specs: Optional[List[EntityTagSpec]],
1315
1395
  config: Dict[Text, Any],
1316
1396
  ) -> None:
1397
+ if not TENSORFLOW_AVAILABLE:
1398
+ raise RuntimeError("DIET classifier requires TensorFlow to be installed")
1317
1399
  # create entity tag spec before calling super otherwise building the model
1318
1400
  # will fail
1319
1401
  super().__init__("DIET", config, data_signature, label_data)
@@ -1527,7 +1609,7 @@ class DIET(TransformerRasaModel):
1527
1609
  # convert to bag-of-words by summing along the sequence dimension
1528
1610
  x = tf.reduce_sum(x, axis=1)
1529
1611
 
1530
- return self._tf_layers[f"ffnn.{name}"](x, self._training)
1612
+ return self._tf_layers[f"ffnn.{name}"](x, training=self._training)
1531
1613
 
1532
1614
  def _create_all_labels(self) -> Tuple[tf.Tensor, tf.Tensor]:
1533
1615
  all_label_ids = self.tf_label_data[LABEL_KEY][LABEL_SUB_KEY][0]
@@ -1536,9 +1618,23 @@ class DIET(TransformerRasaModel):
1536
1618
  self.tf_label_data, LABEL
1537
1619
  )
1538
1620
 
1621
+ # Check if SENTENCE features exist, if not use None
1622
+ # This is needed for compatibility with tensorFlow=2.19.1, which
1623
+ # has a transitive dependency on keras=3.11.3, which introduces
1624
+ # stricter data validation
1625
+ sentence_features = None
1626
+ if SENTENCE in self.tf_label_data[LABEL]:
1627
+ sentence_features = self.tf_label_data[LABEL][SENTENCE]
1628
+
1629
+ # Handle missing SEQUENCE features for Keras 3+ compatibility,
1630
+ # which introduces stricter data validation
1631
+ sequence_features = None
1632
+ if SEQUENCE in self.tf_label_data[LABEL]:
1633
+ sequence_features = self.tf_label_data[LABEL][SEQUENCE]
1634
+
1539
1635
  x = self._create_bow(
1540
- self.tf_label_data[LABEL][SEQUENCE],
1541
- self.tf_label_data[LABEL][SENTENCE],
1636
+ sequence_features,
1637
+ sentence_features,
1542
1638
  sequence_feature_lengths,
1543
1639
  self.label_name,
1544
1640
  )
@@ -1797,8 +1893,12 @@ class DIET(TransformerRasaModel):
1797
1893
  )
1798
1894
  predictions = {
1799
1895
  DIAGNOSTIC_DATA: {
1800
- "attention_weights": attention_weights,
1801
- "text_transformed": text_transformed,
1896
+ "attention_weights": attention_weights.numpy()
1897
+ if hasattr(attention_weights, "numpy")
1898
+ else attention_weights,
1899
+ "text_transformed": text_transformed.numpy()
1900
+ if hasattr(text_transformed, "numpy")
1901
+ else text_transformed,
1802
1902
  }
1803
1903
  }
1804
1904
 
@@ -1,5 +1,6 @@
1
1
  from typing import Any, Dict, List, Text, Tuple, Type
2
2
 
3
+ import skops.io as sio
3
4
  import structlog
4
5
  from scipy.sparse import csr_matrix, hstack, vstack
5
6
  from sklearn.exceptions import NotFittedError
@@ -183,8 +184,6 @@ class LogisticRegressionClassifier(IntentClassifier, GraphComponent):
183
184
 
184
185
  def persist(self) -> None:
185
186
  """Persist this model into the passed directory."""
186
- import skops.io as sio
187
-
188
187
  with self._model_storage.write_to(self._resource) as model_dir:
189
188
  path = model_dir / f"{self._resource.name}.skops"
190
189
  sio.dump(self.clf, path)
@@ -203,8 +202,6 @@ class LogisticRegressionClassifier(IntentClassifier, GraphComponent):
203
202
  **kwargs: Any,
204
203
  ) -> "LogisticRegressionClassifier":
205
204
  """Loads trained component (see parent class for full docstring)."""
206
- import skops.io as sio
207
-
208
205
  try:
209
206
  with model_storage.read_from(resource) as model_dir:
210
207
  classifier_file = model_dir / f"{resource.name}.skops"
@@ -4,6 +4,9 @@ import logging
4
4
  import typing
5
5
  from typing import Any, Dict, List, Optional, Text, Type
6
6
 
7
+ # importing mitie at module level to ensure error is raised if mitie is not installed
8
+ import mitie
9
+
7
10
  from rasa.engine.graph import ExecutionContext, GraphComponent
8
11
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
9
12
  from rasa.engine.storage.resource import Resource
@@ -6,6 +6,7 @@ import warnings
6
6
  from typing import Any, Dict, List, Optional, Text, Tuple, Type
7
7
 
8
8
  import numpy as np
9
+ import skops.io as sio
9
10
 
10
11
  import rasa.shared.utils.io
11
12
  from rasa.engine.graph import ExecutionContext, GraphComponent
@@ -266,8 +267,6 @@ class SklearnIntentClassifier(GraphComponent, IntentClassifier):
266
267
 
267
268
  def persist(self) -> None:
268
269
  """Persist this model into the passed directory."""
269
- import skops.io as sio
270
-
271
270
  with self._model_storage.write_to(self._resource) as model_dir:
272
271
  file_name = self.__class__.__name__
273
272
  classifier_file_name = model_dir / f"{file_name}_classifier.skops"
@@ -291,7 +290,6 @@ class SklearnIntentClassifier(GraphComponent, IntentClassifier):
291
290
  **kwargs: Any,
292
291
  ) -> SklearnIntentClassifier:
293
292
  """Loads trained component (see parent class for full docstring)."""
294
- import skops.io as sio
295
293
  from sklearn.preprocessing import LabelEncoder
296
294
 
297
295
  try:
@@ -10,6 +10,9 @@ from typing import Any, Callable, Dict, List, Optional, Text, Tuple, Type
10
10
 
11
11
  import numpy as np
12
12
 
13
+ # importing sklearn_crfsuite at module level to raise error if not installed
14
+ import sklearn_crfsuite
15
+
13
16
  import rasa.nlu.utils.bilou_utils as bilou_utils
14
17
  import rasa.shared.utils.io
15
18
  import rasa.utils.train_utils
@@ -20,7 +23,6 @@ from rasa.engine.storage.storage import ModelStorage
20
23
  from rasa.nlu.constants import TOKENS_NAMES
21
24
  from rasa.nlu.extractors.extractor import EntityExtractorMixin
22
25
  from rasa.nlu.test import determine_token_labels
23
- from rasa.nlu.tokenizers.spacy_tokenizer import POS_TAG_KEY
24
26
  from rasa.nlu.tokenizers.tokenizer import Token, Tokenizer
25
27
  from rasa.shared.constants import DOCS_URL_COMPONENTS
26
28
  from rasa.shared.nlu.constants import (
@@ -37,6 +39,8 @@ from rasa.shared.nlu.training_data.message import Message
37
39
  from rasa.shared.nlu.training_data.training_data import TrainingData
38
40
  from rasa.utils.tensorflow.constants import BILOU_FLAG, FEATURIZERS
39
41
 
42
+ POS_TAG_KEY = "pos"
43
+
40
44
  logger = logging.getLogger(__name__)
41
45
 
42
46
  if typing.TYPE_CHECKING:
@@ -445,13 +449,11 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin):
445
449
  def _load_taggers(
446
450
  cls, model_dir: Path, config: Dict[Text, Any]
447
451
  ) -> Dict[str, "CRF"]:
448
- """
449
- Load taggers from model directory that persists trained binary
450
- `model.crfsuite` files.
451
- """
452
+ """Load taggers from model directory.
452
453
 
454
+ It persists trained binary `model.crfsuite` files.
455
+ """
453
456
  import pycrfsuite
454
- import sklearn_crfsuite
455
457
 
456
458
  # Get tagger directories
457
459
  taggers_base = model_dir / TAGGERS_DIR
@@ -613,8 +615,7 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin):
613
615
 
614
616
  @staticmethod
615
617
  def _pattern_of_token(message: Message, idx: int) -> Dict[Text, bool]:
616
- """Get the patterns of the token at the given index extracted by the
617
- 'RegexFeaturizer'.
618
+ """Get patterns of token at the given index extracted by 'RegexFeaturizer'.
618
619
 
619
620
  The 'RegexFeaturizer' adds all patterns listed in the training data to the
620
621
  token. The pattern name is mapped to either 'True' (pattern applies to token) or
@@ -728,8 +729,6 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin):
728
729
  crf_order: List[str],
729
730
  ) -> OrderedDict[str, CRF]:
730
731
  """Train the crf tagger based on the training data."""
731
- import sklearn_crfsuite
732
-
733
732
  entity_taggers = OrderedDict()
734
733
 
735
734
  for tag_name in crf_order: