rasa-pro 3.12.0.dev1__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.
- README.md +41 -0
- rasa/__init__.py +9 -0
- rasa/__main__.py +177 -0
- rasa/anonymization/__init__.py +2 -0
- rasa/anonymization/anonymisation_rule_yaml_reader.py +91 -0
- rasa/anonymization/anonymization_pipeline.py +286 -0
- rasa/anonymization/anonymization_rule_executor.py +260 -0
- rasa/anonymization/anonymization_rule_orchestrator.py +120 -0
- rasa/anonymization/schemas/config.yml +47 -0
- rasa/anonymization/utils.py +118 -0
- rasa/api.py +160 -0
- rasa/cli/__init__.py +5 -0
- rasa/cli/arguments/__init__.py +0 -0
- rasa/cli/arguments/data.py +106 -0
- rasa/cli/arguments/default_arguments.py +207 -0
- rasa/cli/arguments/evaluate.py +65 -0
- rasa/cli/arguments/export.py +51 -0
- rasa/cli/arguments/interactive.py +74 -0
- rasa/cli/arguments/run.py +219 -0
- rasa/cli/arguments/shell.py +17 -0
- rasa/cli/arguments/test.py +211 -0
- rasa/cli/arguments/train.py +279 -0
- rasa/cli/arguments/visualize.py +34 -0
- rasa/cli/arguments/x.py +30 -0
- rasa/cli/data.py +354 -0
- rasa/cli/dialogue_understanding_test.py +251 -0
- rasa/cli/e2e_test.py +259 -0
- rasa/cli/evaluate.py +222 -0
- rasa/cli/export.py +250 -0
- rasa/cli/inspect.py +75 -0
- rasa/cli/interactive.py +166 -0
- rasa/cli/license.py +65 -0
- rasa/cli/llm_fine_tuning.py +403 -0
- rasa/cli/markers.py +78 -0
- rasa/cli/project_templates/__init__.py +0 -0
- rasa/cli/project_templates/calm/actions/__init__.py +0 -0
- rasa/cli/project_templates/calm/actions/action_template.py +27 -0
- rasa/cli/project_templates/calm/actions/add_contact.py +30 -0
- rasa/cli/project_templates/calm/actions/db.py +57 -0
- rasa/cli/project_templates/calm/actions/list_contacts.py +22 -0
- rasa/cli/project_templates/calm/actions/remove_contact.py +35 -0
- rasa/cli/project_templates/calm/config.yml +10 -0
- rasa/cli/project_templates/calm/credentials.yml +33 -0
- rasa/cli/project_templates/calm/data/flows/add_contact.yml +31 -0
- rasa/cli/project_templates/calm/data/flows/list_contacts.yml +14 -0
- rasa/cli/project_templates/calm/data/flows/remove_contact.yml +29 -0
- rasa/cli/project_templates/calm/db/contacts.json +10 -0
- rasa/cli/project_templates/calm/domain/add_contact.yml +39 -0
- rasa/cli/project_templates/calm/domain/list_contacts.yml +17 -0
- rasa/cli/project_templates/calm/domain/remove_contact.yml +38 -0
- rasa/cli/project_templates/calm/domain/shared.yml +10 -0
- rasa/cli/project_templates/calm/e2e_tests/cancelations/user_cancels_during_a_correction.yml +16 -0
- rasa/cli/project_templates/calm/e2e_tests/cancelations/user_changes_mind_on_a_whim.yml +7 -0
- rasa/cli/project_templates/calm/e2e_tests/corrections/user_corrects_contact_handle.yml +20 -0
- rasa/cli/project_templates/calm/e2e_tests/corrections/user_corrects_contact_name.yml +19 -0
- rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_adds_contact_to_their_list.yml +15 -0
- rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_lists_contacts.yml +5 -0
- rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_removes_contact.yml +11 -0
- rasa/cli/project_templates/calm/e2e_tests/happy_paths/user_removes_contact_from_list.yml +12 -0
- rasa/cli/project_templates/calm/endpoints.yml +58 -0
- rasa/cli/project_templates/default/actions/__init__.py +0 -0
- rasa/cli/project_templates/default/actions/actions.py +27 -0
- rasa/cli/project_templates/default/config.yml +44 -0
- rasa/cli/project_templates/default/credentials.yml +33 -0
- rasa/cli/project_templates/default/data/nlu.yml +91 -0
- rasa/cli/project_templates/default/data/rules.yml +13 -0
- rasa/cli/project_templates/default/data/stories.yml +30 -0
- rasa/cli/project_templates/default/domain.yml +34 -0
- rasa/cli/project_templates/default/endpoints.yml +42 -0
- rasa/cli/project_templates/default/tests/test_stories.yml +91 -0
- rasa/cli/project_templates/tutorial/actions/__init__.py +0 -0
- rasa/cli/project_templates/tutorial/actions/actions.py +22 -0
- rasa/cli/project_templates/tutorial/config.yml +12 -0
- rasa/cli/project_templates/tutorial/credentials.yml +33 -0
- rasa/cli/project_templates/tutorial/data/flows.yml +8 -0
- rasa/cli/project_templates/tutorial/data/patterns.yml +11 -0
- rasa/cli/project_templates/tutorial/domain.yml +35 -0
- rasa/cli/project_templates/tutorial/endpoints.yml +55 -0
- rasa/cli/run.py +143 -0
- rasa/cli/scaffold.py +273 -0
- rasa/cli/shell.py +141 -0
- rasa/cli/studio/__init__.py +0 -0
- rasa/cli/studio/download.py +62 -0
- rasa/cli/studio/studio.py +296 -0
- rasa/cli/studio/train.py +59 -0
- rasa/cli/studio/upload.py +62 -0
- rasa/cli/telemetry.py +102 -0
- rasa/cli/test.py +280 -0
- rasa/cli/train.py +278 -0
- rasa/cli/utils.py +484 -0
- rasa/cli/visualize.py +40 -0
- rasa/cli/x.py +206 -0
- rasa/constants.py +45 -0
- rasa/core/__init__.py +17 -0
- rasa/core/actions/__init__.py +0 -0
- rasa/core/actions/action.py +1318 -0
- rasa/core/actions/action_clean_stack.py +59 -0
- rasa/core/actions/action_exceptions.py +24 -0
- rasa/core/actions/action_hangup.py +29 -0
- rasa/core/actions/action_repeat_bot_messages.py +89 -0
- rasa/core/actions/action_run_slot_rejections.py +210 -0
- rasa/core/actions/action_trigger_chitchat.py +31 -0
- rasa/core/actions/action_trigger_flow.py +109 -0
- rasa/core/actions/action_trigger_search.py +31 -0
- rasa/core/actions/constants.py +5 -0
- rasa/core/actions/custom_action_executor.py +191 -0
- rasa/core/actions/direct_custom_actions_executor.py +109 -0
- rasa/core/actions/e2e_stub_custom_action_executor.py +72 -0
- rasa/core/actions/forms.py +741 -0
- rasa/core/actions/grpc_custom_action_executor.py +251 -0
- rasa/core/actions/http_custom_action_executor.py +145 -0
- rasa/core/actions/loops.py +114 -0
- rasa/core/actions/two_stage_fallback.py +186 -0
- rasa/core/agent.py +559 -0
- rasa/core/auth_retry_tracker_store.py +122 -0
- rasa/core/brokers/__init__.py +0 -0
- rasa/core/brokers/broker.py +126 -0
- rasa/core/brokers/file.py +58 -0
- rasa/core/brokers/kafka.py +324 -0
- rasa/core/brokers/pika.py +388 -0
- rasa/core/brokers/sql.py +86 -0
- rasa/core/channels/__init__.py +61 -0
- rasa/core/channels/botframework.py +338 -0
- rasa/core/channels/callback.py +84 -0
- rasa/core/channels/channel.py +456 -0
- rasa/core/channels/console.py +241 -0
- rasa/core/channels/development_inspector.py +197 -0
- rasa/core/channels/facebook.py +419 -0
- rasa/core/channels/hangouts.py +329 -0
- rasa/core/channels/inspector/.eslintrc.cjs +25 -0
- rasa/core/channels/inspector/.gitignore +23 -0
- rasa/core/channels/inspector/README.md +54 -0
- rasa/core/channels/inspector/assets/favicon.ico +0 -0
- rasa/core/channels/inspector/assets/rasa-chat.js +2 -0
- rasa/core/channels/inspector/custom.d.ts +3 -0
- rasa/core/channels/inspector/dist/assets/arc-861ddd57.js +1 -0
- rasa/core/channels/inspector/dist/assets/array-9f3ba611.js +1 -0
- rasa/core/channels/inspector/dist/assets/c4Diagram-d0fbc5ce-921f02db.js +10 -0
- rasa/core/channels/inspector/dist/assets/classDiagram-936ed81e-b436c4f8.js +2 -0
- rasa/core/channels/inspector/dist/assets/classDiagram-v2-c3cb15f1-511a23cb.js +2 -0
- rasa/core/channels/inspector/dist/assets/createText-62fc7601-ef476ecd.js +7 -0
- rasa/core/channels/inspector/dist/assets/edges-f2ad444c-f1878e0a.js +4 -0
- rasa/core/channels/inspector/dist/assets/erDiagram-9d236eb7-fac75185.js +51 -0
- rasa/core/channels/inspector/dist/assets/flowDb-1972c806-201c5bbc.js +6 -0
- rasa/core/channels/inspector/dist/assets/flowDiagram-7ea5b25a-f904ae41.js +4 -0
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-b080d6f2.js +1 -0
- rasa/core/channels/inspector/dist/assets/flowchart-elk-definition-abe16c3d-1813da66.js +139 -0
- rasa/core/channels/inspector/dist/assets/ganttDiagram-9b5ea136-872af172.js +266 -0
- rasa/core/channels/inspector/dist/assets/gitGraphDiagram-99d0ae7c-34a0af5a.js +70 -0
- rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-128cfa44.ttf +0 -0
- rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-21dbcb97.woff +0 -0
- rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-222b5e26.svg +329 -0
- rasa/core/channels/inspector/dist/assets/ibm-plex-mono-v4-latin-regular-9ad89b2a.woff2 +0 -0
- rasa/core/channels/inspector/dist/assets/index-2c4b9a3b-42ba3e3d.js +1 -0
- rasa/core/channels/inspector/dist/assets/index-37817b51.js +1317 -0
- rasa/core/channels/inspector/dist/assets/index-3ee28881.css +1 -0
- rasa/core/channels/inspector/dist/assets/infoDiagram-736b4530-6b731386.js +7 -0
- rasa/core/channels/inspector/dist/assets/init-77b53fdd.js +1 -0
- rasa/core/channels/inspector/dist/assets/journeyDiagram-df861f2b-e8579ac6.js +139 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-60c05ee4.woff +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-8335d9b8.svg +438 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-9cc39c75.ttf +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-700-ead13ccf.woff2 +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-16705655.woff2 +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-5aeb07f9.woff +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-9c459044.ttf +0 -0
- rasa/core/channels/inspector/dist/assets/lato-v14-latin-regular-9e2898a4.svg +435 -0
- rasa/core/channels/inspector/dist/assets/layout-89e6403a.js +1 -0
- rasa/core/channels/inspector/dist/assets/line-dc73d3fc.js +1 -0
- rasa/core/channels/inspector/dist/assets/linear-f5b1d2bc.js +1 -0
- rasa/core/channels/inspector/dist/assets/mindmap-definition-beec6740-82cb74fa.js +109 -0
- rasa/core/channels/inspector/dist/assets/ordinal-ba9b4969.js +1 -0
- rasa/core/channels/inspector/dist/assets/path-53f90ab3.js +1 -0
- rasa/core/channels/inspector/dist/assets/pieDiagram-dbbf0591-bdf5f29b.js +35 -0
- rasa/core/channels/inspector/dist/assets/quadrantDiagram-4d7f4fd6-c7a0cbe4.js +7 -0
- rasa/core/channels/inspector/dist/assets/requirementDiagram-6fc4c22a-7ec5410f.js +52 -0
- rasa/core/channels/inspector/dist/assets/sankeyDiagram-8f13d901-caee5554.js +8 -0
- rasa/core/channels/inspector/dist/assets/sequenceDiagram-b655622a-2935f8db.js +122 -0
- rasa/core/channels/inspector/dist/assets/stateDiagram-59f0c015-8f5d9693.js +1 -0
- rasa/core/channels/inspector/dist/assets/stateDiagram-v2-2b26beab-d565d1de.js +1 -0
- rasa/core/channels/inspector/dist/assets/styles-080da4f6-75ad421d.js +110 -0
- rasa/core/channels/inspector/dist/assets/styles-3dcbcfbf-7e764226.js +159 -0
- rasa/core/channels/inspector/dist/assets/styles-9c745c82-7a4e0e61.js +207 -0
- rasa/core/channels/inspector/dist/assets/svgDrawCommon-4835440b-4019d1bf.js +1 -0
- rasa/core/channels/inspector/dist/assets/timeline-definition-5b62e21b-01ea12df.js +61 -0
- rasa/core/channels/inspector/dist/assets/xychartDiagram-2b33534f-89407137.js +7 -0
- rasa/core/channels/inspector/dist/index.html +42 -0
- rasa/core/channels/inspector/index.html +40 -0
- rasa/core/channels/inspector/jest.config.ts +13 -0
- rasa/core/channels/inspector/package.json +52 -0
- rasa/core/channels/inspector/setupTests.ts +2 -0
- rasa/core/channels/inspector/src/App.tsx +220 -0
- rasa/core/channels/inspector/src/components/Chat.tsx +95 -0
- rasa/core/channels/inspector/src/components/DiagramFlow.tsx +108 -0
- rasa/core/channels/inspector/src/components/DialogueInformation.tsx +187 -0
- rasa/core/channels/inspector/src/components/DialogueStack.tsx +136 -0
- rasa/core/channels/inspector/src/components/ExpandIcon.tsx +16 -0
- rasa/core/channels/inspector/src/components/FullscreenButton.tsx +45 -0
- rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +22 -0
- rasa/core/channels/inspector/src/components/NoActiveFlow.tsx +21 -0
- rasa/core/channels/inspector/src/components/RasaLogo.tsx +32 -0
- rasa/core/channels/inspector/src/components/SaraDiagrams.tsx +39 -0
- rasa/core/channels/inspector/src/components/Slots.tsx +91 -0
- rasa/core/channels/inspector/src/components/Welcome.tsx +54 -0
- rasa/core/channels/inspector/src/helpers/audiostream.ts +191 -0
- rasa/core/channels/inspector/src/helpers/formatters.test.ts +392 -0
- rasa/core/channels/inspector/src/helpers/formatters.ts +306 -0
- rasa/core/channels/inspector/src/helpers/utils.ts +127 -0
- rasa/core/channels/inspector/src/main.tsx +13 -0
- rasa/core/channels/inspector/src/theme/Button/Button.ts +29 -0
- rasa/core/channels/inspector/src/theme/Heading/Heading.ts +31 -0
- rasa/core/channels/inspector/src/theme/Input/Input.ts +27 -0
- rasa/core/channels/inspector/src/theme/Link/Link.ts +10 -0
- rasa/core/channels/inspector/src/theme/Modal/Modal.ts +47 -0
- rasa/core/channels/inspector/src/theme/Table/Table.tsx +38 -0
- rasa/core/channels/inspector/src/theme/Tooltip/Tooltip.ts +12 -0
- rasa/core/channels/inspector/src/theme/base/breakpoints.ts +8 -0
- rasa/core/channels/inspector/src/theme/base/colors.ts +88 -0
- rasa/core/channels/inspector/src/theme/base/fonts/fontFaces.css +29 -0
- rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.eot +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.svg +329 -0
- rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.ttf +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.woff +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/ibm-plex-mono-v4-latin/ibm-plex-mono-v4-latin-regular.woff2 +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.eot +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.svg +438 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.ttf +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.woff +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-700.woff2 +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.eot +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.svg +435 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.ttf +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.woff +0 -0
- rasa/core/channels/inspector/src/theme/base/fonts/lato-v14-latin/lato-v14-latin-regular.woff2 +0 -0
- rasa/core/channels/inspector/src/theme/base/radii.ts +9 -0
- rasa/core/channels/inspector/src/theme/base/shadows.ts +7 -0
- rasa/core/channels/inspector/src/theme/base/sizes.ts +7 -0
- rasa/core/channels/inspector/src/theme/base/space.ts +15 -0
- rasa/core/channels/inspector/src/theme/base/styles.ts +13 -0
- rasa/core/channels/inspector/src/theme/base/typography.ts +24 -0
- rasa/core/channels/inspector/src/theme/base/zIndices.ts +19 -0
- rasa/core/channels/inspector/src/theme/index.ts +101 -0
- rasa/core/channels/inspector/src/types.ts +84 -0
- rasa/core/channels/inspector/src/vite-env.d.ts +1 -0
- rasa/core/channels/inspector/tests/__mocks__/fileMock.ts +1 -0
- rasa/core/channels/inspector/tests/__mocks__/matchMedia.ts +16 -0
- rasa/core/channels/inspector/tests/__mocks__/styleMock.ts +1 -0
- rasa/core/channels/inspector/tests/renderWithProviders.tsx +14 -0
- rasa/core/channels/inspector/tsconfig.json +26 -0
- rasa/core/channels/inspector/tsconfig.node.json +10 -0
- rasa/core/channels/inspector/vite.config.ts +8 -0
- rasa/core/channels/inspector/yarn.lock +6249 -0
- rasa/core/channels/mattermost.py +229 -0
- rasa/core/channels/rasa_chat.py +126 -0
- rasa/core/channels/rest.py +230 -0
- rasa/core/channels/rocketchat.py +174 -0
- rasa/core/channels/slack.py +620 -0
- rasa/core/channels/socketio.py +302 -0
- rasa/core/channels/telegram.py +298 -0
- rasa/core/channels/twilio.py +169 -0
- rasa/core/channels/vier_cvg.py +374 -0
- rasa/core/channels/voice_ready/__init__.py +0 -0
- rasa/core/channels/voice_ready/audiocodes.py +501 -0
- rasa/core/channels/voice_ready/jambonz.py +121 -0
- rasa/core/channels/voice_ready/jambonz_protocol.py +396 -0
- rasa/core/channels/voice_ready/twilio_voice.py +403 -0
- rasa/core/channels/voice_ready/utils.py +37 -0
- rasa/core/channels/voice_stream/__init__.py +0 -0
- rasa/core/channels/voice_stream/asr/__init__.py +0 -0
- rasa/core/channels/voice_stream/asr/asr_engine.py +89 -0
- rasa/core/channels/voice_stream/asr/asr_event.py +18 -0
- rasa/core/channels/voice_stream/asr/azure.py +130 -0
- rasa/core/channels/voice_stream/asr/deepgram.py +90 -0
- rasa/core/channels/voice_stream/audio_bytes.py +8 -0
- rasa/core/channels/voice_stream/browser_audio.py +107 -0
- rasa/core/channels/voice_stream/call_state.py +23 -0
- rasa/core/channels/voice_stream/tts/__init__.py +0 -0
- rasa/core/channels/voice_stream/tts/azure.py +106 -0
- rasa/core/channels/voice_stream/tts/cartesia.py +118 -0
- rasa/core/channels/voice_stream/tts/tts_cache.py +27 -0
- rasa/core/channels/voice_stream/tts/tts_engine.py +58 -0
- rasa/core/channels/voice_stream/twilio_media_streams.py +173 -0
- rasa/core/channels/voice_stream/util.py +57 -0
- rasa/core/channels/voice_stream/voice_channel.py +427 -0
- rasa/core/channels/webexteams.py +134 -0
- rasa/core/concurrent_lock_store.py +210 -0
- rasa/core/constants.py +112 -0
- rasa/core/evaluation/__init__.py +0 -0
- rasa/core/evaluation/marker.py +267 -0
- rasa/core/evaluation/marker_base.py +923 -0
- rasa/core/evaluation/marker_stats.py +293 -0
- rasa/core/evaluation/marker_tracker_loader.py +103 -0
- rasa/core/exceptions.py +29 -0
- rasa/core/exporter.py +284 -0
- rasa/core/featurizers/__init__.py +0 -0
- rasa/core/featurizers/precomputation.py +410 -0
- rasa/core/featurizers/single_state_featurizer.py +421 -0
- rasa/core/featurizers/tracker_featurizers.py +1262 -0
- rasa/core/http_interpreter.py +89 -0
- rasa/core/information_retrieval/__init__.py +7 -0
- rasa/core/information_retrieval/faiss.py +124 -0
- rasa/core/information_retrieval/information_retrieval.py +137 -0
- rasa/core/information_retrieval/milvus.py +59 -0
- rasa/core/information_retrieval/qdrant.py +96 -0
- rasa/core/jobs.py +63 -0
- rasa/core/lock.py +139 -0
- rasa/core/lock_store.py +343 -0
- rasa/core/migrate.py +403 -0
- rasa/core/nlg/__init__.py +3 -0
- rasa/core/nlg/callback.py +146 -0
- rasa/core/nlg/contextual_response_rephraser.py +320 -0
- rasa/core/nlg/generator.py +230 -0
- rasa/core/nlg/interpolator.py +143 -0
- rasa/core/nlg/response.py +155 -0
- rasa/core/nlg/summarize.py +70 -0
- rasa/core/persistor.py +538 -0
- rasa/core/policies/__init__.py +0 -0
- rasa/core/policies/ensemble.py +329 -0
- rasa/core/policies/enterprise_search_policy.py +905 -0
- rasa/core/policies/enterprise_search_prompt_template.jinja2 +25 -0
- rasa/core/policies/enterprise_search_prompt_with_citation_template.jinja2 +60 -0
- rasa/core/policies/flow_policy.py +205 -0
- rasa/core/policies/flows/__init__.py +0 -0
- rasa/core/policies/flows/flow_exceptions.py +44 -0
- rasa/core/policies/flows/flow_executor.py +754 -0
- rasa/core/policies/flows/flow_step_result.py +43 -0
- rasa/core/policies/intentless_policy.py +1031 -0
- rasa/core/policies/intentless_prompt_template.jinja2 +22 -0
- rasa/core/policies/memoization.py +538 -0
- rasa/core/policies/policy.py +725 -0
- rasa/core/policies/rule_policy.py +1273 -0
- rasa/core/policies/ted_policy.py +2169 -0
- rasa/core/policies/unexpected_intent_policy.py +1022 -0
- rasa/core/processor.py +1465 -0
- rasa/core/run.py +342 -0
- rasa/core/secrets_manager/__init__.py +0 -0
- rasa/core/secrets_manager/constants.py +36 -0
- rasa/core/secrets_manager/endpoints.py +391 -0
- rasa/core/secrets_manager/factory.py +241 -0
- rasa/core/secrets_manager/secret_manager.py +262 -0
- rasa/core/secrets_manager/vault.py +584 -0
- rasa/core/test.py +1335 -0
- rasa/core/tracker_store.py +1703 -0
- rasa/core/train.py +105 -0
- rasa/core/training/__init__.py +89 -0
- rasa/core/training/converters/__init__.py +0 -0
- rasa/core/training/converters/responses_prefix_converter.py +119 -0
- rasa/core/training/interactive.py +1744 -0
- rasa/core/training/story_conflict.py +381 -0
- rasa/core/training/training.py +93 -0
- rasa/core/utils.py +366 -0
- rasa/core/visualize.py +70 -0
- rasa/dialogue_understanding/__init__.py +0 -0
- rasa/dialogue_understanding/coexistence/__init__.py +0 -0
- rasa/dialogue_understanding/coexistence/constants.py +4 -0
- rasa/dialogue_understanding/coexistence/intent_based_router.py +196 -0
- rasa/dialogue_understanding/coexistence/llm_based_router.py +327 -0
- rasa/dialogue_understanding/coexistence/router_template.jinja2 +12 -0
- rasa/dialogue_understanding/commands/__init__.py +61 -0
- rasa/dialogue_understanding/commands/can_not_handle_command.py +70 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +125 -0
- rasa/dialogue_understanding/commands/change_flow_command.py +44 -0
- rasa/dialogue_understanding/commands/chit_chat_answer_command.py +57 -0
- rasa/dialogue_understanding/commands/clarify_command.py +86 -0
- rasa/dialogue_understanding/commands/command.py +85 -0
- rasa/dialogue_understanding/commands/correct_slots_command.py +297 -0
- rasa/dialogue_understanding/commands/error_command.py +79 -0
- rasa/dialogue_understanding/commands/free_form_answer_command.py +9 -0
- rasa/dialogue_understanding/commands/handle_code_change_command.py +73 -0
- rasa/dialogue_understanding/commands/human_handoff_command.py +66 -0
- rasa/dialogue_understanding/commands/knowledge_answer_command.py +57 -0
- rasa/dialogue_understanding/commands/noop_command.py +54 -0
- rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +60 -0
- rasa/dialogue_understanding/commands/restart_command.py +58 -0
- rasa/dialogue_understanding/commands/session_end_command.py +61 -0
- rasa/dialogue_understanding/commands/session_start_command.py +59 -0
- rasa/dialogue_understanding/commands/set_slot_command.py +160 -0
- rasa/dialogue_understanding/commands/skip_question_command.py +75 -0
- rasa/dialogue_understanding/commands/start_flow_command.py +107 -0
- rasa/dialogue_understanding/commands/user_silence_command.py +59 -0
- rasa/dialogue_understanding/commands/utils.py +45 -0
- rasa/dialogue_understanding/generator/__init__.py +21 -0
- rasa/dialogue_understanding/generator/command_generator.py +464 -0
- rasa/dialogue_understanding/generator/constants.py +27 -0
- rasa/dialogue_understanding/generator/flow_document_template.jinja2 +4 -0
- rasa/dialogue_understanding/generator/flow_retrieval.py +466 -0
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +500 -0
- rasa/dialogue_understanding/generator/llm_command_generator.py +67 -0
- rasa/dialogue_understanding/generator/multi_step/__init__.py +0 -0
- rasa/dialogue_understanding/generator/multi_step/fill_slots_prompt.jinja2 +62 -0
- rasa/dialogue_understanding/generator/multi_step/handle_flows_prompt.jinja2 +38 -0
- rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +920 -0
- rasa/dialogue_understanding/generator/nlu_command_adapter.py +261 -0
- rasa/dialogue_understanding/generator/single_step/__init__.py +0 -0
- rasa/dialogue_understanding/generator/single_step/command_prompt_template.jinja2 +60 -0
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +486 -0
- rasa/dialogue_understanding/patterns/__init__.py +0 -0
- rasa/dialogue_understanding/patterns/cancel.py +111 -0
- rasa/dialogue_understanding/patterns/cannot_handle.py +43 -0
- rasa/dialogue_understanding/patterns/chitchat.py +37 -0
- rasa/dialogue_understanding/patterns/clarify.py +97 -0
- rasa/dialogue_understanding/patterns/code_change.py +41 -0
- rasa/dialogue_understanding/patterns/collect_information.py +90 -0
- rasa/dialogue_understanding/patterns/completed.py +40 -0
- rasa/dialogue_understanding/patterns/continue_interrupted.py +42 -0
- rasa/dialogue_understanding/patterns/correction.py +278 -0
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +301 -0
- rasa/dialogue_understanding/patterns/human_handoff.py +37 -0
- rasa/dialogue_understanding/patterns/internal_error.py +47 -0
- rasa/dialogue_understanding/patterns/repeat.py +37 -0
- rasa/dialogue_understanding/patterns/restart.py +37 -0
- rasa/dialogue_understanding/patterns/search.py +37 -0
- rasa/dialogue_understanding/patterns/session_start.py +37 -0
- rasa/dialogue_understanding/patterns/skip_question.py +38 -0
- rasa/dialogue_understanding/patterns/user_silence.py +37 -0
- rasa/dialogue_understanding/processor/__init__.py +0 -0
- rasa/dialogue_understanding/processor/command_processor.py +720 -0
- rasa/dialogue_understanding/processor/command_processor_component.py +43 -0
- rasa/dialogue_understanding/stack/__init__.py +0 -0
- rasa/dialogue_understanding/stack/dialogue_stack.py +178 -0
- rasa/dialogue_understanding/stack/frames/__init__.py +19 -0
- rasa/dialogue_understanding/stack/frames/chit_chat_frame.py +27 -0
- rasa/dialogue_understanding/stack/frames/dialogue_stack_frame.py +137 -0
- rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +157 -0
- rasa/dialogue_understanding/stack/frames/pattern_frame.py +10 -0
- rasa/dialogue_understanding/stack/frames/search_frame.py +27 -0
- rasa/dialogue_understanding/stack/utils.py +211 -0
- rasa/dialogue_understanding/utils.py +14 -0
- rasa/dialogue_understanding_test/__init__.py +0 -0
- rasa/dialogue_understanding_test/command_metric_calculation.py +12 -0
- rasa/dialogue_understanding_test/constants.py +17 -0
- rasa/dialogue_understanding_test/du_test_case.py +118 -0
- rasa/dialogue_understanding_test/du_test_result.py +11 -0
- rasa/dialogue_understanding_test/du_test_runner.py +93 -0
- rasa/dialogue_understanding_test/io.py +54 -0
- rasa/dialogue_understanding_test/validation.py +22 -0
- rasa/e2e_test/__init__.py +0 -0
- rasa/e2e_test/aggregate_test_stats_calculator.py +134 -0
- rasa/e2e_test/assertions.py +1345 -0
- rasa/e2e_test/assertions_schema.yml +129 -0
- rasa/e2e_test/constants.py +31 -0
- rasa/e2e_test/e2e_config.py +220 -0
- rasa/e2e_test/e2e_config_schema.yml +26 -0
- rasa/e2e_test/e2e_test_case.py +569 -0
- rasa/e2e_test/e2e_test_converter.py +363 -0
- rasa/e2e_test/e2e_test_converter_prompt.jinja2 +70 -0
- rasa/e2e_test/e2e_test_coverage_report.py +364 -0
- rasa/e2e_test/e2e_test_result.py +54 -0
- rasa/e2e_test/e2e_test_runner.py +1192 -0
- rasa/e2e_test/e2e_test_schema.yml +181 -0
- rasa/e2e_test/pykwalify_extensions.py +39 -0
- rasa/e2e_test/stub_custom_action.py +70 -0
- rasa/e2e_test/utils/__init__.py +0 -0
- rasa/e2e_test/utils/e2e_yaml_utils.py +55 -0
- rasa/e2e_test/utils/io.py +598 -0
- rasa/e2e_test/utils/validation.py +178 -0
- rasa/engine/__init__.py +0 -0
- rasa/engine/caching.py +463 -0
- rasa/engine/constants.py +17 -0
- rasa/engine/exceptions.py +14 -0
- rasa/engine/graph.py +642 -0
- rasa/engine/loader.py +48 -0
- rasa/engine/recipes/__init__.py +0 -0
- rasa/engine/recipes/config_files/default_config.yml +41 -0
- rasa/engine/recipes/default_components.py +97 -0
- rasa/engine/recipes/default_recipe.py +1272 -0
- rasa/engine/recipes/graph_recipe.py +79 -0
- rasa/engine/recipes/recipe.py +93 -0
- rasa/engine/runner/__init__.py +0 -0
- rasa/engine/runner/dask.py +250 -0
- rasa/engine/runner/interface.py +49 -0
- rasa/engine/storage/__init__.py +0 -0
- rasa/engine/storage/local_model_storage.py +244 -0
- rasa/engine/storage/resource.py +110 -0
- rasa/engine/storage/storage.py +199 -0
- rasa/engine/training/__init__.py +0 -0
- rasa/engine/training/components.py +176 -0
- rasa/engine/training/fingerprinting.py +64 -0
- rasa/engine/training/graph_trainer.py +256 -0
- rasa/engine/training/hooks.py +164 -0
- rasa/engine/validation.py +1451 -0
- rasa/env.py +14 -0
- rasa/exceptions.py +69 -0
- rasa/graph_components/__init__.py +0 -0
- rasa/graph_components/converters/__init__.py +0 -0
- rasa/graph_components/converters/nlu_message_converter.py +48 -0
- rasa/graph_components/providers/__init__.py +0 -0
- rasa/graph_components/providers/domain_for_core_training_provider.py +87 -0
- rasa/graph_components/providers/domain_provider.py +71 -0
- rasa/graph_components/providers/flows_provider.py +74 -0
- rasa/graph_components/providers/forms_provider.py +44 -0
- rasa/graph_components/providers/nlu_training_data_provider.py +56 -0
- rasa/graph_components/providers/responses_provider.py +44 -0
- rasa/graph_components/providers/rule_only_provider.py +49 -0
- rasa/graph_components/providers/story_graph_provider.py +96 -0
- rasa/graph_components/providers/training_tracker_provider.py +55 -0
- rasa/graph_components/validators/__init__.py +0 -0
- rasa/graph_components/validators/default_recipe_validator.py +550 -0
- rasa/graph_components/validators/finetuning_validator.py +302 -0
- rasa/hooks.py +111 -0
- rasa/jupyter.py +63 -0
- rasa/llm_fine_tuning/__init__.py +0 -0
- rasa/llm_fine_tuning/annotation_module.py +241 -0
- rasa/llm_fine_tuning/conversations.py +144 -0
- rasa/llm_fine_tuning/llm_data_preparation_module.py +178 -0
- rasa/llm_fine_tuning/paraphrasing/__init__.py +0 -0
- rasa/llm_fine_tuning/paraphrasing/conversation_rephraser.py +281 -0
- rasa/llm_fine_tuning/paraphrasing/default_rephrase_prompt_template.jina2 +44 -0
- rasa/llm_fine_tuning/paraphrasing/rephrase_validator.py +121 -0
- rasa/llm_fine_tuning/paraphrasing/rephrased_user_message.py +10 -0
- rasa/llm_fine_tuning/paraphrasing_module.py +128 -0
- rasa/llm_fine_tuning/storage.py +174 -0
- rasa/llm_fine_tuning/train_test_split_module.py +441 -0
- rasa/markers/__init__.py +0 -0
- rasa/markers/marker.py +269 -0
- rasa/markers/marker_base.py +828 -0
- rasa/markers/upload.py +74 -0
- rasa/markers/validate.py +21 -0
- rasa/model.py +118 -0
- rasa/model_manager/__init__.py +0 -0
- rasa/model_manager/config.py +40 -0
- rasa/model_manager/model_api.py +559 -0
- rasa/model_manager/runner_service.py +286 -0
- rasa/model_manager/socket_bridge.py +146 -0
- rasa/model_manager/studio_jwt_auth.py +86 -0
- rasa/model_manager/trainer_service.py +325 -0
- rasa/model_manager/utils.py +87 -0
- rasa/model_manager/warm_rasa_process.py +187 -0
- rasa/model_service.py +112 -0
- rasa/model_testing.py +457 -0
- rasa/model_training.py +596 -0
- rasa/nlu/__init__.py +7 -0
- rasa/nlu/classifiers/__init__.py +3 -0
- rasa/nlu/classifiers/classifier.py +5 -0
- rasa/nlu/classifiers/diet_classifier.py +1881 -0
- rasa/nlu/classifiers/fallback_classifier.py +192 -0
- rasa/nlu/classifiers/keyword_intent_classifier.py +188 -0
- rasa/nlu/classifiers/logistic_regression_classifier.py +253 -0
- rasa/nlu/classifiers/mitie_intent_classifier.py +156 -0
- rasa/nlu/classifiers/regex_message_handler.py +56 -0
- rasa/nlu/classifiers/sklearn_intent_classifier.py +330 -0
- rasa/nlu/constants.py +77 -0
- rasa/nlu/convert.py +40 -0
- rasa/nlu/emulators/__init__.py +0 -0
- rasa/nlu/emulators/dialogflow.py +55 -0
- rasa/nlu/emulators/emulator.py +49 -0
- rasa/nlu/emulators/luis.py +86 -0
- rasa/nlu/emulators/no_emulator.py +10 -0
- rasa/nlu/emulators/wit.py +56 -0
- rasa/nlu/extractors/__init__.py +0 -0
- rasa/nlu/extractors/crf_entity_extractor.py +715 -0
- rasa/nlu/extractors/duckling_entity_extractor.py +206 -0
- rasa/nlu/extractors/entity_synonyms.py +178 -0
- rasa/nlu/extractors/extractor.py +470 -0
- rasa/nlu/extractors/mitie_entity_extractor.py +293 -0
- rasa/nlu/extractors/regex_entity_extractor.py +220 -0
- rasa/nlu/extractors/spacy_entity_extractor.py +95 -0
- rasa/nlu/featurizers/__init__.py +0 -0
- rasa/nlu/featurizers/dense_featurizer/__init__.py +0 -0
- rasa/nlu/featurizers/dense_featurizer/convert_featurizer.py +445 -0
- rasa/nlu/featurizers/dense_featurizer/dense_featurizer.py +57 -0
- rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py +768 -0
- rasa/nlu/featurizers/dense_featurizer/mitie_featurizer.py +170 -0
- rasa/nlu/featurizers/dense_featurizer/spacy_featurizer.py +132 -0
- rasa/nlu/featurizers/featurizer.py +89 -0
- rasa/nlu/featurizers/sparse_featurizer/__init__.py +0 -0
- rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +867 -0
- rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +571 -0
- rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +271 -0
- rasa/nlu/featurizers/sparse_featurizer/sparse_featurizer.py +9 -0
- rasa/nlu/model.py +24 -0
- rasa/nlu/run.py +27 -0
- rasa/nlu/selectors/__init__.py +0 -0
- rasa/nlu/selectors/response_selector.py +987 -0
- rasa/nlu/test.py +1940 -0
- rasa/nlu/tokenizers/__init__.py +0 -0
- rasa/nlu/tokenizers/jieba_tokenizer.py +148 -0
- rasa/nlu/tokenizers/mitie_tokenizer.py +75 -0
- rasa/nlu/tokenizers/spacy_tokenizer.py +72 -0
- rasa/nlu/tokenizers/tokenizer.py +239 -0
- rasa/nlu/tokenizers/whitespace_tokenizer.py +95 -0
- rasa/nlu/utils/__init__.py +35 -0
- rasa/nlu/utils/bilou_utils.py +462 -0
- rasa/nlu/utils/hugging_face/__init__.py +0 -0
- rasa/nlu/utils/hugging_face/registry.py +108 -0
- rasa/nlu/utils/hugging_face/transformers_pre_post_processors.py +311 -0
- rasa/nlu/utils/mitie_utils.py +113 -0
- rasa/nlu/utils/pattern_utils.py +168 -0
- rasa/nlu/utils/spacy_utils.py +310 -0
- rasa/plugin.py +90 -0
- rasa/server.py +1588 -0
- rasa/shared/__init__.py +0 -0
- rasa/shared/constants.py +311 -0
- rasa/shared/core/__init__.py +0 -0
- rasa/shared/core/command_payload_reader.py +109 -0
- rasa/shared/core/constants.py +180 -0
- rasa/shared/core/conversation.py +46 -0
- rasa/shared/core/domain.py +2172 -0
- rasa/shared/core/events.py +2559 -0
- rasa/shared/core/flows/__init__.py +7 -0
- rasa/shared/core/flows/flow.py +562 -0
- rasa/shared/core/flows/flow_path.py +84 -0
- rasa/shared/core/flows/flow_step.py +146 -0
- rasa/shared/core/flows/flow_step_links.py +319 -0
- rasa/shared/core/flows/flow_step_sequence.py +70 -0
- rasa/shared/core/flows/flows_list.py +258 -0
- rasa/shared/core/flows/flows_yaml_schema.json +303 -0
- rasa/shared/core/flows/nlu_trigger.py +117 -0
- rasa/shared/core/flows/steps/__init__.py +24 -0
- rasa/shared/core/flows/steps/action.py +56 -0
- rasa/shared/core/flows/steps/call.py +64 -0
- rasa/shared/core/flows/steps/collect.py +112 -0
- rasa/shared/core/flows/steps/constants.py +5 -0
- rasa/shared/core/flows/steps/continuation.py +36 -0
- rasa/shared/core/flows/steps/end.py +22 -0
- rasa/shared/core/flows/steps/internal.py +44 -0
- rasa/shared/core/flows/steps/link.py +51 -0
- rasa/shared/core/flows/steps/no_operation.py +48 -0
- rasa/shared/core/flows/steps/set_slots.py +50 -0
- rasa/shared/core/flows/steps/start.py +30 -0
- rasa/shared/core/flows/utils.py +39 -0
- rasa/shared/core/flows/validation.py +735 -0
- rasa/shared/core/flows/yaml_flows_io.py +405 -0
- rasa/shared/core/generator.py +908 -0
- rasa/shared/core/slot_mappings.py +526 -0
- rasa/shared/core/slots.py +654 -0
- rasa/shared/core/trackers.py +1183 -0
- rasa/shared/core/training_data/__init__.py +0 -0
- rasa/shared/core/training_data/loading.py +89 -0
- rasa/shared/core/training_data/story_reader/__init__.py +0 -0
- rasa/shared/core/training_data/story_reader/story_reader.py +129 -0
- rasa/shared/core/training_data/story_reader/story_step_builder.py +168 -0
- rasa/shared/core/training_data/story_reader/yaml_story_reader.py +888 -0
- rasa/shared/core/training_data/story_writer/__init__.py +0 -0
- rasa/shared/core/training_data/story_writer/story_writer.py +76 -0
- rasa/shared/core/training_data/story_writer/yaml_story_writer.py +444 -0
- rasa/shared/core/training_data/structures.py +858 -0
- rasa/shared/core/training_data/visualization.html +146 -0
- rasa/shared/core/training_data/visualization.py +603 -0
- rasa/shared/data.py +249 -0
- rasa/shared/engine/__init__.py +0 -0
- rasa/shared/engine/caching.py +26 -0
- rasa/shared/exceptions.py +167 -0
- rasa/shared/importers/__init__.py +0 -0
- rasa/shared/importers/importer.py +770 -0
- rasa/shared/importers/multi_project.py +215 -0
- rasa/shared/importers/rasa.py +108 -0
- rasa/shared/importers/remote_importer.py +196 -0
- rasa/shared/importers/utils.py +36 -0
- rasa/shared/nlu/__init__.py +0 -0
- rasa/shared/nlu/constants.py +53 -0
- rasa/shared/nlu/interpreter.py +10 -0
- rasa/shared/nlu/training_data/__init__.py +0 -0
- rasa/shared/nlu/training_data/entities_parser.py +208 -0
- rasa/shared/nlu/training_data/features.py +492 -0
- rasa/shared/nlu/training_data/formats/__init__.py +10 -0
- rasa/shared/nlu/training_data/formats/dialogflow.py +163 -0
- rasa/shared/nlu/training_data/formats/luis.py +87 -0
- rasa/shared/nlu/training_data/formats/rasa.py +135 -0
- rasa/shared/nlu/training_data/formats/rasa_yaml.py +618 -0
- rasa/shared/nlu/training_data/formats/readerwriter.py +244 -0
- rasa/shared/nlu/training_data/formats/wit.py +52 -0
- rasa/shared/nlu/training_data/loading.py +137 -0
- rasa/shared/nlu/training_data/lookup_tables_parser.py +30 -0
- rasa/shared/nlu/training_data/message.py +490 -0
- rasa/shared/nlu/training_data/schemas/__init__.py +0 -0
- rasa/shared/nlu/training_data/schemas/data_schema.py +85 -0
- rasa/shared/nlu/training_data/schemas/nlu.yml +53 -0
- rasa/shared/nlu/training_data/schemas/responses.yml +70 -0
- rasa/shared/nlu/training_data/synonyms_parser.py +42 -0
- rasa/shared/nlu/training_data/training_data.py +729 -0
- rasa/shared/nlu/training_data/util.py +223 -0
- rasa/shared/providers/__init__.py +0 -0
- rasa/shared/providers/_configs/__init__.py +0 -0
- rasa/shared/providers/_configs/azure_openai_client_config.py +677 -0
- rasa/shared/providers/_configs/client_config.py +59 -0
- rasa/shared/providers/_configs/default_litellm_client_config.py +132 -0
- rasa/shared/providers/_configs/huggingface_local_embedding_client_config.py +236 -0
- rasa/shared/providers/_configs/litellm_router_client_config.py +222 -0
- rasa/shared/providers/_configs/model_group_config.py +173 -0
- rasa/shared/providers/_configs/openai_client_config.py +177 -0
- rasa/shared/providers/_configs/rasa_llm_client_config.py +75 -0
- rasa/shared/providers/_configs/self_hosted_llm_client_config.py +178 -0
- rasa/shared/providers/_configs/utils.py +117 -0
- rasa/shared/providers/_ssl_verification_utils.py +124 -0
- rasa/shared/providers/_utils.py +79 -0
- rasa/shared/providers/constants.py +7 -0
- rasa/shared/providers/embedding/__init__.py +0 -0
- rasa/shared/providers/embedding/_base_litellm_embedding_client.py +243 -0
- rasa/shared/providers/embedding/_langchain_embedding_client_adapter.py +74 -0
- rasa/shared/providers/embedding/azure_openai_embedding_client.py +335 -0
- rasa/shared/providers/embedding/default_litellm_embedding_client.py +126 -0
- rasa/shared/providers/embedding/embedding_client.py +90 -0
- rasa/shared/providers/embedding/embedding_response.py +41 -0
- rasa/shared/providers/embedding/huggingface_local_embedding_client.py +191 -0
- rasa/shared/providers/embedding/litellm_router_embedding_client.py +138 -0
- rasa/shared/providers/embedding/openai_embedding_client.py +172 -0
- rasa/shared/providers/llm/__init__.py +0 -0
- rasa/shared/providers/llm/_base_litellm_client.py +265 -0
- rasa/shared/providers/llm/azure_openai_llm_client.py +415 -0
- rasa/shared/providers/llm/default_litellm_llm_client.py +110 -0
- rasa/shared/providers/llm/litellm_router_llm_client.py +202 -0
- rasa/shared/providers/llm/llm_client.py +78 -0
- rasa/shared/providers/llm/llm_response.py +50 -0
- rasa/shared/providers/llm/openai_llm_client.py +161 -0
- rasa/shared/providers/llm/rasa_llm_client.py +120 -0
- rasa/shared/providers/llm/self_hosted_llm_client.py +276 -0
- rasa/shared/providers/mappings.py +94 -0
- rasa/shared/providers/router/__init__.py +0 -0
- rasa/shared/providers/router/_base_litellm_router_client.py +185 -0
- rasa/shared/providers/router/router_client.py +75 -0
- rasa/shared/utils/__init__.py +0 -0
- rasa/shared/utils/cli.py +102 -0
- rasa/shared/utils/common.py +324 -0
- rasa/shared/utils/constants.py +4 -0
- rasa/shared/utils/health_check/__init__.py +0 -0
- rasa/shared/utils/health_check/embeddings_health_check_mixin.py +31 -0
- rasa/shared/utils/health_check/health_check.py +258 -0
- rasa/shared/utils/health_check/llm_health_check_mixin.py +31 -0
- rasa/shared/utils/io.py +499 -0
- rasa/shared/utils/llm.py +764 -0
- rasa/shared/utils/pykwalify_extensions.py +27 -0
- rasa/shared/utils/schemas/__init__.py +0 -0
- rasa/shared/utils/schemas/config.yml +2 -0
- rasa/shared/utils/schemas/domain.yml +145 -0
- rasa/shared/utils/schemas/events.py +214 -0
- rasa/shared/utils/schemas/model_config.yml +36 -0
- rasa/shared/utils/schemas/stories.yml +173 -0
- rasa/shared/utils/yaml.py +1068 -0
- rasa/studio/__init__.py +0 -0
- rasa/studio/auth.py +270 -0
- rasa/studio/config.py +136 -0
- rasa/studio/constants.py +19 -0
- rasa/studio/data_handler.py +368 -0
- rasa/studio/download.py +489 -0
- rasa/studio/results_logger.py +137 -0
- rasa/studio/train.py +134 -0
- rasa/studio/upload.py +563 -0
- rasa/telemetry.py +1876 -0
- rasa/tracing/__init__.py +0 -0
- rasa/tracing/config.py +355 -0
- rasa/tracing/constants.py +62 -0
- rasa/tracing/instrumentation/__init__.py +0 -0
- rasa/tracing/instrumentation/attribute_extractors.py +765 -0
- rasa/tracing/instrumentation/instrumentation.py +1306 -0
- rasa/tracing/instrumentation/intentless_policy_instrumentation.py +144 -0
- rasa/tracing/instrumentation/metrics.py +294 -0
- rasa/tracing/metric_instrument_provider.py +205 -0
- rasa/utils/__init__.py +0 -0
- rasa/utils/beta.py +83 -0
- rasa/utils/cli.py +28 -0
- rasa/utils/common.py +639 -0
- rasa/utils/converter.py +53 -0
- rasa/utils/endpoints.py +331 -0
- rasa/utils/io.py +252 -0
- rasa/utils/json_utils.py +60 -0
- rasa/utils/licensing.py +542 -0
- rasa/utils/log_utils.py +181 -0
- rasa/utils/mapper.py +210 -0
- rasa/utils/ml_utils.py +147 -0
- rasa/utils/plotting.py +362 -0
- rasa/utils/sanic_error_handler.py +32 -0
- rasa/utils/singleton.py +23 -0
- rasa/utils/tensorflow/__init__.py +0 -0
- rasa/utils/tensorflow/callback.py +112 -0
- rasa/utils/tensorflow/constants.py +116 -0
- rasa/utils/tensorflow/crf.py +492 -0
- rasa/utils/tensorflow/data_generator.py +440 -0
- rasa/utils/tensorflow/environment.py +161 -0
- rasa/utils/tensorflow/exceptions.py +5 -0
- rasa/utils/tensorflow/feature_array.py +366 -0
- rasa/utils/tensorflow/layers.py +1565 -0
- rasa/utils/tensorflow/layers_utils.py +113 -0
- rasa/utils/tensorflow/metrics.py +281 -0
- rasa/utils/tensorflow/model_data.py +798 -0
- rasa/utils/tensorflow/model_data_utils.py +499 -0
- rasa/utils/tensorflow/models.py +935 -0
- rasa/utils/tensorflow/rasa_layers.py +1094 -0
- rasa/utils/tensorflow/transformer.py +640 -0
- rasa/utils/tensorflow/types.py +6 -0
- rasa/utils/train_utils.py +572 -0
- rasa/utils/url_tools.py +53 -0
- rasa/utils/yaml.py +54 -0
- rasa/validator.py +1644 -0
- rasa/version.py +3 -0
- rasa_pro-3.12.0.dev1.dist-info/METADATA +199 -0
- rasa_pro-3.12.0.dev1.dist-info/NOTICE +5 -0
- rasa_pro-3.12.0.dev1.dist-info/RECORD +790 -0
- rasa_pro-3.12.0.dev1.dist-info/WHEEL +4 -0
- rasa_pro-3.12.0.dev1.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,1068 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
import datetime
|
|
3
|
+
import io
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
from collections import OrderedDict
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from dataclasses import field
|
|
10
|
+
from functools import lru_cache
|
|
11
|
+
from io import StringIO
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Generator, List, Optional, Tuple, Dict, Callable, Union
|
|
14
|
+
|
|
15
|
+
import jsonschema
|
|
16
|
+
from importlib_resources import files
|
|
17
|
+
from packaging import version
|
|
18
|
+
from pykwalify.core import Core
|
|
19
|
+
from pykwalify.errors import SchemaError
|
|
20
|
+
from rasa.shared.constants import (
|
|
21
|
+
ASSERTIONS_SCHEMA_EXTENSIONS_FILE,
|
|
22
|
+
ASSERTIONS_SCHEMA_FILE,
|
|
23
|
+
MODEL_CONFIG_SCHEMA_FILE,
|
|
24
|
+
CONFIG_SCHEMA_FILE,
|
|
25
|
+
DOCS_URL_TRAINING_DATA,
|
|
26
|
+
PACKAGE_NAME,
|
|
27
|
+
LATEST_TRAINING_DATA_FORMAT_VERSION,
|
|
28
|
+
SCHEMA_EXTENSIONS_FILE,
|
|
29
|
+
RESPONSES_SCHEMA_FILE,
|
|
30
|
+
SENSITIVE_DATA,
|
|
31
|
+
)
|
|
32
|
+
from rasa.shared.exceptions import (
|
|
33
|
+
YamlException,
|
|
34
|
+
YamlSyntaxException,
|
|
35
|
+
SchemaValidationError,
|
|
36
|
+
RasaException,
|
|
37
|
+
FileNotFoundException,
|
|
38
|
+
)
|
|
39
|
+
from rasa.shared.utils.constants import (
|
|
40
|
+
DEFAULT_ENCODING,
|
|
41
|
+
READ_YAML_FILE_CACHE_MAXSIZE_ENV_VAR,
|
|
42
|
+
DEFAULT_READ_YAML_FILE_CACHE_MAXSIZE,
|
|
43
|
+
)
|
|
44
|
+
from rasa.shared.utils.io import (
|
|
45
|
+
read_file,
|
|
46
|
+
convert_to_ordered_dict,
|
|
47
|
+
raise_warning,
|
|
48
|
+
read_json_file,
|
|
49
|
+
)
|
|
50
|
+
from ruamel import yaml as yaml
|
|
51
|
+
from ruamel.yaml import YAML, RoundTripRepresenter, YAMLError
|
|
52
|
+
from ruamel.yaml.comments import CommentedSeq, CommentedMap
|
|
53
|
+
from ruamel.yaml.constructor import DuplicateKeyError, BaseConstructor, ScalarNode
|
|
54
|
+
from ruamel.yaml.loader import SafeLoader
|
|
55
|
+
|
|
56
|
+
logger = logging.getLogger(__name__)
|
|
57
|
+
|
|
58
|
+
KEY_TRAINING_DATA_FORMAT_VERSION = "version"
|
|
59
|
+
YAML_VERSION = (1, 2)
|
|
60
|
+
READ_YAML_FILE_CACHE_MAXSIZE = os.environ.get(
|
|
61
|
+
READ_YAML_FILE_CACHE_MAXSIZE_ENV_VAR, DEFAULT_READ_YAML_FILE_CACHE_MAXSIZE
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class PathWithError:
|
|
67
|
+
"""Represents a validation error at a specific location in the YAML content.
|
|
68
|
+
|
|
69
|
+
Attributes:
|
|
70
|
+
message (str): A description of the validation error.
|
|
71
|
+
path (List[str]): Path to the node where the error occurred.
|
|
72
|
+
key (Optional[str]): The specific key associated with the error, if any.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
message: str
|
|
76
|
+
path: List[str] = field(default_factory=list)
|
|
77
|
+
key: Optional[str] = None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def fix_yaml_loader() -> None:
|
|
81
|
+
"""Ensure that any string read by yaml is represented as unicode."""
|
|
82
|
+
|
|
83
|
+
def construct_yaml_str(self: BaseConstructor, node: ScalarNode) -> Any:
|
|
84
|
+
# Override the default string handling function
|
|
85
|
+
# to always return unicode objects
|
|
86
|
+
return self.construct_scalar(node)
|
|
87
|
+
|
|
88
|
+
yaml.Loader.add_constructor("tag:yaml.org,2002:str", construct_yaml_str)
|
|
89
|
+
yaml.SafeLoader.add_constructor("tag:yaml.org,2002:str", construct_yaml_str)
|
|
90
|
+
|
|
91
|
+
_add_env_var_resolver()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _add_env_var_resolver() -> None:
|
|
95
|
+
"""Enable yaml loader to detect the environment variables in the yaml."""
|
|
96
|
+
# eg. ${USER_NAME}, ${PASSWORD}
|
|
97
|
+
env_var_pattern = re.compile(r"^(.*)\$\{(.*)\}(.*)$")
|
|
98
|
+
yaml.Resolver.add_implicit_resolver("!env_var", env_var_pattern, None)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _add_yaml_constructor_to_replace_environment_variables() -> None:
|
|
102
|
+
"""Enable yaml loader to replace the environment variables in the yaml."""
|
|
103
|
+
|
|
104
|
+
def env_var_constructor(loader: BaseConstructor, node: ScalarNode) -> str:
|
|
105
|
+
"""Process environment variables found in the YAML."""
|
|
106
|
+
value = loader.construct_scalar(node)
|
|
107
|
+
|
|
108
|
+
# get key of current node
|
|
109
|
+
key_node = list(loader.constructed_objects)[-1]
|
|
110
|
+
if isinstance(key_node, ScalarNode) and key_node.value in SENSITIVE_DATA:
|
|
111
|
+
return value
|
|
112
|
+
|
|
113
|
+
expanded_vars = os.path.expandvars(value)
|
|
114
|
+
not_expanded = [
|
|
115
|
+
w for w in expanded_vars.split() if w.startswith("$") and w in value
|
|
116
|
+
]
|
|
117
|
+
if not_expanded:
|
|
118
|
+
raise RasaException(
|
|
119
|
+
f"Error when trying to expand the "
|
|
120
|
+
f"environment variables in '{value}'. "
|
|
121
|
+
f"Please make sure to also set these "
|
|
122
|
+
f"environment variables: '{not_expanded}'."
|
|
123
|
+
)
|
|
124
|
+
return expanded_vars
|
|
125
|
+
|
|
126
|
+
yaml.SafeConstructor.add_constructor("!env_var", env_var_constructor)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
fix_yaml_loader()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class YamlValidationException(YamlException, ValueError):
|
|
133
|
+
"""Raised if a yaml file does not correspond to the expected schema."""
|
|
134
|
+
|
|
135
|
+
def __init__(
|
|
136
|
+
self,
|
|
137
|
+
message: str,
|
|
138
|
+
validation_errors: Optional[List[PathWithError]] = None,
|
|
139
|
+
filename: Optional[str] = None,
|
|
140
|
+
content: Any = None,
|
|
141
|
+
) -> None:
|
|
142
|
+
"""Create The Error.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
message: error message
|
|
146
|
+
validation_errors: validation errors
|
|
147
|
+
filename: name of the file which was validated
|
|
148
|
+
content: yaml content loaded from the file (used for line information)
|
|
149
|
+
"""
|
|
150
|
+
super(YamlValidationException, self).__init__(filename)
|
|
151
|
+
|
|
152
|
+
self.message = message
|
|
153
|
+
self.validation_errors = validation_errors
|
|
154
|
+
self.content = content
|
|
155
|
+
|
|
156
|
+
def __str__(self) -> str:
|
|
157
|
+
msg = self.file_error_message()
|
|
158
|
+
msg += " Failed to validate YAML. "
|
|
159
|
+
msg += self.message
|
|
160
|
+
if self.validation_errors:
|
|
161
|
+
unique_errors = {}
|
|
162
|
+
for error in self.validation_errors:
|
|
163
|
+
line_number = self._line_number_for_path(
|
|
164
|
+
self.content, error.path, error.key
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
if line_number and self.filename:
|
|
168
|
+
error_location = f" in {self.filename}:{line_number}:\n"
|
|
169
|
+
elif line_number:
|
|
170
|
+
error_location = f" in Line {line_number}:\n"
|
|
171
|
+
else:
|
|
172
|
+
error_location = ""
|
|
173
|
+
|
|
174
|
+
code_snippet = self._get_code_snippet(line_number)
|
|
175
|
+
error_message = f"{error_location}\n{code_snippet}{error.message}\n"
|
|
176
|
+
unique_errors[error.message] = error_message
|
|
177
|
+
error_msg = "\n".join(unique_errors.values())
|
|
178
|
+
msg += f":\n{error_msg}"
|
|
179
|
+
return msg
|
|
180
|
+
|
|
181
|
+
def _get_code_snippet(
|
|
182
|
+
self,
|
|
183
|
+
error_line: Optional[int],
|
|
184
|
+
context_lines: int = 2,
|
|
185
|
+
) -> str:
|
|
186
|
+
"""Extract code snippet from the YAML lines around the error.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
error_line: Line number where the error occurred (1-based).
|
|
190
|
+
context_lines: Number of context lines before and after the error line.
|
|
191
|
+
Default is 2, balancing context and readability. Adjust as needed.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
A string containing the code snippet with the error highlighted.
|
|
195
|
+
"""
|
|
196
|
+
yaml_lines = self._get_serialized_yaml_lines()
|
|
197
|
+
if not yaml_lines or error_line is None:
|
|
198
|
+
return ""
|
|
199
|
+
|
|
200
|
+
start = max(error_line - context_lines - 1, 0)
|
|
201
|
+
end = min(error_line + context_lines, len(yaml_lines))
|
|
202
|
+
snippet_lines = yaml_lines[start:end]
|
|
203
|
+
snippet = ""
|
|
204
|
+
for idx, line_content in enumerate(snippet_lines, start=start + 1):
|
|
205
|
+
prefix = ">>> " if idx == error_line else " "
|
|
206
|
+
line_number_str = str(idx)
|
|
207
|
+
snippet += f"{prefix}{line_number_str} | {line_content}\n"
|
|
208
|
+
return snippet
|
|
209
|
+
|
|
210
|
+
def _get_serialized_yaml_lines(self) -> List[str]:
|
|
211
|
+
"""Serialize the content back to YAML and return the lines."""
|
|
212
|
+
yaml_lines = []
|
|
213
|
+
try:
|
|
214
|
+
yaml = YAML()
|
|
215
|
+
yaml.default_flow_style = False
|
|
216
|
+
# Set width to 1000, so we don't break the lines of the original YAML file
|
|
217
|
+
yaml.width = 1000 # type: ignore[assignment]
|
|
218
|
+
yaml.indent(mapping=2, sequence=4, offset=2)
|
|
219
|
+
stream = io.StringIO()
|
|
220
|
+
yaml.dump(self.content, stream)
|
|
221
|
+
serialized_yaml = stream.getvalue()
|
|
222
|
+
yaml_lines = serialized_yaml.splitlines()
|
|
223
|
+
return yaml_lines
|
|
224
|
+
except Exception as exc:
|
|
225
|
+
logger.debug(f"Error serializing YAML content: {exc}")
|
|
226
|
+
|
|
227
|
+
return yaml_lines
|
|
228
|
+
|
|
229
|
+
def _calculate_number_of_lines(
|
|
230
|
+
self,
|
|
231
|
+
current: Union[CommentedSeq, CommentedMap],
|
|
232
|
+
target: Optional[str] = None,
|
|
233
|
+
) -> Tuple[int, bool]:
|
|
234
|
+
"""Counts the lines that are missing due to the ruamel yaml parser logic.
|
|
235
|
+
|
|
236
|
+
Since not all nodes returned from the ruamel yaml parser
|
|
237
|
+
have line numbers attached (arrays have them, dicts have
|
|
238
|
+
them, but strings don't), this method calculates the number
|
|
239
|
+
of lines that are missing instead of just returning line of the parent element
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
current: current content
|
|
243
|
+
target: target key to find the line number of
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
A tuple containing a number of missing lines
|
|
247
|
+
and a flag indicating if an element with a line number was found
|
|
248
|
+
"""
|
|
249
|
+
if isinstance(current, list):
|
|
250
|
+
# return the line number of the last list element
|
|
251
|
+
line_number = current[-1].lc.line + 1
|
|
252
|
+
logger.debug(f"Returning from list: last element at {line_number}")
|
|
253
|
+
return line_number, True
|
|
254
|
+
|
|
255
|
+
keys_to_check = list(current.keys())
|
|
256
|
+
if target:
|
|
257
|
+
# If target is specified, only check keys before it
|
|
258
|
+
keys_to_check = keys_to_check[: keys_to_check.index(target)]
|
|
259
|
+
try:
|
|
260
|
+
# find the last key that has a line number attached
|
|
261
|
+
last_key_with_lc = next(
|
|
262
|
+
iter(
|
|
263
|
+
[
|
|
264
|
+
key
|
|
265
|
+
for key in reversed(keys_to_check)
|
|
266
|
+
if hasattr(current[key], "lc")
|
|
267
|
+
]
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
logger.debug(f"Last key with line number: {last_key_with_lc}")
|
|
271
|
+
except StopIteration:
|
|
272
|
+
# otherwise return the number of elements on that level up to the target
|
|
273
|
+
logger.debug(f"No line number found in {current}")
|
|
274
|
+
if target:
|
|
275
|
+
return list(current.keys()).index(target), False
|
|
276
|
+
return len(list(current.keys())), False
|
|
277
|
+
|
|
278
|
+
offset = current[last_key_with_lc].lc.line if not target else 0
|
|
279
|
+
# Recursively calculate the number of lines
|
|
280
|
+
# for the element associated with the last key with a line number
|
|
281
|
+
child_offset, found_lc = self._calculate_number_of_lines(
|
|
282
|
+
current[last_key_with_lc]
|
|
283
|
+
)
|
|
284
|
+
if not found_lc:
|
|
285
|
+
child_offset += offset
|
|
286
|
+
if target:
|
|
287
|
+
child_offset += 1
|
|
288
|
+
# add the number of trailing keys without line numbers to the offset
|
|
289
|
+
last_idx_with_lc = keys_to_check.index(last_key_with_lc)
|
|
290
|
+
child_offset += len(keys_to_check[last_idx_with_lc + 1 :])
|
|
291
|
+
|
|
292
|
+
logger.debug(f"Analysed {current}, found {child_offset} lines")
|
|
293
|
+
# Return the calculated child offset and True indicating a line number was found
|
|
294
|
+
return child_offset, True
|
|
295
|
+
|
|
296
|
+
def _line_number_for_path(
|
|
297
|
+
self, current: Any, path: List[str], key: Optional[str] = None
|
|
298
|
+
) -> Optional[int]:
|
|
299
|
+
"""Get line number for a yaml path in the current content.
|
|
300
|
+
|
|
301
|
+
Implemented using recursion: algorithm goes down the path navigating to the
|
|
302
|
+
leaf in the YAML tree.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
current: current content
|
|
306
|
+
path: path to traverse within the content
|
|
307
|
+
key: the key associated with the error, if any
|
|
308
|
+
|
|
309
|
+
Returns:
|
|
310
|
+
the line number of the path in the content.
|
|
311
|
+
"""
|
|
312
|
+
if not current:
|
|
313
|
+
return None
|
|
314
|
+
|
|
315
|
+
this_line = current.lc.line + 1 if hasattr(current, "lc") else None
|
|
316
|
+
|
|
317
|
+
if not path:
|
|
318
|
+
if key and hasattr(current, "lc"):
|
|
319
|
+
if hasattr(current.lc, "data") and key in current.lc.data:
|
|
320
|
+
key_line_no = current.lc.data[key][0] + 1
|
|
321
|
+
return key_line_no
|
|
322
|
+
return this_line
|
|
323
|
+
|
|
324
|
+
head, tail = path[0], path[1:]
|
|
325
|
+
|
|
326
|
+
if head == "":
|
|
327
|
+
return current.lc.line
|
|
328
|
+
|
|
329
|
+
if head:
|
|
330
|
+
if isinstance(current, dict) and head in current:
|
|
331
|
+
line = self._line_number_for_path(current[head], tail, key)
|
|
332
|
+
if line is None:
|
|
333
|
+
line_offset, found_lc = self._calculate_number_of_lines(
|
|
334
|
+
current, head
|
|
335
|
+
)
|
|
336
|
+
if found_lc:
|
|
337
|
+
return line_offset
|
|
338
|
+
return this_line + line_offset
|
|
339
|
+
return line
|
|
340
|
+
elif isinstance(current, list) and head.isdigit():
|
|
341
|
+
return (
|
|
342
|
+
self._line_number_for_path(current[int(head)], tail, key)
|
|
343
|
+
or this_line
|
|
344
|
+
)
|
|
345
|
+
else:
|
|
346
|
+
return this_line
|
|
347
|
+
return self._line_number_for_path(current, tail, key) or this_line
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def read_schema_file(
|
|
351
|
+
schema_file: str, package_name: str = PACKAGE_NAME, expand_env_vars: bool = True
|
|
352
|
+
) -> Union[List[Any], Dict[str, Any]]:
|
|
353
|
+
"""Read a schema file from the package.
|
|
354
|
+
|
|
355
|
+
Args:
|
|
356
|
+
schema_file: The schema file to read.
|
|
357
|
+
package_name: the name of the package the schema is located in. defaults
|
|
358
|
+
to `rasa`.
|
|
359
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
360
|
+
|
|
361
|
+
Returns:
|
|
362
|
+
The schema as a dictionary.
|
|
363
|
+
"""
|
|
364
|
+
schema_path = str(files(package_name).joinpath(schema_file))
|
|
365
|
+
return read_yaml_file(schema_path, expand_env_vars=expand_env_vars)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def parse_raw_yaml(raw_yaml_content: str) -> Dict[str, Any]:
|
|
369
|
+
"""Parses yaml from a text and raises an exception if the content is not valid.
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
raw_yaml_content: A raw text containing yaml content.
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
The parsed content of the YAML.
|
|
376
|
+
If the content is not valid, a `YamlSyntaxException` will be raised.
|
|
377
|
+
"""
|
|
378
|
+
try:
|
|
379
|
+
source_data = read_yaml(raw_yaml_content, reader_type=["safe", "rt"])
|
|
380
|
+
except (YAMLError, DuplicateKeyError) as e:
|
|
381
|
+
raise YamlSyntaxException(underlying_yaml_exception=e)
|
|
382
|
+
|
|
383
|
+
return source_data
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def validate_yaml_content_using_schema(
|
|
387
|
+
yaml_content: Any,
|
|
388
|
+
schema_content: Union[List[Any], Dict[str, Any]],
|
|
389
|
+
schema_extensions: Optional[List[str]] = None,
|
|
390
|
+
) -> None:
|
|
391
|
+
"""Validate yaml content using a schema with optional schema extensions.
|
|
392
|
+
|
|
393
|
+
Args:
|
|
394
|
+
yaml_content: the content of the YAML to be validated
|
|
395
|
+
schema_content: the content of the YAML schema
|
|
396
|
+
schema_extensions: pykwalify schema extension files
|
|
397
|
+
"""
|
|
398
|
+
log = logging.getLogger("pykwalify")
|
|
399
|
+
log.setLevel(logging.CRITICAL)
|
|
400
|
+
|
|
401
|
+
core = Core(
|
|
402
|
+
source_data=yaml_content,
|
|
403
|
+
schema_data=schema_content,
|
|
404
|
+
extensions=schema_extensions,
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
try:
|
|
408
|
+
core.validate(raise_exception=True)
|
|
409
|
+
except SchemaError:
|
|
410
|
+
# PyKwalify propagates each validation error up the data hierarchy, resulting
|
|
411
|
+
# in multiple redundant errors for a single issue. To present a clear message
|
|
412
|
+
# about the root cause, we use only the first error.
|
|
413
|
+
error = core.errors[0]
|
|
414
|
+
|
|
415
|
+
# Increment numeric indices by 1 to convert from 0-based to 1-based indexing
|
|
416
|
+
error_message = re.sub(
|
|
417
|
+
r"(/)(\d+)", lambda m: f"/{int(m.group(2)) + 1}", str(error)
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
raise YamlValidationException(
|
|
421
|
+
"Please make sure the file is correct and all "
|
|
422
|
+
"mandatory parameters are specified. Here are the errors "
|
|
423
|
+
"found during validation",
|
|
424
|
+
[
|
|
425
|
+
PathWithError(
|
|
426
|
+
message=error_message,
|
|
427
|
+
path=error.path.removeprefix("/").split("/"),
|
|
428
|
+
key=getattr(error, "key", None),
|
|
429
|
+
)
|
|
430
|
+
],
|
|
431
|
+
content=yaml_content,
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def validate_raw_yaml_using_schema(
|
|
436
|
+
raw_yaml_content: str,
|
|
437
|
+
schema_content: Dict[str, Any],
|
|
438
|
+
schema_extensions: Optional[List[str]] = None,
|
|
439
|
+
expand_env_vars: bool = True,
|
|
440
|
+
) -> None:
|
|
441
|
+
"""Validate raw yaml content using a schema.
|
|
442
|
+
|
|
443
|
+
If the content is not valid, a `YamlSyntaxException` will be raised.
|
|
444
|
+
|
|
445
|
+
Args:
|
|
446
|
+
raw_yaml_content: the raw YAML content to be validated (usually a string)
|
|
447
|
+
schema_content: the schema for the yaml_file_content
|
|
448
|
+
schema_extensions: pykwalify schema extension files
|
|
449
|
+
expand_env_vars: Whether to expand environment variables.
|
|
450
|
+
"""
|
|
451
|
+
try:
|
|
452
|
+
# we need "rt" since
|
|
453
|
+
# it will add meta information to the parsed output. this meta information
|
|
454
|
+
# will include e.g. at which line an object was parsed. this is very
|
|
455
|
+
# helpful when we validate files later on and want to point the user to the
|
|
456
|
+
# right line
|
|
457
|
+
yaml_data = read_yaml(
|
|
458
|
+
raw_yaml_content,
|
|
459
|
+
reader_type=["safe", "rt"],
|
|
460
|
+
expand_env_vars=expand_env_vars,
|
|
461
|
+
)
|
|
462
|
+
except (YAMLError, DuplicateKeyError) as e:
|
|
463
|
+
raise YamlSyntaxException(underlying_yaml_exception=e)
|
|
464
|
+
|
|
465
|
+
validate_yaml_content_using_schema(yaml_data, schema_content, schema_extensions)
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def validate_raw_yaml_using_schema_file(
|
|
469
|
+
raw_yaml_content: str,
|
|
470
|
+
schema_path: str,
|
|
471
|
+
package_name: str = PACKAGE_NAME,
|
|
472
|
+
expand_env_vars: bool = True,
|
|
473
|
+
) -> None:
|
|
474
|
+
"""Validate raw yaml content using a schema from file.
|
|
475
|
+
|
|
476
|
+
Args:
|
|
477
|
+
raw_yaml_content: the raw YAML content to be validated (usually a string)
|
|
478
|
+
schema_path: the schema used for validation
|
|
479
|
+
package_name: the name of the package the schema is located in. defaults
|
|
480
|
+
to `rasa`.
|
|
481
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
482
|
+
"""
|
|
483
|
+
schema_content = read_schema_file(
|
|
484
|
+
schema_path, package_name, expand_env_vars=expand_env_vars
|
|
485
|
+
)
|
|
486
|
+
validate_raw_yaml_using_schema(
|
|
487
|
+
raw_yaml_content, schema_content, expand_env_vars=expand_env_vars
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def validate_raw_yaml_content_using_schema_with_responses(
|
|
492
|
+
raw_yaml_content: str,
|
|
493
|
+
schema_content: Union[List[Any], Dict[str, Any]],
|
|
494
|
+
package_name: str = PACKAGE_NAME,
|
|
495
|
+
expand_env_vars: bool = True,
|
|
496
|
+
) -> None:
|
|
497
|
+
"""Validate raw yaml content using a schema with responses sub-schema.
|
|
498
|
+
|
|
499
|
+
Args:
|
|
500
|
+
raw_yaml_content: the raw YAML content to be validated (usually a string)
|
|
501
|
+
schema_content: the content of the YAML schema
|
|
502
|
+
package_name: the name of the package the schema is located in. defaults
|
|
503
|
+
to `rasa`.
|
|
504
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
505
|
+
"""
|
|
506
|
+
# bot responses are part of the schema extension
|
|
507
|
+
# it will be included if the schema explicitly references it with include: responses
|
|
508
|
+
bot_responses_schema_content = read_schema_file(
|
|
509
|
+
RESPONSES_SCHEMA_FILE, package_name, expand_env_vars=expand_env_vars
|
|
510
|
+
)
|
|
511
|
+
schema_content = dict(schema_content, **bot_responses_schema_content)
|
|
512
|
+
schema_extensions = [str(files(package_name).joinpath(SCHEMA_EXTENSIONS_FILE))]
|
|
513
|
+
|
|
514
|
+
validate_raw_yaml_using_schema(
|
|
515
|
+
raw_yaml_content, schema_content, schema_extensions, expand_env_vars
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def validate_raw_yaml_using_schema_file_with_responses(
|
|
520
|
+
raw_yaml_content: str,
|
|
521
|
+
schema_path: str,
|
|
522
|
+
package_name: str = PACKAGE_NAME,
|
|
523
|
+
expand_env_vars: bool = True,
|
|
524
|
+
) -> None:
|
|
525
|
+
"""Validate domain yaml content using a schema from file with responses sub-schema.
|
|
526
|
+
|
|
527
|
+
Args:
|
|
528
|
+
raw_yaml_content: the raw YAML content to be validated (usually a string)
|
|
529
|
+
schema_path: the schema of the yaml file
|
|
530
|
+
package_name: the name of the package the schema is located in. defaults
|
|
531
|
+
to `rasa`.
|
|
532
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
533
|
+
"""
|
|
534
|
+
schema_content = read_schema_file(schema_path, package_name, expand_env_vars)
|
|
535
|
+
validate_raw_yaml_content_using_schema_with_responses(
|
|
536
|
+
raw_yaml_content, schema_content, package_name, expand_env_vars
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
@contextmanager
|
|
541
|
+
def environment_variables_replaced(
|
|
542
|
+
yaml_parser: yaml.YAML,
|
|
543
|
+
) -> Generator[None, None, None]:
|
|
544
|
+
"""Replace environment variables during yaml loading.
|
|
545
|
+
|
|
546
|
+
Resets the environment variable constructor after the context manager exits.
|
|
547
|
+
"""
|
|
548
|
+
try:
|
|
549
|
+
_add_yaml_constructor_to_replace_environment_variables()
|
|
550
|
+
yield
|
|
551
|
+
finally:
|
|
552
|
+
# replace env var constructor with one that does not expand env vars
|
|
553
|
+
yaml_parser.constructor.add_constructor(
|
|
554
|
+
"!env_var", lambda loader, node: loader.construct_scalar(node)
|
|
555
|
+
)
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def read_yaml(
|
|
559
|
+
content: str,
|
|
560
|
+
reader_type: Union[str, List[str]] = "safe",
|
|
561
|
+
**kwargs: Any,
|
|
562
|
+
) -> Any:
|
|
563
|
+
"""Parses yaml from a text.
|
|
564
|
+
|
|
565
|
+
Args:
|
|
566
|
+
content: A text containing yaml content.
|
|
567
|
+
reader_type: Reader type to use. By default, "safe" will be used.
|
|
568
|
+
**kwargs: Any
|
|
569
|
+
|
|
570
|
+
Raises:
|
|
571
|
+
ruamel.yaml.parser.ParserError: If there was an error when parsing the YAML.
|
|
572
|
+
"""
|
|
573
|
+
custom_constructor = kwargs.get("custom_constructor", None)
|
|
574
|
+
expand_env_vars = kwargs.get("expand_env_vars", True)
|
|
575
|
+
|
|
576
|
+
# Create YAML parser with custom constructor
|
|
577
|
+
yaml_parser, reset_constructors = create_yaml_parser(
|
|
578
|
+
reader_type, custom_constructor
|
|
579
|
+
)
|
|
580
|
+
if expand_env_vars:
|
|
581
|
+
with environment_variables_replaced(yaml_parser):
|
|
582
|
+
yaml_content = yaml_parser.load(content) or {}
|
|
583
|
+
else:
|
|
584
|
+
yaml_content = yaml_parser.load(content) or {}
|
|
585
|
+
|
|
586
|
+
# Reset to default constructors
|
|
587
|
+
reset_constructors()
|
|
588
|
+
|
|
589
|
+
return yaml_content
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def create_yaml_parser(
|
|
593
|
+
reader_type: str,
|
|
594
|
+
custom_constructor: Optional[Callable] = None,
|
|
595
|
+
) -> Tuple[yaml.YAML, Callable[[], None]]:
|
|
596
|
+
"""Create a YAML parser with an optional custom constructor.
|
|
597
|
+
|
|
598
|
+
Args:
|
|
599
|
+
reader_type (str): The type of the reader
|
|
600
|
+
(e.g., 'safe', 'rt', 'unsafe').
|
|
601
|
+
custom_constructor (Optional[Callable]):
|
|
602
|
+
A custom constructor function for YAML parsing.
|
|
603
|
+
|
|
604
|
+
Returns:
|
|
605
|
+
Tuple[yaml.YAML, Callable[[], None]]: A tuple containing
|
|
606
|
+
the YAML parser and a function to reset constructors to
|
|
607
|
+
their original state.
|
|
608
|
+
"""
|
|
609
|
+
yaml_parser = yaml.YAML(typ=reader_type)
|
|
610
|
+
yaml_parser.version = YAML_VERSION # type: ignore[assignment]
|
|
611
|
+
yaml_parser.preserve_quotes = True # type: ignore[assignment]
|
|
612
|
+
|
|
613
|
+
# Save the original constructors
|
|
614
|
+
original_mapping_constructor = yaml_parser.constructor.yaml_constructors.get(
|
|
615
|
+
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
|
|
616
|
+
)
|
|
617
|
+
original_sequence_constructor = yaml_parser.constructor.yaml_constructors.get(
|
|
618
|
+
yaml.resolver.BaseResolver.DEFAULT_SEQUENCE_TAG
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
if custom_constructor is not None:
|
|
622
|
+
# Attach the custom constructor to the loader
|
|
623
|
+
yaml_parser.constructor.add_constructor(
|
|
624
|
+
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, custom_constructor
|
|
625
|
+
)
|
|
626
|
+
yaml_parser.constructor.add_constructor(
|
|
627
|
+
yaml.resolver.BaseResolver.DEFAULT_SEQUENCE_TAG, custom_constructor
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
def reset_constructors() -> None:
|
|
631
|
+
"""Reset the constructors back to their original state."""
|
|
632
|
+
yaml_parser.constructor.add_constructor(
|
|
633
|
+
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, original_mapping_constructor
|
|
634
|
+
)
|
|
635
|
+
yaml_parser.constructor.add_constructor(
|
|
636
|
+
yaml.resolver.BaseResolver.DEFAULT_SEQUENCE_TAG,
|
|
637
|
+
original_sequence_constructor,
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
def custom_date_constructor(loader: SafeLoader, node: ScalarNode) -> str:
|
|
641
|
+
"""Custom constructor for parsing dates in the format '%Y-%m-%d'.
|
|
642
|
+
|
|
643
|
+
This constructor parses dates in the '%Y-%m-%d' format and returns them as
|
|
644
|
+
strings instead of datetime objects. This change was introduced because the
|
|
645
|
+
default timestamp constructor in ruamel.yaml returns datetime objects, which
|
|
646
|
+
caused issues in our use case where the `api_version` in the LLM config must
|
|
647
|
+
be a string, but was being interpreted as a datetime object.
|
|
648
|
+
"""
|
|
649
|
+
value = loader.construct_scalar(node)
|
|
650
|
+
try:
|
|
651
|
+
# Attempt to parse the date
|
|
652
|
+
date_obj = datetime.datetime.strptime(value, "%Y-%m-%d").date()
|
|
653
|
+
# Return the date as a string instead of a datetime object
|
|
654
|
+
return date_obj.strftime("%Y-%m-%d")
|
|
655
|
+
except ValueError:
|
|
656
|
+
# If the date is not in the correct format, return the original value
|
|
657
|
+
return value
|
|
658
|
+
|
|
659
|
+
# Add the custom date constructor
|
|
660
|
+
yaml_parser.constructor.add_constructor(
|
|
661
|
+
"tag:yaml.org,2002:timestamp", custom_date_constructor
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
return yaml_parser, reset_constructors
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
def _is_ascii(text: str) -> bool:
|
|
668
|
+
return all(ord(character) < 128 for character in text)
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
@lru_cache(maxsize=READ_YAML_FILE_CACHE_MAXSIZE)
|
|
672
|
+
def read_yaml_file(
|
|
673
|
+
filename: Union[str, Path],
|
|
674
|
+
reader_type: Union[str, Tuple[str]] = "safe",
|
|
675
|
+
expand_env_vars: bool = True,
|
|
676
|
+
) -> Union[List[Any], Dict[str, Any]]:
|
|
677
|
+
"""Parses a yaml file.
|
|
678
|
+
|
|
679
|
+
Raises an exception if the content of the file can not be parsed as YAML.
|
|
680
|
+
|
|
681
|
+
Args:
|
|
682
|
+
filename: The path to the file which should be read.
|
|
683
|
+
reader_type: Reader type to use. By default "safe" will be used.
|
|
684
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
685
|
+
|
|
686
|
+
Returns:
|
|
687
|
+
Parsed content of the file.
|
|
688
|
+
"""
|
|
689
|
+
try:
|
|
690
|
+
fixed_reader_type = (
|
|
691
|
+
list(reader_type) if isinstance(reader_type, tuple) else reader_type
|
|
692
|
+
)
|
|
693
|
+
return read_yaml(
|
|
694
|
+
read_file(filename, DEFAULT_ENCODING),
|
|
695
|
+
fixed_reader_type,
|
|
696
|
+
expand_env_vars=expand_env_vars,
|
|
697
|
+
)
|
|
698
|
+
except (YAMLError, DuplicateKeyError) as e:
|
|
699
|
+
raise YamlSyntaxException(filename, e)
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def read_config_file(
|
|
703
|
+
filename: Union[Path, str], reader_type: Union[str, List[str]] = "safe"
|
|
704
|
+
) -> Dict[str, Any]:
|
|
705
|
+
"""Parses a yaml configuration file. Content needs to be a dictionary.
|
|
706
|
+
|
|
707
|
+
Args:
|
|
708
|
+
filename: The path to the file which should be read.
|
|
709
|
+
reader_type: Reader type to use. By default "safe" will be used.
|
|
710
|
+
|
|
711
|
+
Raises:
|
|
712
|
+
YamlValidationException: In case file content is not a `Dict`.
|
|
713
|
+
|
|
714
|
+
Returns:
|
|
715
|
+
Parsed config file.
|
|
716
|
+
"""
|
|
717
|
+
return read_validated_yaml(filename, CONFIG_SCHEMA_FILE, reader_type)
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def read_model_configuration(
|
|
721
|
+
filename: Union[Path, str], expand_env_vars: bool = True
|
|
722
|
+
) -> Dict[str, Any]:
|
|
723
|
+
"""Parses a model configuration file.
|
|
724
|
+
|
|
725
|
+
Args:
|
|
726
|
+
filename: The path to the file which should be read.
|
|
727
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
728
|
+
|
|
729
|
+
Raises:
|
|
730
|
+
YamlValidationException: In case the model configuration doesn't match the
|
|
731
|
+
expected schema.
|
|
732
|
+
|
|
733
|
+
Returns:
|
|
734
|
+
Parsed config file.
|
|
735
|
+
"""
|
|
736
|
+
return read_validated_yaml(
|
|
737
|
+
filename, MODEL_CONFIG_SCHEMA_FILE, expand_env_vars=expand_env_vars
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
def dump_obj_as_yaml_to_string(
|
|
742
|
+
obj: Any,
|
|
743
|
+
should_preserve_key_order: bool = False,
|
|
744
|
+
transform: Optional[Callable] = None,
|
|
745
|
+
) -> str:
|
|
746
|
+
"""Writes data (python dict) to a yaml string.
|
|
747
|
+
|
|
748
|
+
Args:
|
|
749
|
+
obj: The object to dump. Has to be serializable.
|
|
750
|
+
should_preserve_key_order: Whether to force preserve key order in `data`.
|
|
751
|
+
transform: A function to transform the data before writing it to the file.
|
|
752
|
+
|
|
753
|
+
Returns:
|
|
754
|
+
The object converted to a YAML string.
|
|
755
|
+
"""
|
|
756
|
+
buffer = StringIO()
|
|
757
|
+
|
|
758
|
+
write_yaml(
|
|
759
|
+
obj,
|
|
760
|
+
buffer,
|
|
761
|
+
should_preserve_key_order=should_preserve_key_order,
|
|
762
|
+
transform=transform,
|
|
763
|
+
)
|
|
764
|
+
|
|
765
|
+
return buffer.getvalue()
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def _enable_ordered_dict_yaml_dumping() -> None:
|
|
769
|
+
"""Ensure that `OrderedDict`s are dumped so that the order of keys is respected."""
|
|
770
|
+
yaml.add_representer(
|
|
771
|
+
OrderedDict,
|
|
772
|
+
RoundTripRepresenter.represent_dict,
|
|
773
|
+
representer=RoundTripRepresenter,
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
YAML_LINE_MAX_WIDTH = 4096
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def write_yaml(
|
|
781
|
+
data: Any,
|
|
782
|
+
target: Union[str, Path, StringIO],
|
|
783
|
+
should_preserve_key_order: bool = False,
|
|
784
|
+
transform: Optional[Callable[[Any], Any]] = None,
|
|
785
|
+
) -> None:
|
|
786
|
+
"""Writes a yaml to the file or to the stream.
|
|
787
|
+
|
|
788
|
+
Args:
|
|
789
|
+
data: The data to write.
|
|
790
|
+
target: The path to the file which should be written or a stream object
|
|
791
|
+
should_preserve_key_order: Whether to force preserve key order in `data`.
|
|
792
|
+
transform: A function to transform the data before writing it to the file.
|
|
793
|
+
"""
|
|
794
|
+
_enable_ordered_dict_yaml_dumping()
|
|
795
|
+
|
|
796
|
+
if should_preserve_key_order:
|
|
797
|
+
data = convert_to_ordered_dict(data)
|
|
798
|
+
|
|
799
|
+
dumper = yaml.YAML()
|
|
800
|
+
# no wrap lines
|
|
801
|
+
dumper.width = YAML_LINE_MAX_WIDTH # type: ignore[assignment]
|
|
802
|
+
|
|
803
|
+
# use `null` to represent `None`
|
|
804
|
+
dumper.representer.add_representer(
|
|
805
|
+
type(None),
|
|
806
|
+
lambda self, _: self.represent_scalar("tag:yaml.org,2002:null", "null"),
|
|
807
|
+
)
|
|
808
|
+
|
|
809
|
+
if isinstance(target, StringIO):
|
|
810
|
+
dumper.dump(data, target, transform=transform)
|
|
811
|
+
return
|
|
812
|
+
|
|
813
|
+
with Path(target).open("w", encoding=DEFAULT_ENCODING) as outfile:
|
|
814
|
+
dumper.dump(data, outfile, transform=transform)
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
def is_key_in_yaml(file_path: Union[str, Path], *keys: str) -> bool:
|
|
818
|
+
"""Checks if any of the keys is contained in the root object of the yaml file.
|
|
819
|
+
|
|
820
|
+
Arguments:
|
|
821
|
+
file_path: path to the yaml file
|
|
822
|
+
keys: keys to look for
|
|
823
|
+
|
|
824
|
+
Returns:
|
|
825
|
+
`True` if at least one of the keys is found, `False` otherwise.
|
|
826
|
+
|
|
827
|
+
Raises:
|
|
828
|
+
FileNotFoundException: if the file cannot be found.
|
|
829
|
+
"""
|
|
830
|
+
try:
|
|
831
|
+
with open(file_path, encoding=DEFAULT_ENCODING) as file:
|
|
832
|
+
return any(
|
|
833
|
+
any(line.lstrip().startswith(f"{key}:") for key in keys)
|
|
834
|
+
for line in file
|
|
835
|
+
)
|
|
836
|
+
except FileNotFoundError:
|
|
837
|
+
raise FileNotFoundException(
|
|
838
|
+
f"Failed to read file, " f"'{os.path.abspath(file_path)}' does not exist."
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def read_validated_yaml(
|
|
843
|
+
filename: Union[str, Path],
|
|
844
|
+
schema: str,
|
|
845
|
+
reader_type: Union[str, List[str]] = "safe",
|
|
846
|
+
expand_env_vars: bool = True,
|
|
847
|
+
) -> Any:
|
|
848
|
+
"""Validates YAML file content and returns parsed content.
|
|
849
|
+
|
|
850
|
+
Args:
|
|
851
|
+
filename: The path to the file which should be read.
|
|
852
|
+
schema: The path to the schema file which should be used for validating the
|
|
853
|
+
file content.
|
|
854
|
+
reader_type: Reader type to use. By default, "safe" will be used.
|
|
855
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
856
|
+
|
|
857
|
+
Returns:
|
|
858
|
+
The parsed file content.
|
|
859
|
+
|
|
860
|
+
Raises:
|
|
861
|
+
YamlValidationException: In case the model configuration doesn't match the
|
|
862
|
+
expected schema.
|
|
863
|
+
"""
|
|
864
|
+
content = read_file(filename)
|
|
865
|
+
|
|
866
|
+
validate_raw_yaml_using_schema_file(
|
|
867
|
+
content, schema, expand_env_vars=expand_env_vars
|
|
868
|
+
)
|
|
869
|
+
return read_yaml(content, reader_type, expand_env_vars=expand_env_vars)
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
def validate_training_data(json_data: Dict[str, Any], schema: Dict[str, Any]) -> None:
|
|
873
|
+
"""Validate rasa training data format to ensure proper training.
|
|
874
|
+
|
|
875
|
+
Args:
|
|
876
|
+
json_data: the data to validate
|
|
877
|
+
schema: the schema
|
|
878
|
+
|
|
879
|
+
Raises:
|
|
880
|
+
SchemaValidationError if validation fails.
|
|
881
|
+
"""
|
|
882
|
+
try:
|
|
883
|
+
jsonschema.validate(json_data, schema)
|
|
884
|
+
except jsonschema.ValidationError as e:
|
|
885
|
+
e.message += (
|
|
886
|
+
f". Failed to validate data, make sure your data "
|
|
887
|
+
f"is valid. For more information about the format visit "
|
|
888
|
+
f"{DOCS_URL_TRAINING_DATA}."
|
|
889
|
+
)
|
|
890
|
+
raise SchemaValidationError.create_from(e) from e
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
def validate_training_data_format_version(
|
|
894
|
+
yaml_file_content: Dict[str, Any], filename: Optional[str]
|
|
895
|
+
) -> bool:
|
|
896
|
+
"""Validates version on the training data content using `version` field.
|
|
897
|
+
|
|
898
|
+
Warns users if the file is not compatible with the current version of
|
|
899
|
+
Rasa Pro.
|
|
900
|
+
|
|
901
|
+
Args:
|
|
902
|
+
yaml_file_content: Raw content of training data file as a dictionary.
|
|
903
|
+
filename: Name of the validated file.
|
|
904
|
+
|
|
905
|
+
Returns:
|
|
906
|
+
`True` if the file can be processed by current version of Rasa Pro,
|
|
907
|
+
`False` otherwise.
|
|
908
|
+
"""
|
|
909
|
+
if filename:
|
|
910
|
+
filename = os.path.abspath(filename)
|
|
911
|
+
|
|
912
|
+
if not isinstance(yaml_file_content, dict):
|
|
913
|
+
raise YamlValidationException(
|
|
914
|
+
"YAML content in is not a mapping, can not validate training "
|
|
915
|
+
"data schema version.",
|
|
916
|
+
filename=filename,
|
|
917
|
+
)
|
|
918
|
+
|
|
919
|
+
version_value = yaml_file_content.get(KEY_TRAINING_DATA_FORMAT_VERSION)
|
|
920
|
+
|
|
921
|
+
if not version_value:
|
|
922
|
+
# not raising here since it's not critical
|
|
923
|
+
logger.info(
|
|
924
|
+
f"The '{KEY_TRAINING_DATA_FORMAT_VERSION}' key is missing in "
|
|
925
|
+
f"the training data file {filename}. "
|
|
926
|
+
f"Rasa Pro will read the file as a "
|
|
927
|
+
f"version '{LATEST_TRAINING_DATA_FORMAT_VERSION}' file. "
|
|
928
|
+
f"See {DOCS_URL_TRAINING_DATA}."
|
|
929
|
+
)
|
|
930
|
+
return True
|
|
931
|
+
|
|
932
|
+
try:
|
|
933
|
+
if isinstance(version_value, str):
|
|
934
|
+
version_value = version_value.strip("\"'")
|
|
935
|
+
parsed_version = version.parse(version_value)
|
|
936
|
+
latest_version = version.parse(LATEST_TRAINING_DATA_FORMAT_VERSION)
|
|
937
|
+
|
|
938
|
+
if parsed_version < latest_version:
|
|
939
|
+
raise_warning(
|
|
940
|
+
f"Training data file {filename} has a lower "
|
|
941
|
+
f"format version than your Rasa Pro installation: "
|
|
942
|
+
f"{version_value} < {LATEST_TRAINING_DATA_FORMAT_VERSION}. "
|
|
943
|
+
f"Rasa Pro will read the file as a version "
|
|
944
|
+
f"{LATEST_TRAINING_DATA_FORMAT_VERSION} file. "
|
|
945
|
+
f"Please update your version key to "
|
|
946
|
+
f"{LATEST_TRAINING_DATA_FORMAT_VERSION}. "
|
|
947
|
+
f"See {DOCS_URL_TRAINING_DATA}."
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
if latest_version >= parsed_version:
|
|
951
|
+
return True
|
|
952
|
+
|
|
953
|
+
except (TypeError, version.InvalidVersion):
|
|
954
|
+
raise_warning(
|
|
955
|
+
f"Training data file {filename} must specify "
|
|
956
|
+
f"'{KEY_TRAINING_DATA_FORMAT_VERSION}' as string, for example:\n"
|
|
957
|
+
f"{KEY_TRAINING_DATA_FORMAT_VERSION}: "
|
|
958
|
+
f"'{LATEST_TRAINING_DATA_FORMAT_VERSION}'\n"
|
|
959
|
+
f"Rasa Pro will read the file as a "
|
|
960
|
+
f"version '{LATEST_TRAINING_DATA_FORMAT_VERSION}' file.",
|
|
961
|
+
docs=DOCS_URL_TRAINING_DATA,
|
|
962
|
+
)
|
|
963
|
+
return True
|
|
964
|
+
|
|
965
|
+
raise_warning(
|
|
966
|
+
f"Training data file {filename} has a greater "
|
|
967
|
+
f"format version than your Rasa Pro installation: "
|
|
968
|
+
f"{version_value} > {LATEST_TRAINING_DATA_FORMAT_VERSION}. "
|
|
969
|
+
f"Please consider updating to the latest version of Rasa Pro."
|
|
970
|
+
f"This file will be skipped.",
|
|
971
|
+
docs=DOCS_URL_TRAINING_DATA,
|
|
972
|
+
)
|
|
973
|
+
return False
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
def default_error_humanizer(error: jsonschema.ValidationError) -> str:
|
|
977
|
+
"""Creates a user readable error message for an error."""
|
|
978
|
+
return error.message
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
def validate_yaml_with_jsonschema(
|
|
982
|
+
yaml_file_content: str,
|
|
983
|
+
schema_path: str,
|
|
984
|
+
package_name: str = PACKAGE_NAME,
|
|
985
|
+
humanize_error: Callable[
|
|
986
|
+
[jsonschema.ValidationError], str
|
|
987
|
+
] = default_error_humanizer,
|
|
988
|
+
expand_env_vars: bool = True,
|
|
989
|
+
) -> None:
|
|
990
|
+
"""Validate data format.
|
|
991
|
+
|
|
992
|
+
Args:
|
|
993
|
+
yaml_file_content: the content of the yaml file to be validated
|
|
994
|
+
schema_path: the schema of the yaml file
|
|
995
|
+
package_name: the name of the package the schema is located in. defaults
|
|
996
|
+
to `rasa`.
|
|
997
|
+
humanize_error: a function to convert a jsonschema.ValidationError into a
|
|
998
|
+
human-readable error message. Defaults to `default_error_humanizer`.
|
|
999
|
+
expand_env_vars: Whether to expand environment variables in the file.
|
|
1000
|
+
|
|
1001
|
+
Raises:
|
|
1002
|
+
YamlSyntaxException: if the yaml file is not valid.
|
|
1003
|
+
SchemaValidationError: if validation fails.
|
|
1004
|
+
"""
|
|
1005
|
+
from ruamel.yaml import YAMLError
|
|
1006
|
+
import importlib_resources
|
|
1007
|
+
|
|
1008
|
+
schema_file = str(importlib_resources.files(package_name).joinpath(schema_path))
|
|
1009
|
+
schema_content = read_json_file(schema_file)
|
|
1010
|
+
|
|
1011
|
+
try:
|
|
1012
|
+
# we need "rt" since
|
|
1013
|
+
# it will add meta information to the parsed output. this meta information
|
|
1014
|
+
# will include e.g. at which line an object was parsed. this is very
|
|
1015
|
+
# helpful when we validate files later on and want to point the user to the
|
|
1016
|
+
# right line
|
|
1017
|
+
source_data = read_yaml(
|
|
1018
|
+
yaml_file_content,
|
|
1019
|
+
reader_type=["safe", "rt"],
|
|
1020
|
+
expand_env_vars=expand_env_vars,
|
|
1021
|
+
)
|
|
1022
|
+
except (YAMLError, DuplicateKeyError) as e:
|
|
1023
|
+
raise YamlSyntaxException(underlying_yaml_exception=e)
|
|
1024
|
+
|
|
1025
|
+
try:
|
|
1026
|
+
jsonschema.validate(source_data, schema_content)
|
|
1027
|
+
except jsonschema.ValidationError as error:
|
|
1028
|
+
errors = [
|
|
1029
|
+
PathWithError(
|
|
1030
|
+
message=humanize_error(error),
|
|
1031
|
+
path=[str(e) for e in error.absolute_path],
|
|
1032
|
+
)
|
|
1033
|
+
]
|
|
1034
|
+
raise YamlValidationException(
|
|
1035
|
+
"Please make sure the file is correct and all "
|
|
1036
|
+
"mandatory parameters are specified. Here are the errors "
|
|
1037
|
+
"found during validation",
|
|
1038
|
+
errors,
|
|
1039
|
+
content=source_data,
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
def validate_yaml_data_using_schema_with_assertions(
|
|
1044
|
+
yaml_data: Any,
|
|
1045
|
+
schema_content: Union[List[Any], Dict[str, Any]],
|
|
1046
|
+
package_name: str = PACKAGE_NAME,
|
|
1047
|
+
) -> None:
|
|
1048
|
+
"""Validate raw yaml content using a schema with assertions sub-schema.
|
|
1049
|
+
|
|
1050
|
+
Args:
|
|
1051
|
+
yaml_data: the parsed yaml data to be validated
|
|
1052
|
+
schema_content: the content of the YAML schema
|
|
1053
|
+
package_name: the name of the package the schema is located in. defaults
|
|
1054
|
+
to `rasa`.
|
|
1055
|
+
"""
|
|
1056
|
+
# test case assertions are part of the schema extension
|
|
1057
|
+
# it will be included if the schema explicitly references it with
|
|
1058
|
+
# include: assertions
|
|
1059
|
+
e2e_test_cases_schema_content = read_schema_file(
|
|
1060
|
+
ASSERTIONS_SCHEMA_FILE, package_name
|
|
1061
|
+
)
|
|
1062
|
+
|
|
1063
|
+
schema_content = dict(schema_content, **e2e_test_cases_schema_content)
|
|
1064
|
+
schema_extensions = [
|
|
1065
|
+
str(files(package_name).joinpath(ASSERTIONS_SCHEMA_EXTENSIONS_FILE))
|
|
1066
|
+
]
|
|
1067
|
+
|
|
1068
|
+
validate_yaml_content_using_schema(yaml_data, schema_content, schema_extensions)
|