rasa-pro 3.8.16__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 (644) hide show
  1. README.md +380 -0
  2. rasa/__init__.py +10 -0
  3. rasa/__main__.py +151 -0
  4. rasa/anonymization/__init__.py +2 -0
  5. rasa/anonymization/anonymisation_rule_yaml_reader.py +91 -0
  6. rasa/anonymization/anonymization_pipeline.py +287 -0
  7. rasa/anonymization/anonymization_rule_executor.py +260 -0
  8. rasa/anonymization/anonymization_rule_orchestrator.py +120 -0
  9. rasa/anonymization/schemas/config.yml +47 -0
  10. rasa/anonymization/utils.py +117 -0
  11. rasa/api.py +146 -0
  12. rasa/cli/__init__.py +5 -0
  13. rasa/cli/arguments/__init__.py +0 -0
  14. rasa/cli/arguments/data.py +81 -0
  15. rasa/cli/arguments/default_arguments.py +165 -0
  16. rasa/cli/arguments/evaluate.py +65 -0
  17. rasa/cli/arguments/export.py +51 -0
  18. rasa/cli/arguments/interactive.py +74 -0
  19. rasa/cli/arguments/run.py +204 -0
  20. rasa/cli/arguments/shell.py +13 -0
  21. rasa/cli/arguments/test.py +211 -0
  22. rasa/cli/arguments/train.py +263 -0
  23. rasa/cli/arguments/visualize.py +34 -0
  24. rasa/cli/arguments/x.py +30 -0
  25. rasa/cli/data.py +292 -0
  26. rasa/cli/e2e_test.py +566 -0
  27. rasa/cli/evaluate.py +222 -0
  28. rasa/cli/export.py +251 -0
  29. rasa/cli/inspect.py +63 -0
  30. rasa/cli/interactive.py +164 -0
  31. rasa/cli/license.py +65 -0
  32. rasa/cli/markers.py +78 -0
  33. rasa/cli/project_templates/__init__.py +0 -0
  34. rasa/cli/project_templates/calm/actions/__init__.py +0 -0
  35. rasa/cli/project_templates/calm/actions/action_template.py +27 -0
  36. rasa/cli/project_templates/calm/actions/add_contact.py +30 -0
  37. rasa/cli/project_templates/calm/actions/db.py +57 -0
  38. rasa/cli/project_templates/calm/actions/list_contacts.py +22 -0
  39. rasa/cli/project_templates/calm/actions/remove_contact.py +35 -0
  40. rasa/cli/project_templates/calm/config.yml +12 -0
  41. rasa/cli/project_templates/calm/credentials.yml +33 -0
  42. rasa/cli/project_templates/calm/data/flows/add_contact.yml +31 -0
  43. rasa/cli/project_templates/calm/data/flows/list_contacts.yml +14 -0
  44. rasa/cli/project_templates/calm/data/flows/remove_contact.yml +29 -0
  45. rasa/cli/project_templates/calm/db/contacts.json +10 -0
  46. rasa/cli/project_templates/calm/domain/add_contact.yml +33 -0
  47. rasa/cli/project_templates/calm/domain/list_contacts.yml +14 -0
  48. rasa/cli/project_templates/calm/domain/remove_contact.yml +31 -0
  49. rasa/cli/project_templates/calm/domain/shared.yml +5 -0
  50. rasa/cli/project_templates/calm/e2e_tests/cancelations/user_cancels_during_a_correction.yml +16 -0
  51. rasa/cli/project_templates/calm/e2e_tests/cancelations/user_changes_mind_on_a_whim.yml +7 -0
  52. rasa/cli/project_templates/calm/e2e_tests/corrections/user_corrects_contact_handle.yml +20 -0
  53. rasa/cli/project_templates/calm/e2e_tests/corrections/user_corrects_contact_name.yml +19 -0
  54. rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_adds_contact_to_their_list.yml +15 -0
  55. rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_lists_contacts.yml +5 -0
  56. rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_removes_contact.yml +11 -0
  57. rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_removes_contact_from_list.yml +12 -0
  58. rasa/cli/project_templates/calm/endpoints.yml +45 -0
  59. rasa/cli/project_templates/default/actions/__init__.py +0 -0
  60. rasa/cli/project_templates/default/actions/actions.py +27 -0
  61. rasa/cli/project_templates/default/config.yml +44 -0
  62. rasa/cli/project_templates/default/credentials.yml +33 -0
  63. rasa/cli/project_templates/default/data/nlu.yml +91 -0
  64. rasa/cli/project_templates/default/data/rules.yml +13 -0
  65. rasa/cli/project_templates/default/data/stories.yml +30 -0
  66. rasa/cli/project_templates/default/domain.yml +34 -0
  67. rasa/cli/project_templates/default/endpoints.yml +42 -0
  68. rasa/cli/project_templates/default/tests/test_stories.yml +91 -0
  69. rasa/cli/project_templates/tutorial/actions.py +22 -0
  70. rasa/cli/project_templates/tutorial/config.yml +11 -0
  71. rasa/cli/project_templates/tutorial/credentials.yml +33 -0
  72. rasa/cli/project_templates/tutorial/data/flows.yml +8 -0
  73. rasa/cli/project_templates/tutorial/domain.yml +17 -0
  74. rasa/cli/project_templates/tutorial/endpoints.yml +45 -0
  75. rasa/cli/run.py +136 -0
  76. rasa/cli/scaffold.py +268 -0
  77. rasa/cli/shell.py +141 -0
  78. rasa/cli/studio/__init__.py +0 -0
  79. rasa/cli/studio/download.py +51 -0
  80. rasa/cli/studio/studio.py +110 -0
  81. rasa/cli/studio/train.py +59 -0
  82. rasa/cli/studio/upload.py +85 -0
  83. rasa/cli/telemetry.py +90 -0
  84. rasa/cli/test.py +280 -0
  85. rasa/cli/train.py +260 -0
  86. rasa/cli/utils.py +453 -0
  87. rasa/cli/visualize.py +40 -0
  88. rasa/cli/x.py +205 -0
  89. rasa/constants.py +37 -0
  90. rasa/core/__init__.py +17 -0
  91. rasa/core/actions/__init__.py +0 -0
  92. rasa/core/actions/action.py +1450 -0
  93. rasa/core/actions/action_clean_stack.py +59 -0
  94. rasa/core/actions/action_run_slot_rejections.py +207 -0
  95. rasa/core/actions/action_trigger_chitchat.py +31 -0
  96. rasa/core/actions/action_trigger_flow.py +109 -0
  97. rasa/core/actions/action_trigger_search.py +31 -0
  98. rasa/core/actions/constants.py +2 -0
  99. rasa/core/actions/forms.py +737 -0
  100. rasa/core/actions/loops.py +111 -0
  101. rasa/core/actions/two_stage_fallback.py +186 -0
  102. rasa/core/agent.py +557 -0
  103. rasa/core/auth_retry_tracker_store.py +122 -0
  104. rasa/core/brokers/__init__.py +0 -0
  105. rasa/core/brokers/broker.py +126 -0
  106. rasa/core/brokers/file.py +58 -0
  107. rasa/core/brokers/kafka.py +322 -0
  108. rasa/core/brokers/pika.py +387 -0
  109. rasa/core/brokers/sql.py +86 -0
  110. rasa/core/channels/__init__.py +55 -0
  111. rasa/core/channels/audiocodes.py +463 -0
  112. rasa/core/channels/botframework.py +339 -0
  113. rasa/core/channels/callback.py +85 -0
  114. rasa/core/channels/channel.py +419 -0
  115. rasa/core/channels/console.py +243 -0
  116. rasa/core/channels/development_inspector.py +93 -0
  117. rasa/core/channels/facebook.py +422 -0
  118. rasa/core/channels/hangouts.py +335 -0
  119. rasa/core/channels/inspector/.eslintrc.cjs +25 -0
  120. rasa/core/channels/inspector/.gitignore +23 -0
  121. rasa/core/channels/inspector/README.md +54 -0
  122. rasa/core/channels/inspector/assets/favicon.ico +0 -0
  123. rasa/core/channels/inspector/assets/rasa-chat.js +2 -0
  124. rasa/core/channels/inspector/custom.d.ts +3 -0
  125. rasa/core/channels/inspector/dist/assets/arc-5623b6dc.js +1 -0
  126. rasa/core/channels/inspector/dist/assets/array-9f3ba611.js +1 -0
  127. rasa/core/channels/inspector/dist/assets/c4Diagram-d0fbc5ce-685c106a.js +10 -0
  128. rasa/core/channels/inspector/dist/assets/classDiagram-936ed81e-8cbed007.js +2 -0
  129. rasa/core/channels/inspector/dist/assets/classDiagram-v2-c3cb15f1-5889cf12.js +2 -0
  130. rasa/core/channels/inspector/dist/assets/createText-62fc7601-24c249d7.js +7 -0
  131. rasa/core/channels/inspector/dist/assets/edges-f2ad444c-7dd06a75.js +4 -0
  132. rasa/core/channels/inspector/dist/assets/erDiagram-9d236eb7-62c1e54c.js +51 -0
  133. rasa/core/channels/inspector/dist/assets/flowDb-1972c806-ce49b86f.js +6 -0
  134. rasa/core/channels/inspector/dist/assets/flowDiagram-7ea5b25a-4067e48f.js +4 -0
  135. rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-85583a23.js +1 -0
  136. rasa/core/channels/inspector/dist/assets/flowchart-elk-definition-abe16c3d-59fe4051.js +139 -0
  137. rasa/core/channels/inspector/dist/assets/ganttDiagram-9b5ea136-47e3a43b.js +266 -0
  138. rasa/core/channels/inspector/dist/assets/gitGraphDiagram-99d0ae7c-5a2ac0d9.js +70 -0
  139. rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-128cfa44.ttf +0 -0
  140. rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-21dbcb97.woff +0 -0
  141. rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-222b5e26.svg +329 -0
  142. rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-9ad89b2a.woff2 +0 -0
  143. rasa/core/channels/inspector/dist/assets/index-268a75c0.js +1040 -0
  144. rasa/core/channels/inspector/dist/assets/index-2c4b9a3b-dfb8efc4.js +1 -0
  145. rasa/core/channels/inspector/dist/assets/index-3ee28881.css +1 -0
  146. rasa/core/channels/inspector/dist/assets/infoDiagram-736b4530-b0c470f2.js +7 -0
  147. rasa/core/channels/inspector/dist/assets/init-77b53fdd.js +1 -0
  148. rasa/core/channels/inspector/dist/assets/journeyDiagram-df861f2b-2edb829a.js +139 -0
  149. rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-60c05ee4.woff +0 -0
  150. rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-8335d9b8.svg +438 -0
  151. rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-9cc39c75.ttf +0 -0
  152. rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-ead13ccf.woff2 +0 -0
  153. rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-16705655.woff2 +0 -0
  154. rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-5aeb07f9.woff +0 -0
  155. rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-9c459044.ttf +0 -0
  156. rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-9e2898a4.svg +435 -0
  157. rasa/core/channels/inspector/dist/assets/layout-b6873d69.js +1 -0
  158. rasa/core/channels/inspector/dist/assets/line-1efc5781.js +1 -0
  159. rasa/core/channels/inspector/dist/assets/linear-661e9b94.js +1 -0
  160. rasa/core/channels/inspector/dist/assets/mindmap-definition-beec6740-2d2e727f.js +109 -0
  161. rasa/core/channels/inspector/dist/assets/ordinal-ba9b4969.js +1 -0
  162. rasa/core/channels/inspector/dist/assets/path-53f90ab3.js +1 -0
  163. rasa/core/channels/inspector/dist/assets/pieDiagram-dbbf0591-9d3ea93d.js +35 -0
  164. rasa/core/channels/inspector/dist/assets/quadrantDiagram-4d7f4fd6-06a178a2.js +7 -0
  165. rasa/core/channels/inspector/dist/assets/requirementDiagram-6fc4c22a-0bfedffc.js +52 -0
  166. rasa/core/channels/inspector/dist/assets/sankeyDiagram-8f13d901-d76d0a04.js +8 -0
  167. rasa/core/channels/inspector/dist/assets/sequenceDiagram-b655622a-37bb4341.js +122 -0
  168. rasa/core/channels/inspector/dist/assets/stateDiagram-59f0c015-f52f7f57.js +1 -0
  169. rasa/core/channels/inspector/dist/assets/stateDiagram-v2-2b26beab-4a986a20.js +1 -0
  170. rasa/core/channels/inspector/dist/assets/styles-080da4f6-7dd9ae12.js +110 -0
  171. rasa/core/channels/inspector/dist/assets/styles-3dcbcfbf-46e1ca14.js +159 -0
  172. rasa/core/channels/inspector/dist/assets/styles-9c745c82-4a97439a.js +207 -0
  173. rasa/core/channels/inspector/dist/assets/svgDrawCommon-4835440b-823917a3.js +1 -0
  174. rasa/core/channels/inspector/dist/assets/timeline-definition-5b62e21b-9ea72896.js +61 -0
  175. rasa/core/channels/inspector/dist/assets/xychartDiagram-2b33534f-b631a8b6.js +7 -0
  176. rasa/core/channels/inspector/dist/index.html +39 -0
  177. rasa/core/channels/inspector/index.html +37 -0
  178. rasa/core/channels/inspector/jest.config.ts +13 -0
  179. rasa/core/channels/inspector/package.json +48 -0
  180. rasa/core/channels/inspector/setupTests.ts +2 -0
  181. rasa/core/channels/inspector/src/App.tsx +170 -0
  182. rasa/core/channels/inspector/src/components/DiagramFlow.tsx +97 -0
  183. rasa/core/channels/inspector/src/components/DialogueInformation.tsx +187 -0
  184. rasa/core/channels/inspector/src/components/DialogueStack.tsx +151 -0
  185. rasa/core/channels/inspector/src/components/ExpandIcon.tsx +16 -0
  186. rasa/core/channels/inspector/src/components/FullscreenButton.tsx +45 -0
  187. rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +19 -0
  188. rasa/core/channels/inspector/src/components/NoActiveFlow.tsx +21 -0
  189. rasa/core/channels/inspector/src/components/RasaLogo.tsx +32 -0
  190. rasa/core/channels/inspector/src/components/SaraDiagrams.tsx +39 -0
  191. rasa/core/channels/inspector/src/components/Slots.tsx +91 -0
  192. rasa/core/channels/inspector/src/components/Welcome.tsx +54 -0
  193. rasa/core/channels/inspector/src/helpers/formatters.test.ts +385 -0
  194. rasa/core/channels/inspector/src/helpers/formatters.ts +239 -0
  195. rasa/core/channels/inspector/src/helpers/utils.ts +42 -0
  196. rasa/core/channels/inspector/src/main.tsx +13 -0
  197. rasa/core/channels/inspector/src/theme/Button/Button.ts +29 -0
  198. rasa/core/channels/inspector/src/theme/Heading/Heading.ts +31 -0
  199. rasa/core/channels/inspector/src/theme/Input/Input.ts +27 -0
  200. rasa/core/channels/inspector/src/theme/Link/Link.ts +10 -0
  201. rasa/core/channels/inspector/src/theme/Modal/Modal.ts +47 -0
  202. rasa/core/channels/inspector/src/theme/Table/Table.tsx +38 -0
  203. rasa/core/channels/inspector/src/theme/Tooltip/Tooltip.ts +12 -0
  204. rasa/core/channels/inspector/src/theme/base/breakpoints.ts +8 -0
  205. rasa/core/channels/inspector/src/theme/base/colors.ts +88 -0
  206. rasa/core/channels/inspector/src/theme/base/fonts/fontFaces.css +29 -0
  207. rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.eot +0 -0
  208. rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.svg +329 -0
  209. rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.ttf +0 -0
  210. rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.woff +0 -0
  211. rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.woff2 +0 -0
  212. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.eot +0 -0
  213. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.svg +438 -0
  214. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.ttf +0 -0
  215. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.woff +0 -0
  216. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.woff2 +0 -0
  217. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.eot +0 -0
  218. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.svg +435 -0
  219. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.ttf +0 -0
  220. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.woff +0 -0
  221. rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.woff2 +0 -0
  222. rasa/core/channels/inspector/src/theme/base/radii.ts +9 -0
  223. rasa/core/channels/inspector/src/theme/base/shadows.ts +7 -0
  224. rasa/core/channels/inspector/src/theme/base/sizes.ts +7 -0
  225. rasa/core/channels/inspector/src/theme/base/space.ts +15 -0
  226. rasa/core/channels/inspector/src/theme/base/styles.ts +13 -0
  227. rasa/core/channels/inspector/src/theme/base/typography.ts +24 -0
  228. rasa/core/channels/inspector/src/theme/base/zIndices.ts +19 -0
  229. rasa/core/channels/inspector/src/theme/index.ts +101 -0
  230. rasa/core/channels/inspector/src/types.ts +64 -0
  231. rasa/core/channels/inspector/src/vite-env.d.ts +1 -0
  232. rasa/core/channels/inspector/tests/__mocks__/fileMock.ts +1 -0
  233. rasa/core/channels/inspector/tests/__mocks__/matchMedia.ts +16 -0
  234. rasa/core/channels/inspector/tests/__mocks__/styleMock.ts +1 -0
  235. rasa/core/channels/inspector/tests/renderWithProviders.tsx +14 -0
  236. rasa/core/channels/inspector/tsconfig.json +26 -0
  237. rasa/core/channels/inspector/tsconfig.node.json +10 -0
  238. rasa/core/channels/inspector/vite.config.ts +8 -0
  239. rasa/core/channels/inspector/yarn.lock +6156 -0
  240. rasa/core/channels/mattermost.py +229 -0
  241. rasa/core/channels/rasa_chat.py +126 -0
  242. rasa/core/channels/rest.py +210 -0
  243. rasa/core/channels/rocketchat.py +175 -0
  244. rasa/core/channels/slack.py +620 -0
  245. rasa/core/channels/socketio.py +274 -0
  246. rasa/core/channels/telegram.py +298 -0
  247. rasa/core/channels/twilio.py +169 -0
  248. rasa/core/channels/twilio_voice.py +367 -0
  249. rasa/core/channels/vier_cvg.py +374 -0
  250. rasa/core/channels/webexteams.py +135 -0
  251. rasa/core/concurrent_lock_store.py +210 -0
  252. rasa/core/constants.py +107 -0
  253. rasa/core/evaluation/__init__.py +0 -0
  254. rasa/core/evaluation/marker.py +267 -0
  255. rasa/core/evaluation/marker_base.py +925 -0
  256. rasa/core/evaluation/marker_stats.py +294 -0
  257. rasa/core/evaluation/marker_tracker_loader.py +103 -0
  258. rasa/core/exceptions.py +29 -0
  259. rasa/core/exporter.py +284 -0
  260. rasa/core/featurizers/__init__.py +0 -0
  261. rasa/core/featurizers/precomputation.py +410 -0
  262. rasa/core/featurizers/single_state_featurizer.py +402 -0
  263. rasa/core/featurizers/tracker_featurizers.py +1172 -0
  264. rasa/core/http_interpreter.py +89 -0
  265. rasa/core/information_retrieval/__init__.py +0 -0
  266. rasa/core/information_retrieval/faiss.py +116 -0
  267. rasa/core/information_retrieval/information_retrieval.py +72 -0
  268. rasa/core/information_retrieval/milvus.py +59 -0
  269. rasa/core/information_retrieval/qdrant.py +102 -0
  270. rasa/core/jobs.py +63 -0
  271. rasa/core/lock.py +139 -0
  272. rasa/core/lock_store.py +344 -0
  273. rasa/core/migrate.py +404 -0
  274. rasa/core/nlg/__init__.py +3 -0
  275. rasa/core/nlg/callback.py +147 -0
  276. rasa/core/nlg/contextual_response_rephraser.py +270 -0
  277. rasa/core/nlg/generator.py +230 -0
  278. rasa/core/nlg/interpolator.py +143 -0
  279. rasa/core/nlg/response.py +155 -0
  280. rasa/core/nlg/summarize.py +69 -0
  281. rasa/core/policies/__init__.py +0 -0
  282. rasa/core/policies/ensemble.py +329 -0
  283. rasa/core/policies/enterprise_search_policy.py +717 -0
  284. rasa/core/policies/enterprise_search_prompt_template.jinja2 +62 -0
  285. rasa/core/policies/flow_policy.py +205 -0
  286. rasa/core/policies/flows/__init__.py +0 -0
  287. rasa/core/policies/flows/flow_exceptions.py +44 -0
  288. rasa/core/policies/flows/flow_executor.py +582 -0
  289. rasa/core/policies/flows/flow_step_result.py +43 -0
  290. rasa/core/policies/intentless_policy.py +924 -0
  291. rasa/core/policies/intentless_prompt_template.jinja2 +22 -0
  292. rasa/core/policies/memoization.py +538 -0
  293. rasa/core/policies/policy.py +716 -0
  294. rasa/core/policies/rule_policy.py +1276 -0
  295. rasa/core/policies/ted_policy.py +2146 -0
  296. rasa/core/policies/unexpected_intent_policy.py +1015 -0
  297. rasa/core/processor.py +1331 -0
  298. rasa/core/run.py +315 -0
  299. rasa/core/secrets_manager/__init__.py +0 -0
  300. rasa/core/secrets_manager/constants.py +32 -0
  301. rasa/core/secrets_manager/endpoints.py +391 -0
  302. rasa/core/secrets_manager/factory.py +233 -0
  303. rasa/core/secrets_manager/secret_manager.py +262 -0
  304. rasa/core/secrets_manager/vault.py +576 -0
  305. rasa/core/test.py +1337 -0
  306. rasa/core/tracker_store.py +1664 -0
  307. rasa/core/train.py +107 -0
  308. rasa/core/training/__init__.py +89 -0
  309. rasa/core/training/converters/__init__.py +0 -0
  310. rasa/core/training/converters/responses_prefix_converter.py +119 -0
  311. rasa/core/training/interactive.py +1742 -0
  312. rasa/core/training/story_conflict.py +381 -0
  313. rasa/core/training/training.py +93 -0
  314. rasa/core/utils.py +344 -0
  315. rasa/core/visualize.py +70 -0
  316. rasa/dialogue_understanding/__init__.py +0 -0
  317. rasa/dialogue_understanding/coexistence/__init__.py +0 -0
  318. rasa/dialogue_understanding/coexistence/constants.py +4 -0
  319. rasa/dialogue_understanding/coexistence/intent_based_router.py +189 -0
  320. rasa/dialogue_understanding/coexistence/llm_based_router.py +261 -0
  321. rasa/dialogue_understanding/coexistence/router_template.jinja2 +12 -0
  322. rasa/dialogue_understanding/commands/__init__.py +45 -0
  323. rasa/dialogue_understanding/commands/can_not_handle_command.py +61 -0
  324. rasa/dialogue_understanding/commands/cancel_flow_command.py +116 -0
  325. rasa/dialogue_understanding/commands/chit_chat_answer_command.py +48 -0
  326. rasa/dialogue_understanding/commands/clarify_command.py +77 -0
  327. rasa/dialogue_understanding/commands/command.py +85 -0
  328. rasa/dialogue_understanding/commands/correct_slots_command.py +288 -0
  329. rasa/dialogue_understanding/commands/error_command.py +67 -0
  330. rasa/dialogue_understanding/commands/free_form_answer_command.py +9 -0
  331. rasa/dialogue_understanding/commands/handle_code_change_command.py +64 -0
  332. rasa/dialogue_understanding/commands/human_handoff_command.py +57 -0
  333. rasa/dialogue_understanding/commands/knowledge_answer_command.py +48 -0
  334. rasa/dialogue_understanding/commands/noop_command.py +45 -0
  335. rasa/dialogue_understanding/commands/set_slot_command.py +125 -0
  336. rasa/dialogue_understanding/commands/skip_question_command.py +66 -0
  337. rasa/dialogue_understanding/commands/start_flow_command.py +98 -0
  338. rasa/dialogue_understanding/generator/__init__.py +6 -0
  339. rasa/dialogue_understanding/generator/command_generator.py +257 -0
  340. rasa/dialogue_understanding/generator/command_prompt_template.jinja2 +57 -0
  341. rasa/dialogue_understanding/generator/flow_document_template.jinja2 +4 -0
  342. rasa/dialogue_understanding/generator/flow_retrieval.py +410 -0
  343. rasa/dialogue_understanding/generator/llm_command_generator.py +637 -0
  344. rasa/dialogue_understanding/generator/nlu_command_adapter.py +157 -0
  345. rasa/dialogue_understanding/patterns/__init__.py +0 -0
  346. rasa/dialogue_understanding/patterns/cancel.py +111 -0
  347. rasa/dialogue_understanding/patterns/cannot_handle.py +43 -0
  348. rasa/dialogue_understanding/patterns/chitchat.py +37 -0
  349. rasa/dialogue_understanding/patterns/clarify.py +97 -0
  350. rasa/dialogue_understanding/patterns/code_change.py +41 -0
  351. rasa/dialogue_understanding/patterns/collect_information.py +90 -0
  352. rasa/dialogue_understanding/patterns/completed.py +40 -0
  353. rasa/dialogue_understanding/patterns/continue_interrupted.py +42 -0
  354. rasa/dialogue_understanding/patterns/correction.py +278 -0
  355. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +243 -0
  356. rasa/dialogue_understanding/patterns/human_handoff.py +37 -0
  357. rasa/dialogue_understanding/patterns/internal_error.py +47 -0
  358. rasa/dialogue_understanding/patterns/search.py +37 -0
  359. rasa/dialogue_understanding/patterns/skip_question.py +38 -0
  360. rasa/dialogue_understanding/processor/__init__.py +0 -0
  361. rasa/dialogue_understanding/processor/command_processor.py +578 -0
  362. rasa/dialogue_understanding/processor/command_processor_component.py +39 -0
  363. rasa/dialogue_understanding/stack/__init__.py +0 -0
  364. rasa/dialogue_understanding/stack/dialogue_stack.py +178 -0
  365. rasa/dialogue_understanding/stack/frames/__init__.py +19 -0
  366. rasa/dialogue_understanding/stack/frames/chit_chat_frame.py +27 -0
  367. rasa/dialogue_understanding/stack/frames/dialogue_stack_frame.py +137 -0
  368. rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +157 -0
  369. rasa/dialogue_understanding/stack/frames/pattern_frame.py +10 -0
  370. rasa/dialogue_understanding/stack/frames/search_frame.py +27 -0
  371. rasa/dialogue_understanding/stack/utils.py +211 -0
  372. rasa/e2e_test/__init__.py +0 -0
  373. rasa/e2e_test/constants.py +10 -0
  374. rasa/e2e_test/e2e_test_case.py +322 -0
  375. rasa/e2e_test/e2e_test_result.py +34 -0
  376. rasa/e2e_test/e2e_test_runner.py +659 -0
  377. rasa/e2e_test/e2e_test_schema.yml +67 -0
  378. rasa/engine/__init__.py +0 -0
  379. rasa/engine/caching.py +464 -0
  380. rasa/engine/constants.py +17 -0
  381. rasa/engine/exceptions.py +14 -0
  382. rasa/engine/graph.py +625 -0
  383. rasa/engine/loader.py +36 -0
  384. rasa/engine/recipes/__init__.py +0 -0
  385. rasa/engine/recipes/config_files/default_config.yml +44 -0
  386. rasa/engine/recipes/default_components.py +99 -0
  387. rasa/engine/recipes/default_recipe.py +1252 -0
  388. rasa/engine/recipes/graph_recipe.py +79 -0
  389. rasa/engine/recipes/recipe.py +93 -0
  390. rasa/engine/runner/__init__.py +0 -0
  391. rasa/engine/runner/dask.py +256 -0
  392. rasa/engine/runner/interface.py +49 -0
  393. rasa/engine/storage/__init__.py +0 -0
  394. rasa/engine/storage/local_model_storage.py +248 -0
  395. rasa/engine/storage/resource.py +110 -0
  396. rasa/engine/storage/storage.py +203 -0
  397. rasa/engine/training/__init__.py +0 -0
  398. rasa/engine/training/components.py +176 -0
  399. rasa/engine/training/fingerprinting.py +64 -0
  400. rasa/engine/training/graph_trainer.py +256 -0
  401. rasa/engine/training/hooks.py +164 -0
  402. rasa/engine/validation.py +839 -0
  403. rasa/env.py +5 -0
  404. rasa/exceptions.py +69 -0
  405. rasa/graph_components/__init__.py +0 -0
  406. rasa/graph_components/converters/__init__.py +0 -0
  407. rasa/graph_components/converters/nlu_message_converter.py +48 -0
  408. rasa/graph_components/providers/__init__.py +0 -0
  409. rasa/graph_components/providers/domain_for_core_training_provider.py +87 -0
  410. rasa/graph_components/providers/domain_provider.py +71 -0
  411. rasa/graph_components/providers/flows_provider.py +74 -0
  412. rasa/graph_components/providers/forms_provider.py +44 -0
  413. rasa/graph_components/providers/nlu_training_data_provider.py +56 -0
  414. rasa/graph_components/providers/responses_provider.py +44 -0
  415. rasa/graph_components/providers/rule_only_provider.py +49 -0
  416. rasa/graph_components/providers/story_graph_provider.py +43 -0
  417. rasa/graph_components/providers/training_tracker_provider.py +55 -0
  418. rasa/graph_components/validators/__init__.py +0 -0
  419. rasa/graph_components/validators/default_recipe_validator.py +552 -0
  420. rasa/graph_components/validators/finetuning_validator.py +302 -0
  421. rasa/hooks.py +113 -0
  422. rasa/jupyter.py +63 -0
  423. rasa/keys +1 -0
  424. rasa/markers/__init__.py +0 -0
  425. rasa/markers/marker.py +269 -0
  426. rasa/markers/marker_base.py +828 -0
  427. rasa/markers/upload.py +74 -0
  428. rasa/markers/validate.py +21 -0
  429. rasa/model.py +118 -0
  430. rasa/model_testing.py +457 -0
  431. rasa/model_training.py +535 -0
  432. rasa/nlu/__init__.py +7 -0
  433. rasa/nlu/classifiers/__init__.py +3 -0
  434. rasa/nlu/classifiers/classifier.py +5 -0
  435. rasa/nlu/classifiers/diet_classifier.py +1874 -0
  436. rasa/nlu/classifiers/fallback_classifier.py +192 -0
  437. rasa/nlu/classifiers/keyword_intent_classifier.py +188 -0
  438. rasa/nlu/classifiers/llm_intent_classifier.py +519 -0
  439. rasa/nlu/classifiers/logistic_regression_classifier.py +240 -0
  440. rasa/nlu/classifiers/mitie_intent_classifier.py +156 -0
  441. rasa/nlu/classifiers/regex_message_handler.py +56 -0
  442. rasa/nlu/classifiers/sklearn_intent_classifier.py +309 -0
  443. rasa/nlu/constants.py +77 -0
  444. rasa/nlu/convert.py +40 -0
  445. rasa/nlu/emulators/__init__.py +0 -0
  446. rasa/nlu/emulators/dialogflow.py +55 -0
  447. rasa/nlu/emulators/emulator.py +49 -0
  448. rasa/nlu/emulators/luis.py +86 -0
  449. rasa/nlu/emulators/no_emulator.py +10 -0
  450. rasa/nlu/emulators/wit.py +56 -0
  451. rasa/nlu/extractors/__init__.py +0 -0
  452. rasa/nlu/extractors/crf_entity_extractor.py +672 -0
  453. rasa/nlu/extractors/duckling_entity_extractor.py +206 -0
  454. rasa/nlu/extractors/entity_synonyms.py +178 -0
  455. rasa/nlu/extractors/extractor.py +470 -0
  456. rasa/nlu/extractors/mitie_entity_extractor.py +293 -0
  457. rasa/nlu/extractors/regex_entity_extractor.py +220 -0
  458. rasa/nlu/extractors/spacy_entity_extractor.py +95 -0
  459. rasa/nlu/featurizers/__init__.py +0 -0
  460. rasa/nlu/featurizers/dense_featurizer/__init__.py +0 -0
  461. rasa/nlu/featurizers/dense_featurizer/convert_featurizer.py +449 -0
  462. rasa/nlu/featurizers/dense_featurizer/dense_featurizer.py +57 -0
  463. rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py +772 -0
  464. rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +170 -0
  465. rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +132 -0
  466. rasa/nlu/featurizers/featurizer.py +89 -0
  467. rasa/nlu/featurizers/sparse_featurizer/__init__.py +0 -0
  468. rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +840 -0
  469. rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +539 -0
  470. rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +269 -0
  471. rasa/nlu/featurizers/sparse_featurizer/sparse_featurizer.py +9 -0
  472. rasa/nlu/model.py +24 -0
  473. rasa/nlu/persistor.py +240 -0
  474. rasa/nlu/run.py +27 -0
  475. rasa/nlu/selectors/__init__.py +0 -0
  476. rasa/nlu/selectors/response_selector.py +990 -0
  477. rasa/nlu/test.py +1943 -0
  478. rasa/nlu/tokenizers/__init__.py +0 -0
  479. rasa/nlu/tokenizers/jieba_tokenizer.py +148 -0
  480. rasa/nlu/tokenizers/mitie_tokenizer.py +75 -0
  481. rasa/nlu/tokenizers/spacy_tokenizer.py +72 -0
  482. rasa/nlu/tokenizers/tokenizer.py +239 -0
  483. rasa/nlu/tokenizers/whitespace_tokenizer.py +106 -0
  484. rasa/nlu/utils/__init__.py +35 -0
  485. rasa/nlu/utils/bilou_utils.py +462 -0
  486. rasa/nlu/utils/hugging_face/__init__.py +0 -0
  487. rasa/nlu/utils/hugging_face/registry.py +108 -0
  488. rasa/nlu/utils/hugging_face/transformers_pre_post_processors.py +311 -0
  489. rasa/nlu/utils/mitie_utils.py +113 -0
  490. rasa/nlu/utils/pattern_utils.py +168 -0
  491. rasa/nlu/utils/spacy_utils.py +312 -0
  492. rasa/plugin.py +90 -0
  493. rasa/server.py +1536 -0
  494. rasa/shared/__init__.py +0 -0
  495. rasa/shared/constants.py +181 -0
  496. rasa/shared/core/__init__.py +0 -0
  497. rasa/shared/core/constants.py +168 -0
  498. rasa/shared/core/conversation.py +46 -0
  499. rasa/shared/core/domain.py +2106 -0
  500. rasa/shared/core/events.py +2507 -0
  501. rasa/shared/core/flows/__init__.py +7 -0
  502. rasa/shared/core/flows/flow.py +353 -0
  503. rasa/shared/core/flows/flow_step.py +146 -0
  504. rasa/shared/core/flows/flow_step_links.py +319 -0
  505. rasa/shared/core/flows/flow_step_sequence.py +70 -0
  506. rasa/shared/core/flows/flows_list.py +211 -0
  507. rasa/shared/core/flows/flows_yaml_schema.json +217 -0
  508. rasa/shared/core/flows/nlu_trigger.py +117 -0
  509. rasa/shared/core/flows/steps/__init__.py +24 -0
  510. rasa/shared/core/flows/steps/action.py +51 -0
  511. rasa/shared/core/flows/steps/call.py +64 -0
  512. rasa/shared/core/flows/steps/collect.py +112 -0
  513. rasa/shared/core/flows/steps/constants.py +5 -0
  514. rasa/shared/core/flows/steps/continuation.py +36 -0
  515. rasa/shared/core/flows/steps/end.py +22 -0
  516. rasa/shared/core/flows/steps/internal.py +44 -0
  517. rasa/shared/core/flows/steps/link.py +51 -0
  518. rasa/shared/core/flows/steps/no_operation.py +48 -0
  519. rasa/shared/core/flows/steps/set_slots.py +50 -0
  520. rasa/shared/core/flows/steps/start.py +30 -0
  521. rasa/shared/core/flows/validation.py +527 -0
  522. rasa/shared/core/flows/yaml_flows_io.py +278 -0
  523. rasa/shared/core/generator.py +907 -0
  524. rasa/shared/core/slot_mappings.py +235 -0
  525. rasa/shared/core/slots.py +647 -0
  526. rasa/shared/core/trackers.py +1159 -0
  527. rasa/shared/core/training_data/__init__.py +0 -0
  528. rasa/shared/core/training_data/loading.py +90 -0
  529. rasa/shared/core/training_data/story_reader/__init__.py +0 -0
  530. rasa/shared/core/training_data/story_reader/story_reader.py +129 -0
  531. rasa/shared/core/training_data/story_reader/story_step_builder.py +168 -0
  532. rasa/shared/core/training_data/story_reader/yaml_story_reader.py +888 -0
  533. rasa/shared/core/training_data/story_writer/__init__.py +0 -0
  534. rasa/shared/core/training_data/story_writer/story_writer.py +76 -0
  535. rasa/shared/core/training_data/story_writer/yaml_story_writer.py +442 -0
  536. rasa/shared/core/training_data/structures.py +838 -0
  537. rasa/shared/core/training_data/visualization.html +146 -0
  538. rasa/shared/core/training_data/visualization.py +603 -0
  539. rasa/shared/data.py +192 -0
  540. rasa/shared/engine/__init__.py +0 -0
  541. rasa/shared/engine/caching.py +26 -0
  542. rasa/shared/exceptions.py +129 -0
  543. rasa/shared/importers/__init__.py +0 -0
  544. rasa/shared/importers/importer.py +705 -0
  545. rasa/shared/importers/multi_project.py +203 -0
  546. rasa/shared/importers/rasa.py +100 -0
  547. rasa/shared/importers/utils.py +34 -0
  548. rasa/shared/nlu/__init__.py +0 -0
  549. rasa/shared/nlu/constants.py +45 -0
  550. rasa/shared/nlu/interpreter.py +10 -0
  551. rasa/shared/nlu/training_data/__init__.py +0 -0
  552. rasa/shared/nlu/training_data/entities_parser.py +209 -0
  553. rasa/shared/nlu/training_data/features.py +374 -0
  554. rasa/shared/nlu/training_data/formats/__init__.py +10 -0
  555. rasa/shared/nlu/training_data/formats/dialogflow.py +162 -0
  556. rasa/shared/nlu/training_data/formats/luis.py +87 -0
  557. rasa/shared/nlu/training_data/formats/rasa.py +135 -0
  558. rasa/shared/nlu/training_data/formats/rasa_yaml.py +605 -0
  559. rasa/shared/nlu/training_data/formats/readerwriter.py +245 -0
  560. rasa/shared/nlu/training_data/formats/wit.py +52 -0
  561. rasa/shared/nlu/training_data/loading.py +137 -0
  562. rasa/shared/nlu/training_data/lookup_tables_parser.py +30 -0
  563. rasa/shared/nlu/training_data/message.py +477 -0
  564. rasa/shared/nlu/training_data/schemas/__init__.py +0 -0
  565. rasa/shared/nlu/training_data/schemas/data_schema.py +85 -0
  566. rasa/shared/nlu/training_data/schemas/nlu.yml +53 -0
  567. rasa/shared/nlu/training_data/schemas/responses.yml +70 -0
  568. rasa/shared/nlu/training_data/synonyms_parser.py +42 -0
  569. rasa/shared/nlu/training_data/training_data.py +732 -0
  570. rasa/shared/nlu/training_data/util.py +223 -0
  571. rasa/shared/providers/__init__.py +0 -0
  572. rasa/shared/providers/openai/__init__.py +0 -0
  573. rasa/shared/providers/openai/clients.py +43 -0
  574. rasa/shared/providers/openai/session_handler.py +110 -0
  575. rasa/shared/utils/__init__.py +0 -0
  576. rasa/shared/utils/cli.py +72 -0
  577. rasa/shared/utils/common.py +308 -0
  578. rasa/shared/utils/constants.py +1 -0
  579. rasa/shared/utils/io.py +403 -0
  580. rasa/shared/utils/llm.py +405 -0
  581. rasa/shared/utils/pykwalify_extensions.py +26 -0
  582. rasa/shared/utils/schemas/__init__.py +0 -0
  583. rasa/shared/utils/schemas/config.yml +2 -0
  584. rasa/shared/utils/schemas/domain.yml +142 -0
  585. rasa/shared/utils/schemas/events.py +212 -0
  586. rasa/shared/utils/schemas/model_config.yml +46 -0
  587. rasa/shared/utils/schemas/stories.yml +173 -0
  588. rasa/shared/utils/yaml.py +777 -0
  589. rasa/studio/__init__.py +0 -0
  590. rasa/studio/auth.py +252 -0
  591. rasa/studio/config.py +127 -0
  592. rasa/studio/constants.py +16 -0
  593. rasa/studio/data_handler.py +352 -0
  594. rasa/studio/download.py +350 -0
  595. rasa/studio/train.py +136 -0
  596. rasa/studio/upload.py +408 -0
  597. rasa/telemetry.py +1583 -0
  598. rasa/tracing/__init__.py +0 -0
  599. rasa/tracing/config.py +338 -0
  600. rasa/tracing/constants.py +38 -0
  601. rasa/tracing/instrumentation/__init__.py +0 -0
  602. rasa/tracing/instrumentation/attribute_extractors.py +663 -0
  603. rasa/tracing/instrumentation/instrumentation.py +939 -0
  604. rasa/tracing/instrumentation/intentless_policy_instrumentation.py +142 -0
  605. rasa/tracing/instrumentation/metrics.py +206 -0
  606. rasa/tracing/metric_instrument_provider.py +125 -0
  607. rasa/utils/__init__.py +0 -0
  608. rasa/utils/beta.py +83 -0
  609. rasa/utils/cli.py +27 -0
  610. rasa/utils/common.py +635 -0
  611. rasa/utils/converter.py +53 -0
  612. rasa/utils/endpoints.py +303 -0
  613. rasa/utils/io.py +326 -0
  614. rasa/utils/licensing.py +319 -0
  615. rasa/utils/log_utils.py +174 -0
  616. rasa/utils/mapper.py +210 -0
  617. rasa/utils/ml_utils.py +145 -0
  618. rasa/utils/plotting.py +362 -0
  619. rasa/utils/singleton.py +23 -0
  620. rasa/utils/tensorflow/__init__.py +0 -0
  621. rasa/utils/tensorflow/callback.py +112 -0
  622. rasa/utils/tensorflow/constants.py +116 -0
  623. rasa/utils/tensorflow/crf.py +492 -0
  624. rasa/utils/tensorflow/data_generator.py +440 -0
  625. rasa/utils/tensorflow/environment.py +161 -0
  626. rasa/utils/tensorflow/exceptions.py +5 -0
  627. rasa/utils/tensorflow/layers.py +1565 -0
  628. rasa/utils/tensorflow/layers_utils.py +113 -0
  629. rasa/utils/tensorflow/metrics.py +281 -0
  630. rasa/utils/tensorflow/model_data.py +991 -0
  631. rasa/utils/tensorflow/model_data_utils.py +500 -0
  632. rasa/utils/tensorflow/models.py +936 -0
  633. rasa/utils/tensorflow/rasa_layers.py +1094 -0
  634. rasa/utils/tensorflow/transformer.py +640 -0
  635. rasa/utils/tensorflow/types.py +6 -0
  636. rasa/utils/train_utils.py +572 -0
  637. rasa/utils/yaml.py +54 -0
  638. rasa/validator.py +1035 -0
  639. rasa/version.py +3 -0
  640. rasa_pro-3.8.16.dist-info/METADATA +528 -0
  641. rasa_pro-3.8.16.dist-info/NOTICE +5 -0
  642. rasa_pro-3.8.16.dist-info/RECORD +644 -0
  643. rasa_pro-3.8.16.dist-info/WHEEL +4 -0
  644. rasa_pro-3.8.16.dist-info/entry_points.txt +3 -0
rasa/telemetry.py ADDED
@@ -0,0 +1,1583 @@
1
+ import asyncio
2
+ import contextlib
3
+ import hashlib
4
+ import inspect
5
+ import json
6
+ import logging
7
+ import multiprocessing
8
+ import os
9
+ import platform
10
+ import sys
11
+ import textwrap
12
+ import typing
13
+ import uuid
14
+ from collections import defaultdict
15
+ from datetime import datetime
16
+ from functools import wraps
17
+ from pathlib import Path
18
+ from typing import Any, Callable, Dict, List, Optional, Text
19
+
20
+ import importlib_resources
21
+ import requests
22
+ from terminaltables import SingleTable
23
+
24
+ import rasa
25
+ import rasa.anonymization.utils
26
+ import rasa.shared.utils.io
27
+ import rasa.utils.io
28
+ from rasa import model
29
+ from rasa.constants import (
30
+ CONFIG_FILE_TELEMETRY_KEY,
31
+ CONFIG_TELEMETRY_DATE,
32
+ CONFIG_TELEMETRY_ENABLED,
33
+ CONFIG_TELEMETRY_ID,
34
+ )
35
+ from rasa.engine.storage.local_model_storage import LocalModelStorage
36
+ from rasa.shared.constants import DOCS_URL_TELEMETRY, UTTER_ASK_PREFIX
37
+ from rasa.shared.core.flows import Flow
38
+ from rasa.shared.core.flows.steps import (
39
+ CollectInformationFlowStep,
40
+ SetSlotsFlowStep,
41
+ LinkFlowStep,
42
+ CallFlowStep,
43
+ )
44
+ from rasa.shared.exceptions import RasaException
45
+ from rasa.utils import common as rasa_utils
46
+ from rasa.utils.licensing import property_of_active_license, get_license_hash
47
+
48
+ if typing.TYPE_CHECKING:
49
+ from rasa.core.brokers.broker import EventBroker
50
+ from rasa.core.tracker_store import TrackerStore
51
+ from rasa.core.channels.channel import InputChannel
52
+ from rasa.core.agent import Agent
53
+ from rasa.shared.nlu.training_data.training_data import TrainingData
54
+ from rasa.shared.importers.importer import TrainingDataImporter
55
+ from rasa.core.utils import AvailableEndpoints
56
+ from rasa.e2e_test.e2e_test_case import TestCase, Fixture
57
+
58
+ logger = logging.getLogger(__name__)
59
+
60
+ SEGMENT_TRACK_ENDPOINT = "https://api.segment.io/v1/track"
61
+ SEGMENT_IDENTIFY_ENDPOINT = "https://api.segment.io/v1/identify"
62
+ SEGMENT_REQUEST_TIMEOUT = 5 # seconds
63
+
64
+ TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE = "RASA_TELEMETRY_ENABLED"
65
+ TELEMETRY_DEBUG_ENVIRONMENT_VARIABLE = "RASA_TELEMETRY_DEBUG"
66
+ RASA_PRO_CONFIG_FILE_TELEMETRY_KEY = "traits"
67
+
68
+ # the environment variable can be used for local development to set a test key
69
+ # e.g. `RASA_TELEMETRY_WRITE_KEY=12354 rasa train`
70
+ TELEMETRY_WRITE_KEY_ENVIRONMENT_VARIABLE = "RASA_TELEMETRY_WRITE_KEY"
71
+ EXCEPTION_WRITE_KEY_ENVIRONMENT_VARIABLE = "RASA_EXCEPTION_WRITE_KEY"
72
+
73
+ TELEMETRY_ID = "metrics_id"
74
+ TELEMETRY_ENABLED_BY_DEFAULT = True
75
+
76
+ # if one of these environment variables is set, we assume to be running in CI env
77
+ CI_ENVIRONMENT_TELL = [
78
+ "bamboo.buildKey",
79
+ "BUILD_ID",
80
+ "BUILD_NUMBER",
81
+ "BUILDKITE",
82
+ "CI",
83
+ "CIRCLECI",
84
+ "CONTINUOUS_INTEGRATION",
85
+ "GITHUB_ACTIONS",
86
+ "HUDSON_URL",
87
+ "JENKINS_URL",
88
+ "TEAMCITY_VERSION",
89
+ "TRAVIS",
90
+ "CODEBUILD_BUILD_ARN",
91
+ "CODEBUILD_BUILD_ID",
92
+ "CODEBUILD_BATCH_BUILD_IDENTIFIER",
93
+ ]
94
+
95
+ # If updating or creating a new event, remember to update
96
+ # https://rasa.com/docs/rasa/telemetry
97
+ TRAINING_STARTED_EVENT = "Training Started"
98
+ TRAINING_COMPLETED_EVENT = "Training Completed"
99
+ TELEMETRY_DISABLED_EVENT = "Telemetry Disabled"
100
+ TELEMETRY_DATA_SPLIT_EVENT = "Training Data Split"
101
+ TELEMETRY_DATA_VALIDATED_EVENT = "Training Data Validated"
102
+ TELEMETRY_DATA_CONVERTED_EVENT = "Training Data Converted"
103
+ TELEMETRY_TRACKER_EXPORTED_EVENT = "Tracker Exported"
104
+ TELEMETRY_INTERACTIVE_LEARNING_STARTED_EVENT = "Interactive Learning Started"
105
+ TELEMETRY_SERVER_STARTED_EVENT = "Server Started"
106
+ TELEMETRY_PROJECT_CREATED_EVENT = "Project Created"
107
+ TELEMETRY_SHELL_STARTED_EVENT = "Shell Started"
108
+ TELEMETRY_VISUALIZATION_STARTED_EVENT = "Story Visualization Started"
109
+ TELEMETRY_TEST_CORE_EVENT = "Model Core Tested"
110
+ TELEMETRY_TEST_NLU_EVENT = "Model NLU Tested"
111
+ TELEMETRY_MARKERS_EXTRACTION_INITIATED_EVENT = "Markers Extraction Initiated"
112
+ TELEMETRY_MARKERS_EXTRACTED_EVENT = "Markers Extracted"
113
+ TELEMETRY_MARKERS_STATS_COMPUTED_EVENT = "Markers Statistics Computed"
114
+ TELEMETRY_MARKERS_PARSED_COUNT = "Markers Parsed"
115
+
116
+ TELEMETRY_RESPONSE_REPHRASED_EVENT = "Response Rephrased"
117
+ TELEMETRY_INTENTLESS_POLICY_TRAINING_STARTED_EVENT = (
118
+ "Intentless Policy Training Started"
119
+ )
120
+ TELEMETRY_INTENTLESS_POLICY_TRAINING_COMPLETED_EVENT = (
121
+ "Intentless Policy Training Completed"
122
+ )
123
+ TELEMETRY_INTENTLESS_POLICY_PREDICT_EVENT = "Intentless Policy Predicted"
124
+ TELEMETRY_LLM_INTENT_PREDICT_EVENT = "LLM Intent Predicted"
125
+ TELEMETRY_LLM_INTENT_TRAIN_COMPLETED_EVENT = "LLM Intent Training Completed"
126
+ TELEMETRY_E2E_TEST_RUN_STARTED_EVENT = "E2E Test Run Started"
127
+
128
+ # used to calculate the context on the first call and cache it afterwards
129
+ TELEMETRY_CONTEXT = None
130
+
131
+ # constants used for the training started events
132
+ NUM_FLOWS = "num_flows"
133
+ NUM_FLOWS_WITH_NLU_TRIGGER = "num_flows_with_nlu_trigger"
134
+ NUM_FLOWS_WITH_FLOW_GUARDS = "num_flows_with_flow_guards"
135
+ NUM_FLOWS_ALWAYS_INCLUDED_IN_PROMPT = "num_flows_always_included_in_prompt"
136
+ NUM_FLOWS_WITH_NOT_STARTABLE_FLOW_GUARDS = "num_flows_with_not_startable_flow_guards"
137
+ NUM_COLLECT_STEPS = "num_collect_steps"
138
+ NUM_COLLECT_STEPS_WITH_SEPARATE_UTTER = "num_collect_steps_with_separate_utter"
139
+ NUM_COLLECT_STEPS_WITH_REJECTIONS = "num_collect_steps_with_rejections"
140
+ NUM_COLLECT_STEPS_WITH_NOT_RESET_AFTER_FLOW_ENDS = (
141
+ "num_collect_steps_with_not_reset_after_flow_ends"
142
+ )
143
+ NUM_SET_SLOT_STEPS = "num_set_slot_steps"
144
+ MAX_DEPTH_OF_IF_CONSTRUCT = "max_depth_of_if_construct"
145
+ NUM_LINK_STEPS = "num_link_steps"
146
+ NUM_CALL_STEPS = "num_call_steps"
147
+ NUM_SHARED_SLOTS_BETWEEN_FLOWS = "num_shared_slots_between_flows"
148
+ LLM_COMMAND_GENERATOR_MODEL_NAME = "llm_command_generator_model_name"
149
+ LLM_COMMAND_GENERATOR_CUSTOM_PROMPT_USED = "llm_command_generator_custom_prompt_used"
150
+ FLOW_RETRIEVAL_ENABLED = "flow_retrieval_enabled"
151
+ FLOW_RETRIEVAL_EMBEDDING_MODEL_NAME = "flow_retrieval_embedding_model_name"
152
+ TRACING_BACKEND = "tracing_backend"
153
+ METRICS_BACKEND = "metrics_backend"
154
+ VERSION = "version"
155
+
156
+
157
+ def print_telemetry_reporting_info() -> None:
158
+ """Print telemetry information to std out."""
159
+ message = textwrap.dedent(
160
+ f"""
161
+ Rasa Open Source reports anonymous usage telemetry to help improve the product
162
+ for all its users.
163
+
164
+ If you'd like to opt-out, you can use `rasa telemetry disable`.
165
+ To learn more, check out {DOCS_URL_TELEMETRY}."""
166
+ ).strip()
167
+
168
+ table = SingleTable([[message]])
169
+ print(table.table)
170
+
171
+
172
+ def _default_telemetry_configuration(is_enabled: bool) -> Dict[Text, Any]:
173
+ return {
174
+ CONFIG_TELEMETRY_ENABLED: is_enabled,
175
+ CONFIG_TELEMETRY_ID: uuid.uuid4().hex,
176
+ CONFIG_TELEMETRY_DATE: datetime.now(),
177
+ }
178
+
179
+
180
+ def _write_default_telemetry_configuration(
181
+ is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT,
182
+ ) -> bool:
183
+ new_config = _default_telemetry_configuration(is_enabled)
184
+
185
+ keys = [CONFIG_FILE_TELEMETRY_KEY, RASA_PRO_CONFIG_FILE_TELEMETRY_KEY]
186
+
187
+ success = all(
188
+ [rasa_utils.write_global_config_value(key, new_config) for key in keys]
189
+ )
190
+
191
+ # Do not show info if user has enabled/disabled telemetry via env var
192
+ telemetry_environ = os.environ.get(TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE)
193
+ if is_enabled and success and telemetry_environ is None:
194
+ print_telemetry_reporting_info()
195
+
196
+ return success
197
+
198
+
199
+ def _is_telemetry_enabled_in_configuration() -> bool:
200
+ """Read telemetry configuration from the user's Rasa config file in $HOME.
201
+
202
+ Creates a default configuration if no configuration exists.
203
+
204
+ Returns:
205
+ `True`, if telemetry is enabled, `False` otherwise.
206
+ """
207
+ try:
208
+ stored_config = rasa_utils.read_global_config_value(
209
+ CONFIG_FILE_TELEMETRY_KEY, unavailable_ok=False
210
+ )
211
+
212
+ return stored_config[CONFIG_TELEMETRY_ENABLED]
213
+ except ValueError as e:
214
+ logger.debug(f"Could not read telemetry settings from configuration file: {e}")
215
+
216
+ # seems like there is no config, we'll create one and enable telemetry
217
+ success = _write_default_telemetry_configuration()
218
+ # if writing the configuration failed, telemetry will be disabled
219
+ return TELEMETRY_ENABLED_BY_DEFAULT and success
220
+
221
+
222
+ def is_telemetry_enabled() -> bool:
223
+ """Check if telemetry is enabled either in configuration or environment.
224
+
225
+ Returns:
226
+ `True`, if telemetry is enabled, `False` otherwise.
227
+ """
228
+ telemetry_environ = os.environ.get(TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE)
229
+
230
+ if telemetry_environ is not None:
231
+ return telemetry_environ.lower() == "true"
232
+
233
+ try:
234
+ return rasa_utils.read_global_config_value(
235
+ CONFIG_FILE_TELEMETRY_KEY, unavailable_ok=False
236
+ )[CONFIG_TELEMETRY_ENABLED]
237
+ except ValueError:
238
+ return False
239
+
240
+
241
+ def initialize_telemetry() -> bool:
242
+ """Read telemetry configuration from the user's Rasa config file in $HOME.
243
+
244
+ Creates a default configuration if no configuration exists.
245
+
246
+ Returns:
247
+ `True`, if telemetry is enabled, `False` otherwise.
248
+ """
249
+ try:
250
+ # calling this even if the environment variable is set makes sure the
251
+ # configuration is created and there is a telemetry ID
252
+ is_enabled_in_configuration = _is_telemetry_enabled_in_configuration()
253
+
254
+ telemetry_environ = os.environ.get(TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE)
255
+
256
+ if telemetry_environ is None:
257
+ return is_enabled_in_configuration
258
+
259
+ return telemetry_environ.lower() == "true"
260
+ except Exception as e: # skipcq:PYL-W0703
261
+ logger.exception(
262
+ f"Failed to initialize telemetry reporting: {e}."
263
+ f"Telemetry reporting will be disabled."
264
+ )
265
+ return False
266
+
267
+
268
+ def ensure_telemetry_enabled(f: Callable[..., Any]) -> Callable[..., Any]:
269
+ """Function decorator for telemetry functions that ensures telemetry is enabled.
270
+
271
+ WARNING: does not work as a decorator for async generators.
272
+
273
+ Args:
274
+ f: function to call if telemetry is enabled
275
+ Returns:
276
+ Return wrapped function
277
+ """
278
+ # allows us to use the decorator for async generator functions
279
+ if inspect.isasyncgenfunction(f):
280
+
281
+ @wraps(f)
282
+ async def decorated_async_gen(*args: Any, **kwargs: Any) -> Any:
283
+ if is_telemetry_enabled():
284
+ yield f(*args, **kwargs)
285
+
286
+ return decorated_async_gen
287
+
288
+ # allows us to use the decorator for async and non async functions
289
+ if asyncio.iscoroutinefunction(f):
290
+
291
+ @wraps(f)
292
+ async def decorated_coroutine(*args: Any, **kwargs: Any) -> Any:
293
+ if is_telemetry_enabled():
294
+ return await f(*args, **kwargs)
295
+ return None
296
+
297
+ return decorated_coroutine
298
+
299
+ @wraps(f)
300
+ def decorated(*args: Any, **kwargs: Any) -> Any:
301
+ if is_telemetry_enabled():
302
+ return f(*args, **kwargs)
303
+ return None
304
+
305
+ return decorated
306
+
307
+
308
+ def _fetch_write_key(tool: Text, environment_variable: Text) -> Optional[Text]:
309
+ """Read the write key from a tool from our set of keys.
310
+
311
+ Args:
312
+ tool: name of the tool we want to fetch a key for
313
+ environment_variable: name of the environment variable to set the key
314
+ Returns:
315
+ write key, if a key was present.
316
+ """
317
+ import importlib_resources
318
+ from rasa import __name__ as name
319
+
320
+ if os.environ.get(environment_variable):
321
+ # a write key set using the environment variable will always
322
+ # overwrite any key provided as part of the package (`keys` file)
323
+ return os.environ.get(environment_variable)
324
+
325
+ write_key_path = str(importlib_resources.files(name).joinpath("keys"))
326
+
327
+ # noinspection PyBroadException
328
+ try:
329
+ with open(write_key_path) as f:
330
+ return json.load(f).get(tool)
331
+ except Exception: # skipcq:PYL-W0703
332
+ return None
333
+
334
+
335
+ def telemetry_write_key() -> Optional[Text]:
336
+ """Read the Segment write key from the segment key text file.
337
+
338
+ The segment key text file should by present only in wheel/sdist packaged
339
+ versions of Rasa Open Source. This avoids running telemetry locally when
340
+ developing on Rasa or when running CI builds.
341
+
342
+ In local development, this should always return `None` to avoid logging telemetry.
343
+
344
+ Returns:
345
+ Segment write key, if the key file was present.
346
+ """
347
+ return _fetch_write_key("segment", TELEMETRY_WRITE_KEY_ENVIRONMENT_VARIABLE)
348
+
349
+
350
+ def sentry_write_key() -> Optional[Text]:
351
+ """Read the sentry write key from the sentry key text file.
352
+
353
+ Returns:
354
+ Sentry write key, if the key file was present.
355
+ """
356
+ return _fetch_write_key("sentry", EXCEPTION_WRITE_KEY_ENVIRONMENT_VARIABLE)
357
+
358
+
359
+ def _encode_base64(original: Text, encoding: Text = "utf-8") -> Text:
360
+ """Encodes a string as a base64 string.
361
+
362
+ Args:
363
+ original: Text to be encoded.
364
+ encoding: Encoding used to convert text to binary.
365
+
366
+ Returns:
367
+ Encoded text.
368
+ """
369
+ import base64
370
+
371
+ return base64.b64encode(original.encode(encoding)).decode(encoding)
372
+
373
+
374
+ def segment_request_header(write_key: Text) -> Dict[Text, Any]:
375
+ """Use a segment write key to create authentication headers for the segment API.
376
+
377
+ Args:
378
+ write_key: Authentication key for segment.
379
+
380
+ Returns:
381
+ Authentication headers for segment.
382
+ """
383
+ return {
384
+ "Authorization": "Basic {}".format(_encode_base64(write_key + ":")),
385
+ "Content-Type": "application/json",
386
+ }
387
+
388
+
389
+ def segment_request_payload(
390
+ distinct_id: Text,
391
+ event_name: Text,
392
+ properties: Dict[Text, Any],
393
+ context: Dict[Text, Any],
394
+ ) -> Dict[Text, Any]:
395
+ """Compose a valid payload for the segment API.
396
+
397
+ Args:
398
+ distinct_id: Unique telemetry ID.
399
+ event_name: Name of the event.
400
+ properties: Values to report along the event.
401
+ context: Context information about the event.
402
+
403
+ Returns:
404
+ Valid segment payload.
405
+ """
406
+ return {
407
+ "userId": distinct_id,
408
+ "event": event_name,
409
+ "properties": properties,
410
+ "context": context,
411
+ }
412
+
413
+
414
+ def in_continuous_integration() -> bool:
415
+ """Returns `True` if currently running inside a continuous integration context."""
416
+ return any(env in os.environ for env in CI_ENVIRONMENT_TELL)
417
+
418
+
419
+ def _is_telemetry_debug_enabled() -> bool:
420
+ """Check if telemetry debug mode is enabled."""
421
+ return (
422
+ os.environ.get(TELEMETRY_DEBUG_ENVIRONMENT_VARIABLE, "false").lower() == "true"
423
+ )
424
+
425
+
426
+ def print_telemetry_payload(payload: Dict[Text, Any]) -> None:
427
+ """Print a telemetry payload to the commandline.
428
+
429
+ Args:
430
+ payload: payload to be delivered to segment.
431
+ """
432
+ payload_json = json.dumps(payload, indent=2)
433
+ logger.debug(f"Telemetry payload: {payload_json}")
434
+
435
+
436
+ def _get_telemetry_write_key() -> Optional[Text]:
437
+ if os.environ.get(TELEMETRY_WRITE_KEY_ENVIRONMENT_VARIABLE):
438
+ return os.environ.get(TELEMETRY_WRITE_KEY_ENVIRONMENT_VARIABLE)
439
+
440
+ write_key_path = str(importlib_resources.files(rasa.__name__).joinpath("keys"))
441
+
442
+ try:
443
+ with open(write_key_path) as f:
444
+ return json.load(f).get("segment")
445
+ except Exception:
446
+ return None
447
+
448
+
449
+ def _send_event(
450
+ distinct_id: Text,
451
+ event_name: Text,
452
+ properties: Dict[Text, Any],
453
+ context: Dict[Text, Any],
454
+ ) -> None:
455
+ """Report the contents segmentof an event to the /track Segment endpoint.
456
+
457
+ Documentation: https://.com/docs/sources/server/http/
458
+
459
+ Do not call this function from outside telemetry.py! This function does not
460
+ check if telemetry is enabled or not.
461
+
462
+ Args:
463
+ distinct_id: Unique telemetry ID.
464
+ event_name: Name of the event.
465
+ properties: Values to report along the event.
466
+ context: Context information about the event.
467
+ """
468
+ payload = segment_request_payload(distinct_id, event_name, properties, context)
469
+
470
+ _send_request(SEGMENT_TRACK_ENDPOINT, payload)
471
+
472
+
473
+ def _send_request(url: Text, payload: Dict[Text, Any]) -> None:
474
+ """Send a request to the Segment API.
475
+
476
+ Args:
477
+ url: URL of the Segment API endpoint
478
+ payload: payload to send to the Segment API
479
+ """
480
+ if _is_telemetry_debug_enabled():
481
+ print_telemetry_payload(payload)
482
+ return
483
+
484
+ write_key = _get_telemetry_write_key()
485
+ if not write_key:
486
+ # If RASA_TELEMETRY_WRITE_KEY is empty or `None`, telemetry has not
487
+ # been enabled for this build (e.g. because it is running from source)
488
+ logger.debug("Skipping request to external service: telemetry key not set.")
489
+ return
490
+
491
+ headers = rasa.telemetry.segment_request_header(write_key)
492
+
493
+ resp = requests.post(
494
+ url=url,
495
+ headers=headers,
496
+ json=payload,
497
+ timeout=SEGMENT_REQUEST_TIMEOUT,
498
+ )
499
+ # handle different failure cases
500
+ if resp.status_code != 200:
501
+ logger.debug(
502
+ f"Segment telemetry request returned a {resp.status_code} response. "
503
+ f"Body: {resp.text}"
504
+ )
505
+ else:
506
+ data = resp.json()
507
+ if not data.get("success"):
508
+ logger.debug(
509
+ f"Segment telemetry request returned a failure. Response: {data}"
510
+ )
511
+
512
+
513
+ def _hash_directory_path(path: Text) -> Optional[Text]:
514
+ """Create a hash for the directory.
515
+
516
+ Returns:
517
+ hash of the directories path
518
+ """
519
+ full_path = Path(path).absolute()
520
+ return hashlib.sha256(str(full_path).encode("utf-8")).hexdigest()
521
+
522
+
523
+ # noinspection PyBroadException
524
+ def _is_docker() -> bool:
525
+ """Guess if we are running in docker environment.
526
+
527
+ Returns:
528
+ `True` if we are running inside docker, `False` otherwise.
529
+ """
530
+ # first we try to use the env
531
+ try:
532
+ os.stat("/.dockerenv")
533
+ return True
534
+ except Exception: # skipcq:PYL-W0703
535
+ pass
536
+
537
+ # if that didn't work, try to use proc information
538
+ try:
539
+ return "docker" in rasa.shared.utils.io.read_file("/proc/self/cgroup", "utf8")
540
+ except Exception: # skipcq:PYL-W0703
541
+ return False
542
+
543
+
544
+ def with_default_context_fields(
545
+ context: Optional[Dict[Text, Any]] = None
546
+ ) -> Dict[Text, Any]:
547
+ """Return a new context dictionary with default and provided field values merged.
548
+
549
+ The default fields contain only the OS information for now.
550
+
551
+ Args:
552
+ context: Context information about the event.
553
+
554
+ Return:
555
+ A new context.
556
+ """
557
+ context = context or {}
558
+
559
+ return {**_default_context_fields(), **context}
560
+
561
+
562
+ def _default_context_fields() -> Dict[Text, Any]:
563
+ """Return a dictionary that contains the default context values.
564
+
565
+ Return:
566
+ A new context containing information about the runtime environment.
567
+ """
568
+ global TELEMETRY_CONTEXT
569
+
570
+ if not TELEMETRY_CONTEXT:
571
+ # Make sure to update the example in docs/docs/telemetry/telemetry.mdx
572
+ # if you change / add context
573
+ TELEMETRY_CONTEXT = {
574
+ "os": {"name": platform.system(), "version": platform.release()},
575
+ "ci": in_continuous_integration(),
576
+ "project": model.project_fingerprint(),
577
+ "directory": _hash_directory_path(os.getcwd()),
578
+ "python": sys.version.split(" ")[0],
579
+ "rasa_pro": rasa.__version__,
580
+ "cpu": multiprocessing.cpu_count(),
581
+ "docker": _is_docker(),
582
+ "license_hash": get_license_hash(),
583
+ "company": property_of_active_license(
584
+ lambda active_license: active_license.company
585
+ ),
586
+ }
587
+
588
+ # avoid returning the cached dict --> caller could modify the dictionary...
589
+ # usually we would use `lru_cache`, but that doesn't return a dict copy and
590
+ # doesn't work on inner functions, so we need to roll our own caching...
591
+ return TELEMETRY_CONTEXT.copy()
592
+
593
+
594
+ def _track(
595
+ event_name: Text,
596
+ properties: Optional[Dict[Text, Any]] = None,
597
+ context: Optional[Dict[Text, Any]] = None,
598
+ ) -> None:
599
+ """Tracks a telemetry event.
600
+
601
+ It is OK to use this function from outside telemetry.py, but note that it
602
+ is recommended to create a new track_xyz() function for complex telemetry
603
+ events, or events that are generated from many parts of the Rasa Open Source code.
604
+
605
+ Args:
606
+ event_name: Name of the event.
607
+ properties: Dictionary containing the event's properties.
608
+ context: Dictionary containing some context for this event.
609
+ """
610
+ try:
611
+ telemetry_id = get_telemetry_id()
612
+
613
+ if not telemetry_id:
614
+ logger.debug("Will not report telemetry events as no ID was found.")
615
+ return
616
+
617
+ if not properties:
618
+ properties = {}
619
+
620
+ properties[TELEMETRY_ID] = telemetry_id
621
+
622
+ # this is an additional check in case _track() is called
623
+ # from a function that is not decorated with @ensure_telemetry_enabled
624
+ if is_telemetry_enabled():
625
+ _send_event(
626
+ telemetry_id,
627
+ event_name,
628
+ properties,
629
+ with_default_context_fields(context),
630
+ )
631
+ except Exception as e: # skipcq:PYL-W0703
632
+ logger.debug(f"Skipping telemetry reporting: {e}")
633
+
634
+
635
+ def _identify(
636
+ traits: Optional[Dict[Text, Any]] = None,
637
+ context: Optional[Dict[Text, Any]] = None,
638
+ ) -> None:
639
+ """Tracks telemetry traits.
640
+
641
+ It is OK to use this function from outside telemetry.py, but note that it
642
+ is recommended to create a new track_xyz() function for complex telemetry
643
+ traits, or traits that are generated from many parts of the Rasa Pro code.
644
+
645
+ Args:
646
+ traits: Dictionary containing the tracked traits.
647
+ context: Dictionary containing some context for the traits.
648
+ """
649
+ try:
650
+ telemetry_id = get_telemetry_id()
651
+
652
+ if not telemetry_id:
653
+ logger.debug("Will not report telemetry events as no ID was found.")
654
+ return
655
+
656
+ if not traits:
657
+ traits = {}
658
+
659
+ _send_traits(telemetry_id, traits, with_default_context_fields(context))
660
+ except Exception as e:
661
+ logger.debug(f"Skipping telemetry reporting: {e}")
662
+
663
+
664
+ def _send_traits(
665
+ distinct_id: Text,
666
+ traits: Dict[Text, Any],
667
+ context: Dict[Text, Any],
668
+ ) -> None:
669
+ """Report the contents of telemetry traits to the /identify Segment endpoint.
670
+
671
+ Do not call this function from outside telemetry.py! This function does not
672
+ check if telemetry is enabled or not.
673
+
674
+ Args:
675
+ distinct_id: Unique telemetry ID.
676
+ traits: Pieces of information to be recorded about
677
+ rasa_plus interface implementations.
678
+ context: Context information to be sent along with traits.
679
+ """
680
+ payload = segment_identify_request_payload(distinct_id, traits, context)
681
+
682
+ _send_request(SEGMENT_IDENTIFY_ENDPOINT, payload)
683
+
684
+
685
+ def segment_identify_request_payload(
686
+ distinct_id: Text,
687
+ traits: Dict[Text, Any],
688
+ context: Dict[Text, Any],
689
+ ) -> Dict[Text, Any]:
690
+ """Compose a valid payload for the segment API.
691
+
692
+ Args:
693
+ distinct_id: Unique telemetry ID.
694
+ traits: Pieces of information to be recorded about
695
+ rasa_plus interface implementations.
696
+ context: Context information to be sent along with traits.
697
+
698
+ Returns:
699
+ Valid segment payload.
700
+ """
701
+ return {
702
+ "userId": distinct_id,
703
+ "traits": traits,
704
+ "context": context,
705
+ }
706
+
707
+
708
+ def get_telemetry_id() -> Optional[Text]:
709
+ """Return the unique telemetry identifier for this Rasa Pro install.
710
+
711
+ The identifier can be based on the license.
712
+ Otherwise, it can be any string, but it should be a UUID.
713
+
714
+ Returns:
715
+ The identifier, if it is configured correctly.
716
+ """
717
+ return property_of_active_license(lambda active_license: active_license.jti)
718
+
719
+
720
+ def toggle_telemetry_reporting(is_enabled: bool) -> None:
721
+ """Write to the configuration if telemetry tracking should be enabled or disabled.
722
+
723
+ Args:
724
+ is_enabled: `True` if the telemetry reporting should be enabled,
725
+ `False` otherwise.
726
+ """
727
+ configuration = rasa_utils.read_global_config_value(CONFIG_FILE_TELEMETRY_KEY)
728
+
729
+ if configuration:
730
+ configuration[CONFIG_TELEMETRY_ENABLED] = is_enabled
731
+ else:
732
+ configuration = _default_telemetry_configuration(is_enabled)
733
+
734
+ rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, configuration)
735
+ rasa_utils.write_global_config_value(
736
+ RASA_PRO_CONFIG_FILE_TELEMETRY_KEY, configuration
737
+ )
738
+
739
+
740
+ def filter_errors(
741
+ event: Optional[Dict[Text, Any]], hint: Optional[Dict[Text, Any]] = None
742
+ ) -> Optional[Dict[Text, Any]]:
743
+ """Filter errors.
744
+
745
+ Args:
746
+ event: event to be logged to sentry
747
+ hint: some hinting information sent alongside of the event
748
+
749
+ Returns:
750
+ the event without any sensitive / PII data or `None` if the event constitutes
751
+ an `ImportError` which should be discarded.
752
+ """
753
+ if hint and "exc_info" in hint:
754
+ exc_type, exc_value, tb = hint["exc_info"]
755
+ if isinstance(exc_value, ImportError):
756
+ return None
757
+ return event
758
+
759
+
760
+ def before_send(
761
+ event: Dict[Text, Any], _unused_hint: Optional[Dict[Text, Any]] = None
762
+ ) -> Optional[Dict[Text, Any]]:
763
+ """Strips the sensitive data and filters errors before sending to sentry.
764
+
765
+ Args:
766
+ event: event to be logged to sentry
767
+ _unused_hint: some hinting information sent alongside of the event
768
+
769
+ Returns:
770
+ the event without any sensitive / PII data or `None` if the event should
771
+ be discarded.
772
+ """
773
+ cleaned_event = strip_sensitive_data_from_sentry_event(event, _unused_hint)
774
+ return filter_errors(cleaned_event, _unused_hint)
775
+
776
+
777
+ def strip_sensitive_data_from_sentry_event(
778
+ event: Dict[Text, Any], _unused_hint: Optional[Dict[Text, Any]] = None
779
+ ) -> Optional[Dict[Text, Any]]:
780
+ """Remove any sensitive data from the event (e.g. path names).
781
+
782
+ Args:
783
+ event: event to be logged to sentry
784
+ _unused_hint: some hinting information sent alongside of the event
785
+
786
+ Returns:
787
+ the event without any sensitive / PII data or `None` if the event should
788
+ be discarded.
789
+ """
790
+ # removes any paths from stack traces (avoids e.g. sending
791
+ # a users home directory name if package is installed there)
792
+ for value in event.get("exception", {}).get("values", []):
793
+ for frame in value.get("stacktrace", {}).get("frames", []):
794
+ frame["abs_path"] = ""
795
+
796
+ if f"rasa_sdk{os.path.sep}executor.py" in frame["filename"]:
797
+ # this looks a lot like an exception in the SDK and hence custom code
798
+ # no need for us to deal with that
799
+ return None
800
+ elif "site-packages" in frame["filename"]:
801
+ # drop site-packages and following slash / backslash
802
+ relative_name = frame["filename"].split("site-packages")[-1][1:]
803
+ frame["filename"] = os.path.join("site-packages", relative_name)
804
+ elif "dist-packages" in frame["filename"]:
805
+ # drop dist-packages and following slash / backslash
806
+ relative_name = frame["filename"].split("dist-packages")[-1][1:]
807
+ frame["filename"] = os.path.join("dist-packages", relative_name)
808
+ elif os.path.isabs(frame["filename"]):
809
+ # if the file path is absolute, we'll drop the whole event as this is
810
+ # very likely custom code. needs to happen after cleaning as
811
+ # site-packages / dist-packages paths are also absolute, but fine.
812
+ return None
813
+ return event
814
+
815
+
816
+ @ensure_telemetry_enabled
817
+ def initialize_error_reporting() -> None:
818
+ """Sets up automated error reporting.
819
+
820
+ Exceptions are reported to sentry. We avoid sending any metadata (local
821
+ variables, paths, ...) to make sure we don't compromise any data. Only the
822
+ exception and its stacktrace is logged and only if the exception origins
823
+ from the `rasa` package.
824
+ """
825
+ import sentry_sdk
826
+ from sentry_sdk import configure_scope
827
+ from sentry_sdk.integrations.atexit import AtexitIntegration
828
+ from sentry_sdk.integrations.dedupe import DedupeIntegration
829
+ from sentry_sdk.integrations.excepthook import ExcepthookIntegration
830
+
831
+ # key for local testing can be found at
832
+ # https://sentry.io/settings/rasahq/projects/rasa-open-source/install/python/
833
+ # for local testing, set the key using `RASA_EXCEPTION_WRITE_KEY=key rasa <command>`
834
+ key = sentry_write_key()
835
+
836
+ if not key:
837
+ return
838
+
839
+ telemetry_id = get_telemetry_id()
840
+
841
+ # this is a very defensive configuration, avoiding as many integrations as
842
+ # possible. it also submits very little data (exception with error message
843
+ # and line numbers).
844
+ sentry_sdk.init(
845
+ f"https://{key}.ingest.sentry.io/2801673",
846
+ before_send=before_send,
847
+ integrations=[
848
+ ExcepthookIntegration(),
849
+ DedupeIntegration(),
850
+ AtexitIntegration(lambda _, __: None),
851
+ ],
852
+ send_default_pii=False, # activate PII filter
853
+ server_name=telemetry_id or "UNKNOWN",
854
+ ignore_errors=[
855
+ # std lib errors
856
+ KeyboardInterrupt, # user hit the interrupt key (Ctrl+C)
857
+ MemoryError, # machine is running out of memory
858
+ NotImplementedError, # user is using a feature that is not implemented
859
+ asyncio.CancelledError, # an async operation has been cancelled by the user
860
+ # expected Rasa errors
861
+ RasaException,
862
+ OSError,
863
+ ],
864
+ in_app_include=["rasa"], # only submit errors in this package
865
+ with_locals=False, # don't submit local variables
866
+ release=f"rasa-{rasa.__version__}",
867
+ default_integrations=False,
868
+ environment="development" if in_continuous_integration() else "production",
869
+ )
870
+
871
+ if not telemetry_id:
872
+ return
873
+
874
+ with configure_scope() as scope:
875
+ # sentry added these more recently, just a protection in a case where a
876
+ # user has installed an older version of sentry
877
+ if hasattr(scope, "set_user"):
878
+ scope.set_user({"id": telemetry_id})
879
+
880
+ default_context = _default_context_fields()
881
+ if hasattr(scope, "set_context"):
882
+ if "os" in default_context:
883
+ # os is a nested dict, hence we report it separately
884
+ scope.set_context("Operating System", default_context.pop("os"))
885
+ scope.set_context("Environment", default_context)
886
+
887
+
888
+ @contextlib.contextmanager
889
+ def track_model_training(
890
+ training_data: "TrainingDataImporter", model_type: Text, is_finetuning: bool = False
891
+ ) -> typing.Generator[None, None, None]:
892
+ """Track a model training started.
893
+
894
+ WARNING: since this is a generator, it can't use the ensure telemetry
895
+ decorator. We need to manually add these checks here. This can be
896
+ fixed as soon as we drop python 3.6 support.
897
+
898
+ Args:
899
+ training_data: Training data used for the training.
900
+ model_type: Specifies the type of training, should be either "rasa", "core"
901
+ or "nlu".
902
+ is_finetuning: `True` if the model is trained by finetuning another model.
903
+ """
904
+ if not initialize_telemetry():
905
+ # telemetry reporting is disabled. we won't do any reporting
906
+ yield # runs the training
907
+ return
908
+
909
+ config = training_data.get_config()
910
+ stories = training_data.get_stories()
911
+ nlu_data = training_data.get_nlu_data()
912
+ domain = training_data.get_domain()
913
+ flows = training_data.get_flows()
914
+ count_conditional_responses = domain.count_conditional_response_variations()
915
+ (
916
+ count_total_mappings,
917
+ count_custom_mappings,
918
+ count_conditional_mappings,
919
+ ) = domain.count_slot_mapping_statistics()
920
+
921
+ training_id = uuid.uuid4().hex
922
+
923
+ tracking_data = {
924
+ "language": config.get("language"),
925
+ "training_id": training_id,
926
+ "type": model_type,
927
+ "pipeline": config.get("pipeline"),
928
+ "policies": config.get("policies"),
929
+ "train_schema": config.get("train_schema"),
930
+ "predict_schema": config.get("predict_schema"),
931
+ "num_intent_examples": len(nlu_data.intent_examples),
932
+ "num_entity_examples": len(nlu_data.entity_examples),
933
+ "num_actions": len(domain.action_names_or_texts),
934
+ # Old nomenclature from when 'responses' were still called
935
+ # 'templates' in the domain
936
+ "num_templates": len(domain.responses),
937
+ "num_conditional_response_variations": count_conditional_responses,
938
+ "num_slot_mappings": count_total_mappings,
939
+ "num_custom_slot_mappings": count_custom_mappings,
940
+ "num_conditional_slot_mappings": count_conditional_mappings,
941
+ "num_slots": len(domain.slots),
942
+ "num_forms": len(domain.forms),
943
+ "num_intents": len(domain.intents),
944
+ "num_entities": len(domain.entities),
945
+ "num_story_steps": len(stories.story_steps),
946
+ "num_lookup_tables": len(nlu_data.lookup_tables),
947
+ "num_synonyms": len(nlu_data.entity_synonyms),
948
+ "num_regexes": len(nlu_data.regex_features),
949
+ "is_finetuning": is_finetuning,
950
+ "recipe": config.get("recipe"),
951
+ }
952
+
953
+ flow_statistics = _collect_flow_statistics(flows.underlying_flows)
954
+ tracking_data.update(flow_statistics)
955
+ command_generator_settings = _get_llm_command_generator_config(config)
956
+ tracking_data.update(command_generator_settings)
957
+
958
+ # Make sure to update the example in docs/docs/telemetry/telemetry.mdx
959
+ # if you change / add any properties
960
+ _track(
961
+ TRAINING_STARTED_EVENT,
962
+ tracking_data,
963
+ )
964
+ start = datetime.now()
965
+ yield
966
+ runtime = datetime.now() - start
967
+
968
+ _track(
969
+ TRAINING_COMPLETED_EVENT,
970
+ {
971
+ "training_id": training_id,
972
+ "type": model_type,
973
+ "runtime": int(runtime.total_seconds()),
974
+ },
975
+ )
976
+
977
+
978
+ def _collect_flow_statistics(flows: List[Flow]) -> Dict[str, Any]:
979
+ """Collects some statistics about the flows, such as number of specific steps."""
980
+ data = {
981
+ NUM_FLOWS: len(flows),
982
+ NUM_FLOWS_WITH_NLU_TRIGGER: 0,
983
+ NUM_FLOWS_WITH_FLOW_GUARDS: 0,
984
+ NUM_FLOWS_ALWAYS_INCLUDED_IN_PROMPT: 0,
985
+ NUM_FLOWS_WITH_NOT_STARTABLE_FLOW_GUARDS: 0,
986
+ NUM_COLLECT_STEPS: 0,
987
+ NUM_COLLECT_STEPS_WITH_SEPARATE_UTTER: 0,
988
+ NUM_COLLECT_STEPS_WITH_REJECTIONS: 0,
989
+ NUM_COLLECT_STEPS_WITH_NOT_RESET_AFTER_FLOW_ENDS: 0,
990
+ NUM_SET_SLOT_STEPS: 0,
991
+ MAX_DEPTH_OF_IF_CONSTRUCT: 0,
992
+ NUM_LINK_STEPS: 0,
993
+ NUM_CALL_STEPS: 0,
994
+ NUM_SHARED_SLOTS_BETWEEN_FLOWS: 0,
995
+ }
996
+
997
+ slots_used_in_different_flows = defaultdict(set)
998
+
999
+ for flow in flows:
1000
+ if flow.guard_condition:
1001
+ data[NUM_FLOWS_WITH_FLOW_GUARDS] += 1
1002
+ if flow.guard_condition.lower() == "false":
1003
+ data[NUM_FLOWS_WITH_NOT_STARTABLE_FLOW_GUARDS] += 1
1004
+
1005
+ if flow.always_include_in_prompt:
1006
+ data[NUM_FLOWS_ALWAYS_INCLUDED_IN_PROMPT] += 1
1007
+
1008
+ if flow.nlu_triggers:
1009
+ data[NUM_FLOWS_WITH_NLU_TRIGGER] += 1
1010
+
1011
+ for step in flow.steps_with_calls_resolved:
1012
+ if isinstance(step, CollectInformationFlowStep):
1013
+ slots_used_in_different_flows[step.collect].add(flow.id)
1014
+ data[NUM_COLLECT_STEPS] += 1
1015
+ if len(step.rejections) > 0:
1016
+ data[NUM_COLLECT_STEPS_WITH_REJECTIONS] += 1
1017
+ if not step.reset_after_flow_ends:
1018
+ data[NUM_COLLECT_STEPS_WITH_NOT_RESET_AFTER_FLOW_ENDS] += 1
1019
+ if step.utter != f"{UTTER_ASK_PREFIX}{step.collect}":
1020
+ data[NUM_COLLECT_STEPS_WITH_SEPARATE_UTTER] += 1
1021
+
1022
+ if isinstance(step, SetSlotsFlowStep):
1023
+ for slot in step.slots:
1024
+ slots_used_in_different_flows[slot["key"]].add(flow.id)
1025
+ data[NUM_SET_SLOT_STEPS] += 1
1026
+
1027
+ if isinstance(step, LinkFlowStep):
1028
+ data[NUM_LINK_STEPS] += 1
1029
+
1030
+ if isinstance(step, CallFlowStep):
1031
+ data[NUM_CALL_STEPS] += 1
1032
+
1033
+ if step.next:
1034
+ depth = step.next.depth_in_tree()
1035
+ if depth > data[MAX_DEPTH_OF_IF_CONSTRUCT]:
1036
+ data[MAX_DEPTH_OF_IF_CONSTRUCT] = depth
1037
+
1038
+ for flows_with_slot in slots_used_in_different_flows.values():
1039
+ if len(flows_with_slot) > 1:
1040
+ data[NUM_SHARED_SLOTS_BETWEEN_FLOWS] += 1
1041
+
1042
+ return data
1043
+
1044
+
1045
+ def _get_llm_command_generator_config(config: Dict[str, Any]) -> Optional[Dict]:
1046
+ """Returns the configuration for the LLMCommandGenerator including the model name,
1047
+ whether a custom prompt is used, whether flow retrieval is enabled, and flow
1048
+ retrieval embedding model.
1049
+ """
1050
+ from rasa.dialogue_understanding.generator import LLMCommandGenerator
1051
+ from rasa.dialogue_understanding.generator.llm_command_generator import (
1052
+ LLM_CONFIG_KEY,
1053
+ DEFAULT_LLM_CONFIG,
1054
+ FLOW_RETRIEVAL_KEY,
1055
+ )
1056
+ from rasa.dialogue_understanding.generator.flow_retrieval import (
1057
+ DEFAULT_EMBEDDINGS_CONFIG,
1058
+ )
1059
+
1060
+ def find_command_generator_component(pipeline: List) -> Optional[Dict]:
1061
+ """Finds the LLMCommandGenerator component in the pipeline."""
1062
+ for component in pipeline:
1063
+ if component["name"] == LLMCommandGenerator.__name__:
1064
+ return component
1065
+ return None
1066
+
1067
+ def extract_settings(component: Dict) -> Dict:
1068
+ """Extracts the settings from the command generator component."""
1069
+ custom_prompt_used = "prompt" in component
1070
+ llm_model_name = component.get(LLM_CONFIG_KEY, {}).get(
1071
+ "model_name", DEFAULT_LLM_CONFIG["model_name"]
1072
+ )
1073
+ flow_retrieval_config = component.get(FLOW_RETRIEVAL_KEY, {})
1074
+ flow_retrieval_enabled = flow_retrieval_config.get("active", True)
1075
+ flow_retrieval_embedding_model_name = (
1076
+ flow_retrieval_config.get("embeddings", DEFAULT_EMBEDDINGS_CONFIG).get(
1077
+ "model"
1078
+ )
1079
+ if flow_retrieval_enabled
1080
+ else None
1081
+ )
1082
+ return {
1083
+ LLM_COMMAND_GENERATOR_MODEL_NAME: llm_model_name,
1084
+ LLM_COMMAND_GENERATOR_CUSTOM_PROMPT_USED: custom_prompt_used,
1085
+ FLOW_RETRIEVAL_ENABLED: flow_retrieval_enabled,
1086
+ FLOW_RETRIEVAL_EMBEDDING_MODEL_NAME: flow_retrieval_embedding_model_name,
1087
+ }
1088
+
1089
+ command_generator_config = {
1090
+ LLM_COMMAND_GENERATOR_MODEL_NAME: None,
1091
+ LLM_COMMAND_GENERATOR_CUSTOM_PROMPT_USED: None,
1092
+ FLOW_RETRIEVAL_ENABLED: None,
1093
+ FLOW_RETRIEVAL_EMBEDDING_MODEL_NAME: None,
1094
+ }
1095
+
1096
+ pipeline = config.get("pipeline", [])
1097
+ if not isinstance(pipeline, list):
1098
+ return command_generator_config
1099
+
1100
+ command_generator_component = find_command_generator_component(pipeline)
1101
+ if command_generator_component is not None:
1102
+ extracted_settings = extract_settings(command_generator_component)
1103
+ command_generator_config.update(extracted_settings)
1104
+
1105
+ return command_generator_config
1106
+
1107
+
1108
+ @ensure_telemetry_enabled
1109
+ def track_telemetry_disabled() -> None:
1110
+ """Track when a user disables telemetry."""
1111
+ _track(TELEMETRY_DISABLED_EVENT)
1112
+
1113
+
1114
+ @ensure_telemetry_enabled
1115
+ def track_data_split(fraction: float, data_type: Text) -> None:
1116
+ """Track when a user splits data.
1117
+
1118
+ Args:
1119
+ fraction: How much data goes into train and how much goes into test
1120
+ data_type: Is this core, nlu or nlg data
1121
+ """
1122
+ _track(TELEMETRY_DATA_SPLIT_EVENT, {"fraction": fraction, "type": data_type})
1123
+
1124
+
1125
+ @ensure_telemetry_enabled
1126
+ def track_validate_files(validation_success: bool) -> None:
1127
+ """Track when a user validates data files.
1128
+
1129
+ Args:
1130
+ validation_success: Whether the validation was successful
1131
+ """
1132
+ _track(TELEMETRY_DATA_VALIDATED_EVENT, {"validation_success": validation_success})
1133
+
1134
+
1135
+ @ensure_telemetry_enabled
1136
+ def track_data_convert(output_format: Text, data_type: Text) -> None:
1137
+ """Track when a user converts data.
1138
+
1139
+ Args:
1140
+ output_format: Target format for the converter
1141
+ data_type: Is this core, nlu or nlg data
1142
+ """
1143
+ _track(
1144
+ TELEMETRY_DATA_CONVERTED_EVENT,
1145
+ {"output_format": output_format, "type": data_type},
1146
+ )
1147
+
1148
+
1149
+ @ensure_telemetry_enabled
1150
+ def track_tracker_export(
1151
+ number_of_exported_events: int,
1152
+ tracker_store: "TrackerStore",
1153
+ event_broker: "EventBroker",
1154
+ ) -> None:
1155
+ """Track when a user exports trackers.
1156
+
1157
+ Args:
1158
+ number_of_exported_events: Number of events that got exported
1159
+ tracker_store: Store used to retrieve the events from
1160
+ event_broker: Broker the events are getting published towards
1161
+ """
1162
+ _track(
1163
+ TELEMETRY_TRACKER_EXPORTED_EVENT,
1164
+ {
1165
+ "number_of_exported_events": number_of_exported_events,
1166
+ "tracker_store": type(tracker_store).__name__,
1167
+ "event_broker": type(event_broker).__name__,
1168
+ },
1169
+ )
1170
+
1171
+
1172
+ @ensure_telemetry_enabled
1173
+ def track_interactive_learning_start(
1174
+ skip_visualization: bool, save_in_e2e: bool
1175
+ ) -> None:
1176
+ """Track when a user starts an interactive learning session.
1177
+
1178
+ Args:
1179
+ skip_visualization: Is visualization skipped in this session
1180
+ save_in_e2e: Is e2e used in this session
1181
+ """
1182
+ _track(
1183
+ TELEMETRY_INTERACTIVE_LEARNING_STARTED_EVENT,
1184
+ {"skip_visualization": skip_visualization, "save_in_e2e": save_in_e2e},
1185
+ )
1186
+
1187
+
1188
+ @ensure_telemetry_enabled
1189
+ def track_server_start(
1190
+ input_channels: List["InputChannel"],
1191
+ endpoints: Optional["AvailableEndpoints"],
1192
+ model_directory: Optional[Text],
1193
+ number_of_workers: int,
1194
+ is_api_enabled: bool,
1195
+ ) -> None:
1196
+ """Tracks when a user starts a rasa server.
1197
+
1198
+ Args:
1199
+ input_channels: Used input channels
1200
+ endpoints: Endpoint configuration for the server
1201
+ model_directory: directory of the running model
1202
+ number_of_workers: number of used Sanic workers
1203
+ is_api_enabled: whether the rasa API server is enabled
1204
+ """
1205
+ from rasa.core.utils import AvailableEndpoints
1206
+
1207
+ def project_fingerprint_from_model(
1208
+ _model_directory: Optional[Text],
1209
+ ) -> Optional[Text]:
1210
+ """Gets project fingerprint from an app's loaded model."""
1211
+ if not model_directory:
1212
+ return None
1213
+
1214
+ try:
1215
+ model_archive = model.get_local_model(_model_directory)
1216
+ metadata = LocalModelStorage.metadata_from_archive(model_archive)
1217
+
1218
+ return metadata.project_fingerprint
1219
+ except Exception:
1220
+ return None
1221
+
1222
+ if not endpoints:
1223
+ endpoints = AvailableEndpoints()
1224
+
1225
+ _track(
1226
+ TELEMETRY_SERVER_STARTED_EVENT,
1227
+ {
1228
+ "input_channels": [i.name() for i in input_channels],
1229
+ "api_enabled": is_api_enabled,
1230
+ "number_of_workers": number_of_workers,
1231
+ "endpoints_nlg": endpoints.nlg.type if endpoints.nlg else None,
1232
+ "endpoints_nlu": endpoints.nlu.type if endpoints.nlu else None,
1233
+ "endpoints_action_server": (
1234
+ endpoints.action.type if endpoints.action else None
1235
+ ),
1236
+ "endpoints_model_server": endpoints.model.type if endpoints.model else None,
1237
+ "endpoints_tracker_store": (
1238
+ endpoints.tracker_store.type if endpoints.tracker_store else None
1239
+ ),
1240
+ "endpoints_lock_store": (
1241
+ endpoints.lock_store.type if endpoints.lock_store else None
1242
+ ),
1243
+ "endpoints_event_broker": (
1244
+ endpoints.event_broker.type if endpoints.event_broker else None
1245
+ ),
1246
+ "project": project_fingerprint_from_model(model_directory),
1247
+ },
1248
+ )
1249
+
1250
+
1251
+ @ensure_telemetry_enabled
1252
+ def track_project_init(path: Text) -> None:
1253
+ """Track when a user creates a project using rasa init.
1254
+
1255
+ Args:
1256
+ path: Location of the project
1257
+ """
1258
+ _track(
1259
+ TELEMETRY_PROJECT_CREATED_EVENT, {"init_directory": _hash_directory_path(path)}
1260
+ )
1261
+
1262
+
1263
+ @ensure_telemetry_enabled
1264
+ def track_shell_started(model_type: Text) -> None:
1265
+ """Track when a user starts a bot using rasa shell.
1266
+
1267
+ Args:
1268
+ model_type: Type of the model, core / nlu or rasa.
1269
+ """
1270
+ _track(TELEMETRY_SHELL_STARTED_EVENT, {"type": model_type})
1271
+
1272
+
1273
+ @ensure_telemetry_enabled
1274
+ def track_visualization() -> None:
1275
+ """Track when a user runs the visualization."""
1276
+ _track(TELEMETRY_VISUALIZATION_STARTED_EVENT)
1277
+
1278
+
1279
+ @ensure_telemetry_enabled
1280
+ def track_core_model_test(num_story_steps: int, e2e: bool, agent: "Agent") -> None:
1281
+ """Track when a user tests a core model.
1282
+
1283
+ Args:
1284
+ num_story_steps: Number of test stories used for the comparison
1285
+ e2e: indicator if tests running in end to end mode
1286
+ agent: Agent of the model getting tested
1287
+ """
1288
+ if agent.processor is None:
1289
+ project_fingerprint = ""
1290
+ else:
1291
+ project_fingerprint = agent.processor.model_metadata.project_fingerprint
1292
+
1293
+ _track(
1294
+ TELEMETRY_TEST_CORE_EVENT,
1295
+ {
1296
+ "project": project_fingerprint,
1297
+ "end_to_end": e2e,
1298
+ "num_story_steps": num_story_steps,
1299
+ },
1300
+ )
1301
+
1302
+
1303
+ @ensure_telemetry_enabled
1304
+ def track_nlu_model_test(test_data: "TrainingData") -> None:
1305
+ """Track when a user tests an nlu model.
1306
+
1307
+ Args:
1308
+ test_data: Data used for testing
1309
+ """
1310
+ _track(
1311
+ TELEMETRY_TEST_NLU_EVENT,
1312
+ {
1313
+ "num_intent_examples": len(test_data.intent_examples),
1314
+ "num_entity_examples": len(test_data.entity_examples),
1315
+ "num_lookup_tables": len(test_data.lookup_tables),
1316
+ "num_synonyms": len(test_data.entity_synonyms),
1317
+ "num_regexes": len(test_data.regex_features),
1318
+ },
1319
+ )
1320
+
1321
+
1322
+ @ensure_telemetry_enabled
1323
+ def track_markers_extraction_initiated(
1324
+ strategy: Text, only_extract: bool, seed: bool, count: Optional[int]
1325
+ ) -> None:
1326
+ """Track when a user tries to extract success markers.
1327
+
1328
+ Args:
1329
+ strategy: The strategy the user is using for tracker selection
1330
+ only_extract: Indicates if the user is only extracting markers or also
1331
+ producing stats
1332
+ seed: Indicates if the user used a seed for this attempt
1333
+ count: (Optional) The number of trackers the user is trying to select.
1334
+ """
1335
+ _track(
1336
+ TELEMETRY_MARKERS_EXTRACTION_INITIATED_EVENT,
1337
+ {
1338
+ "strategy": strategy,
1339
+ "only_extract": only_extract,
1340
+ "seed": seed,
1341
+ "count": count,
1342
+ },
1343
+ )
1344
+
1345
+
1346
+ @ensure_telemetry_enabled
1347
+ def track_markers_extracted(trackers_count: int) -> None:
1348
+ """Track when markers have been extracted by a user.
1349
+
1350
+ Args:
1351
+ trackers_count: The actual number of trackers processed
1352
+ """
1353
+ _track(TELEMETRY_MARKERS_EXTRACTED_EVENT, {"trackers_count": trackers_count})
1354
+
1355
+
1356
+ @ensure_telemetry_enabled
1357
+ def track_markers_stats_computed(trackers_count: int) -> None:
1358
+ """Track when stats over markers have been computed by a user.
1359
+
1360
+ Args:
1361
+ trackers_count: The actual number of trackers processed
1362
+ """
1363
+ _track(TELEMETRY_MARKERS_STATS_COMPUTED_EVENT, {"trackers_count": trackers_count})
1364
+
1365
+
1366
+ @ensure_telemetry_enabled
1367
+ def track_markers_parsed_count(
1368
+ marker_count: int, max_depth: int, branching_factor: int
1369
+ ) -> None:
1370
+ """Track when markers have been successfully parsed from config.
1371
+
1372
+ Args:
1373
+ marker_count: The number of markers found in the config
1374
+ max_depth: The maximum depth of any marker in the config
1375
+ branching_factor: The maximum number of children of any marker in the config.
1376
+ """
1377
+ _track(
1378
+ TELEMETRY_MARKERS_PARSED_COUNT,
1379
+ {
1380
+ "marker_count": marker_count,
1381
+ "max_depth": max_depth,
1382
+ "branching_factor": branching_factor,
1383
+ },
1384
+ )
1385
+
1386
+
1387
+ @ensure_telemetry_enabled
1388
+ def track_e2e_test_run(
1389
+ input_test_cases: List["TestCase"], input_fixtures: List["Fixture"]
1390
+ ) -> None:
1391
+ """Track an end-to-end test run."""
1392
+ _track(
1393
+ TELEMETRY_E2E_TEST_RUN_STARTED_EVENT,
1394
+ {
1395
+ "number_of_test_cases": len(input_test_cases),
1396
+ "number_of_fixtures": len(input_fixtures),
1397
+ "uses_fixtures": len(input_fixtures) > 0,
1398
+ },
1399
+ )
1400
+
1401
+
1402
+ @ensure_telemetry_enabled
1403
+ def track_response_rephrase(
1404
+ rephrase_all: bool,
1405
+ custom_prompt_template: Optional[str],
1406
+ llm_type: Optional[str],
1407
+ llm_model: Optional[str],
1408
+ ) -> None:
1409
+ """Track when a user rephrases a response."""
1410
+ _track(
1411
+ TELEMETRY_RESPONSE_REPHRASED_EVENT,
1412
+ {
1413
+ "rephrase_all": rephrase_all,
1414
+ "custom_prompt_template": custom_prompt_template,
1415
+ "llm_type": llm_type,
1416
+ "llm_model": llm_model,
1417
+ },
1418
+ )
1419
+
1420
+
1421
+ @ensure_telemetry_enabled
1422
+ def track_intentless_policy_train() -> None:
1423
+ """Track when a user trains a policy."""
1424
+ _track(TELEMETRY_INTENTLESS_POLICY_TRAINING_STARTED_EVENT)
1425
+
1426
+
1427
+ @ensure_telemetry_enabled
1428
+ def track_intentless_policy_train_completed(
1429
+ embeddings_type: Optional[str],
1430
+ embeddings_model: Optional[str],
1431
+ llm_type: Optional[str],
1432
+ llm_model: Optional[str],
1433
+ ) -> None:
1434
+ """Track when a user trains a policy."""
1435
+ _track(
1436
+ TELEMETRY_INTENTLESS_POLICY_TRAINING_COMPLETED_EVENT,
1437
+ {
1438
+ "embeddings_type": embeddings_type,
1439
+ "embeddings_model": embeddings_model,
1440
+ "llm_type": llm_type,
1441
+ "llm_model": llm_model,
1442
+ },
1443
+ )
1444
+
1445
+
1446
+ @ensure_telemetry_enabled
1447
+ def track_intentless_policy_predict(
1448
+ embeddings_type: Optional[str],
1449
+ embeddings_model: Optional[str],
1450
+ llm_type: Optional[str],
1451
+ llm_model: Optional[str],
1452
+ score: float,
1453
+ ) -> None:
1454
+ """Track when a user trains a policy."""
1455
+ _track(
1456
+ TELEMETRY_INTENTLESS_POLICY_PREDICT_EVENT,
1457
+ {
1458
+ "embeddings_type": embeddings_type,
1459
+ "embeddings_model": embeddings_model,
1460
+ "llm_type": llm_type,
1461
+ "llm_model": llm_model,
1462
+ "score": score,
1463
+ },
1464
+ )
1465
+
1466
+
1467
+ @ensure_telemetry_enabled
1468
+ def track_llm_intent_predict(
1469
+ embeddings_type: Optional[str],
1470
+ embeddings_model: Optional[str],
1471
+ llm_type: Optional[str],
1472
+ llm_model: Optional[str],
1473
+ ) -> None:
1474
+ """Track when a user predicts an intent using the llm intent classifier."""
1475
+ _track(
1476
+ TELEMETRY_LLM_INTENT_PREDICT_EVENT,
1477
+ {
1478
+ "embeddings_type": embeddings_type,
1479
+ "embeddings_model": embeddings_model,
1480
+ "llm_type": llm_type,
1481
+ "llm_model": llm_model,
1482
+ },
1483
+ )
1484
+
1485
+
1486
+ @ensure_telemetry_enabled
1487
+ def track_llm_intent_train_completed(
1488
+ embeddings_type: Optional[str],
1489
+ embeddings_model: Optional[str],
1490
+ llm_type: Optional[str],
1491
+ llm_model: Optional[str],
1492
+ fallback_intent: Optional[str],
1493
+ custom_prompt_template: Optional[str],
1494
+ number_of_examples: int,
1495
+ number_of_available_intents: int,
1496
+ ) -> None:
1497
+ """Track when a user trains the llm intent classifier."""
1498
+ _track(
1499
+ TELEMETRY_LLM_INTENT_TRAIN_COMPLETED_EVENT,
1500
+ {
1501
+ "embeddings_type": embeddings_type,
1502
+ "embeddings_model": embeddings_model,
1503
+ "llm_type": llm_type,
1504
+ "llm_model": llm_model,
1505
+ "fallback_intent": fallback_intent,
1506
+ "custom_prompt_template": custom_prompt_template,
1507
+ "number_of_examples": number_of_examples,
1508
+ "number_of_available_intents": number_of_available_intents,
1509
+ },
1510
+ )
1511
+
1512
+
1513
+ @ensure_telemetry_enabled
1514
+ def identify_endpoint_config_traits(
1515
+ endpoints_file: Optional[Text],
1516
+ context: Optional[Dict[Text, Any]] = None,
1517
+ ) -> None:
1518
+ """Collect traits if enabled.
1519
+
1520
+ Otherwise, sets traits to None.
1521
+ """
1522
+ traits: Dict[str, Any] = {}
1523
+
1524
+ traits = append_tracing_trait(traits, endpoints_file)
1525
+ traits = append_metrics_trait(traits, endpoints_file)
1526
+ traits = append_anonymization_trait(traits, endpoints_file)
1527
+
1528
+ _identify(traits, context)
1529
+
1530
+
1531
+ def append_tracing_trait(
1532
+ traits: Dict[str, Any], endpoints_file: Optional[str]
1533
+ ) -> Dict[str, Any]:
1534
+ """Append the tracing trait to the traits dictionary."""
1535
+ import rasa.utils.endpoints
1536
+ from rasa.tracing.constants import ENDPOINTS_TRACING_KEY
1537
+
1538
+ tracing_config = rasa.utils.endpoints.read_endpoint_config(
1539
+ endpoints_file, ENDPOINTS_TRACING_KEY
1540
+ )
1541
+ traits[TRACING_BACKEND] = (
1542
+ tracing_config.type if tracing_config is not None else None
1543
+ )
1544
+
1545
+ return traits
1546
+
1547
+
1548
+ def append_metrics_trait(
1549
+ traits: Dict[str, Any], endpoints_file: Optional[str]
1550
+ ) -> Dict[str, Any]:
1551
+ """Append the metrics trait to the traits dictionary."""
1552
+ import rasa.utils.endpoints
1553
+ from rasa.tracing.constants import ENDPOINTS_METRICS_KEY
1554
+
1555
+ metrics_config = rasa.utils.endpoints.read_endpoint_config(
1556
+ endpoints_file, ENDPOINTS_METRICS_KEY
1557
+ )
1558
+ traits[METRICS_BACKEND] = (
1559
+ metrics_config.type if metrics_config is not None else None
1560
+ )
1561
+
1562
+ return traits
1563
+
1564
+
1565
+ def append_anonymization_trait(
1566
+ traits: Dict[str, Any], endpoints_file: Optional[str]
1567
+ ) -> Dict[str, Any]:
1568
+ """Append the anonymization trait to the traits dictionary."""
1569
+ from rasa.anonymization.anonymisation_rule_yaml_reader import (
1570
+ KEY_ANONYMIZATION_RULES,
1571
+ )
1572
+
1573
+ anonymization_config = rasa.anonymization.utils.read_endpoint_config(
1574
+ endpoints_file, KEY_ANONYMIZATION_RULES
1575
+ )
1576
+
1577
+ traits[
1578
+ KEY_ANONYMIZATION_RULES
1579
+ ] = rasa.anonymization.utils.extract_anonymization_traits(
1580
+ anonymization_config, KEY_ANONYMIZATION_RULES
1581
+ )
1582
+
1583
+ return traits