rasa-pro 3.12.18.dev1__py3-none-any.whl → 3.13.0a1.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.
- rasa/__init__.py +0 -6
- rasa/__main__.py +3 -4
- rasa/api.py +1 -1
- rasa/builder/create_openai_vector_store.py +69 -0
- rasa/builder/llm-helper-schema.json +69 -0
- rasa/builder/prompt_to_bot.py +645 -0
- rasa/builder/scrape_rasa_docs.py +97 -0
- rasa/builder/skill_to_bot_prompt.jinja +158 -0
- rasa/cli/dialogue_understanding_test.py +1 -1
- rasa/cli/e2e_test.py +1 -1
- rasa/cli/evaluate.py +2 -2
- rasa/cli/export.py +3 -3
- rasa/cli/llm_fine_tuning.py +1 -1
- rasa/cli/project_templates/default/config.yml +5 -32
- rasa/cli/project_templates/{calm → default}/e2e_tests/cancelations/user_cancels_during_a_correction.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/cancelations/user_changes_mind_on_a_whim.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/corrections/user_corrects_contact_handle.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/corrections/user_corrects_contact_name.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/happy_paths/user_adds_contact_to_their_list.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/happy_paths/user_lists_contacts.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/happy_paths/user_removes_contact.yml +1 -1
- rasa/cli/project_templates/{calm → default}/e2e_tests/happy_paths/user_removes_contact_from_list.yml +1 -1
- rasa/cli/project_templates/default/endpoints.yml +18 -2
- rasa/cli/project_templates/defaults.py +133 -0
- rasa/cli/run.py +1 -1
- rasa/cli/scaffold.py +2 -3
- rasa/cli/studio/download.py +1 -1
- rasa/cli/studio/link.py +53 -0
- rasa/cli/studio/pull.py +78 -0
- rasa/cli/studio/push.py +78 -0
- rasa/cli/studio/studio.py +12 -0
- rasa/cli/studio/upload.py +5 -3
- rasa/cli/train.py +1 -1
- rasa/cli/utils.py +1 -1
- rasa/cli/x.py +1 -1
- rasa/constants.py +2 -0
- rasa/core/__init__.py +0 -16
- rasa/core/actions/action.py +42 -31
- rasa/core/actions/action_repeat_bot_messages.py +18 -22
- rasa/core/actions/action_run_slot_rejections.py +1 -2
- rasa/core/agent.py +18 -3
- rasa/core/available_endpoints.py +146 -0
- rasa/core/brokers/kafka.py +4 -0
- rasa/core/brokers/pika.py +5 -2
- rasa/core/brokers/sql.py +1 -1
- rasa/core/channels/botframework.py +2 -2
- rasa/core/channels/channel.py +2 -2
- rasa/core/channels/development_inspector.py +1 -1
- rasa/core/channels/facebook.py +1 -4
- rasa/core/channels/hangouts.py +8 -5
- rasa/core/channels/inspector/.eslintrc.cjs +12 -6
- rasa/core/channels/inspector/.prettierrc +5 -0
- rasa/core/channels/inspector/README.md +11 -5
- rasa/core/channels/inspector/dist/assets/{arc-9f75cc3b.js → arc-02053cc1.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{blockDiagram-38ab4fdb-7f34db23.js → blockDiagram-38ab4fdb-008b6289.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{c4Diagram-3d4e48cf-948bab2c.js → c4Diagram-3d4e48cf-fb2597be.js} +1 -1
- rasa/core/channels/inspector/dist/assets/channel-078dada8.js +1 -0
- rasa/core/channels/inspector/dist/assets/{classDiagram-70f12bd4-53b0dd0e.js → classDiagram-70f12bd4-7f847e00.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-v2-f2320105-fdf789e7.js → classDiagram-v2-f2320105-ba1d689b.js} +1 -1
- rasa/core/channels/inspector/dist/assets/clone-5b4516de.js +1 -0
- rasa/core/channels/inspector/dist/assets/{createText-2e5e7dd3-87c4ece5.js → createText-2e5e7dd3-dd8e67c4.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{edges-e0da2a9e-5a8b0749.js → edges-e0da2a9e-10784939.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{erDiagram-9861fffd-66da90e2.js → erDiagram-9861fffd-24947ae6.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDb-956e92f1-10044f05.js → flowDb-956e92f1-a9ced505.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDiagram-66a62f08-f338f66a.js → flowDiagram-66a62f08-afda9c7c.js} +1 -1
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-f9613071.js +1 -0
- rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-4a651766-b13140aa.js → flowchart-elk-definition-4a651766-6ef530b8.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{ganttDiagram-c361ad54-f2b4a55a.js → ganttDiagram-c361ad54-0c7dd39a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-72cf32ee-dedc298d.js → gitGraphDiagram-72cf32ee-b57239d6.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{graph-4ede11ff.js → graph-9ed57cec.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-3862675e-65549d37.js → index-3862675e-233090de.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-3a23e736.js → index-72184470.js} +123 -123
- rasa/core/channels/inspector/dist/assets/{infoDiagram-f8f76790-65439671.js → infoDiagram-f8f76790-aa116649.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{journeyDiagram-49397b02-56d03d98.js → journeyDiagram-49397b02-e51877cc.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{layout-dd48f7f4.js → layout-3ca3798c.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{line-1569ad2c.js → line-26ee10d3.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{linear-48bf4935.js → linear-aedded32.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{mindmap-definition-fc14e90a-688504c1.js → mindmap-definition-fc14e90a-d8957261.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{pieDiagram-8a3498a8-78b6d7e6.js → pieDiagram-8a3498a8-d771f885.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{quadrantDiagram-120e2f19-048b84b3.js → quadrantDiagram-120e2f19-09fdf50c.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{requirementDiagram-deff3bca-dd67f107.js → requirementDiagram-deff3bca-9f0af02e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sankeyDiagram-04a897e0-8128436e.js → sankeyDiagram-04a897e0-84415b37.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sequenceDiagram-704730f1-1a0d1461.js → sequenceDiagram-704730f1-8dec4055.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-587899a1-46d388ed.js → stateDiagram-587899a1-c5431d07.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-d93cdb3a-ea42951a.js → stateDiagram-v2-d93cdb3a-274e77d9.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-6aaf32cf-7427ed0c.js → styles-6aaf32cf-e364a1d7.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-9a916d00-ff5e5a16.js → styles-9a916d00-0dae36f6.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-c10674c1-7b3680cf.js → styles-c10674c1-c4641675.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{svgDrawCommon-08f97a94-f860f2ad.js → svgDrawCommon-08f97a94-831fe9a1.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{timeline-definition-85554ec2-2eebf0c8.js → timeline-definition-85554ec2-c3304b3a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{xychartDiagram-e933f94c-5d7f4e96.js → xychartDiagram-e933f94c-da799369.js} +1 -1
- rasa/core/channels/inspector/dist/index.html +1 -1
- rasa/core/channels/inspector/package.json +3 -1
- rasa/core/channels/inspector/src/App.tsx +91 -90
- rasa/core/channels/inspector/src/components/Chat.tsx +45 -41
- rasa/core/channels/inspector/src/components/DiagramFlow.tsx +40 -40
- rasa/core/channels/inspector/src/components/DialogueInformation.tsx +57 -57
- rasa/core/channels/inspector/src/components/DialogueStack.tsx +36 -27
- rasa/core/channels/inspector/src/components/ExpandIcon.tsx +4 -4
- rasa/core/channels/inspector/src/components/FullscreenButton.tsx +7 -7
- rasa/core/channels/inspector/src/components/LoadingSpinner.tsx +28 -12
- rasa/core/channels/inspector/src/components/NoActiveFlow.tsx +9 -9
- rasa/core/channels/inspector/src/components/RasaLogo.tsx +5 -5
- rasa/core/channels/inspector/src/components/RecruitmentPanel.tsx +55 -60
- rasa/core/channels/inspector/src/components/SaraDiagrams.tsx +5 -5
- rasa/core/channels/inspector/src/components/Slots.tsx +22 -22
- rasa/core/channels/inspector/src/components/Welcome.tsx +28 -31
- rasa/core/channels/inspector/src/helpers/audio/audiostream.ts +245 -0
- rasa/core/channels/inspector/src/helpers/audio/microphone-processor.js +12 -0
- rasa/core/channels/inspector/src/helpers/audio/playback-processor.js +36 -0
- rasa/core/channels/inspector/src/helpers/conversation.ts +7 -7
- rasa/core/channels/inspector/src/helpers/formatters.test.ts +181 -181
- rasa/core/channels/inspector/src/helpers/formatters.ts +111 -111
- rasa/core/channels/inspector/src/helpers/utils.ts +78 -61
- rasa/core/channels/inspector/src/main.tsx +8 -8
- rasa/core/channels/inspector/src/theme/Button/Button.ts +8 -8
- rasa/core/channels/inspector/src/theme/Heading/Heading.ts +7 -7
- rasa/core/channels/inspector/src/theme/Input/Input.ts +9 -9
- rasa/core/channels/inspector/src/theme/Link/Link.ts +6 -6
- rasa/core/channels/inspector/src/theme/Modal/Modal.ts +13 -13
- rasa/core/channels/inspector/src/theme/Table/Table.tsx +10 -10
- rasa/core/channels/inspector/src/theme/Tooltip/Tooltip.ts +5 -5
- rasa/core/channels/inspector/src/theme/base/breakpoints.ts +7 -7
- rasa/core/channels/inspector/src/theme/base/colors.ts +64 -64
- rasa/core/channels/inspector/src/theme/base/fonts/fontFaces.css +21 -18
- rasa/core/channels/inspector/src/theme/base/radii.ts +8 -8
- rasa/core/channels/inspector/src/theme/base/shadows.ts +5 -5
- rasa/core/channels/inspector/src/theme/base/sizes.ts +5 -5
- rasa/core/channels/inspector/src/theme/base/space.ts +12 -12
- rasa/core/channels/inspector/src/theme/base/styles.ts +5 -5
- rasa/core/channels/inspector/src/theme/base/typography.ts +12 -12
- rasa/core/channels/inspector/src/theme/base/zIndices.ts +3 -3
- rasa/core/channels/inspector/src/theme/index.ts +38 -38
- rasa/core/channels/inspector/src/types.ts +56 -50
- rasa/core/channels/inspector/yarn.lock +5 -0
- rasa/core/channels/mattermost.py +1 -1
- rasa/core/channels/rasa_chat.py +2 -4
- rasa/core/channels/rest.py +5 -4
- rasa/core/channels/socketio.py +56 -41
- rasa/core/channels/studio_chat.py +337 -71
- rasa/core/channels/vier_cvg.py +1 -2
- rasa/core/channels/voice_ready/audiocodes.py +4 -11
- rasa/core/channels/voice_stream/audiocodes.py +8 -5
- rasa/core/channels/voice_stream/browser_audio.py +1 -1
- rasa/core/channels/voice_stream/genesys.py +2 -2
- rasa/core/channels/voice_stream/tts/__init__.py +8 -0
- rasa/core/channels/voice_stream/twilio_media_streams.py +10 -5
- rasa/core/channels/voice_stream/voice_channel.py +65 -23
- rasa/core/concurrent_lock_store.py +24 -10
- rasa/core/evaluation/marker_tracker_loader.py +1 -1
- rasa/core/exporter.py +1 -1
- rasa/core/http_interpreter.py +3 -7
- rasa/core/information_retrieval/faiss.py +18 -11
- rasa/core/information_retrieval/ingestion/__init__.py +0 -0
- rasa/core/information_retrieval/ingestion/faq_parser.py +158 -0
- rasa/core/jobs.py +2 -1
- rasa/core/lock_store.py +151 -60
- rasa/core/nlg/contextual_response_rephraser.py +17 -7
- rasa/core/nlg/generator.py +5 -22
- rasa/core/nlg/interpolator.py +2 -3
- rasa/core/nlg/response.py +6 -43
- rasa/core/nlg/summarize.py +1 -1
- rasa/core/nlg/translate.py +0 -8
- rasa/core/policies/enterprise_search_policy.py +262 -62
- rasa/core/policies/enterprise_search_prompt_with_relevancy_check_and_citation_template.jinja2 +63 -0
- rasa/core/policies/flow_policy.py +1 -1
- rasa/core/policies/flows/flow_executor.py +96 -17
- rasa/core/policies/intentless_policy.py +57 -20
- rasa/core/processor.py +114 -54
- rasa/core/run.py +33 -11
- rasa/core/tracker_stores/__init__.py +0 -0
- rasa/core/{auth_retry_tracker_store.py → tracker_stores/auth_retry_tracker_store.py} +5 -1
- rasa/core/tracker_stores/dynamo_tracker_store.py +218 -0
- rasa/core/tracker_stores/mongo_tracker_store.py +206 -0
- rasa/core/tracker_stores/redis_tracker_store.py +219 -0
- rasa/core/tracker_stores/sql_tracker_store.py +555 -0
- rasa/core/tracker_stores/tracker_store.py +805 -0
- rasa/core/training/interactive.py +1 -1
- rasa/core/utils.py +24 -95
- rasa/dialogue_understanding/coexistence/intent_based_router.py +2 -1
- rasa/dialogue_understanding/coexistence/llm_based_router.py +10 -6
- rasa/dialogue_understanding/commands/can_not_handle_command.py +2 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +5 -1
- rasa/dialogue_understanding/commands/chit_chat_answer_command.py +2 -0
- rasa/dialogue_understanding/commands/clarify_command.py +4 -0
- rasa/dialogue_understanding/commands/command_syntax_manager.py +1 -0
- rasa/dialogue_understanding/commands/correct_slots_command.py +1 -3
- rasa/dialogue_understanding/commands/human_handoff_command.py +2 -0
- rasa/dialogue_understanding/commands/knowledge_answer_command.py +2 -0
- rasa/dialogue_understanding/commands/repeat_bot_messages_command.py +2 -0
- rasa/dialogue_understanding/commands/set_slot_command.py +10 -0
- rasa/dialogue_understanding/commands/skip_question_command.py +2 -0
- rasa/dialogue_understanding/commands/start_flow_command.py +4 -0
- rasa/dialogue_understanding/commands/utils.py +26 -2
- rasa/dialogue_understanding/generator/__init__.py +7 -1
- rasa/dialogue_understanding/generator/command_generator.py +4 -2
- rasa/dialogue_understanding/generator/command_parser.py +2 -2
- rasa/dialogue_understanding/generator/command_parser_validator.py +63 -0
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +5 -17
- rasa/dialogue_understanding/generator/llm_command_generator.py +1 -3
- rasa/dialogue_understanding/generator/multi_step/multi_step_llm_command_generator.py +4 -44
- rasa/dialogue_understanding/generator/nlu_command_adapter.py +2 -2
- rasa/dialogue_understanding/generator/prompt_templates/command_prompt_v3_gpt_4o_2024_11_20_template.jinja2 +78 -0
- rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +26 -474
- rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +147 -0
- rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +477 -0
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +11 -64
- rasa/dialogue_understanding/patterns/cancel.py +1 -2
- rasa/dialogue_understanding/patterns/clarify.py +1 -1
- rasa/dialogue_understanding/patterns/correction.py +2 -2
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +37 -25
- rasa/dialogue_understanding/patterns/domain_for_patterns.py +190 -0
- rasa/dialogue_understanding/processor/command_processor.py +6 -7
- rasa/dialogue_understanding/stack/frames/flow_stack_frame.py +17 -4
- rasa/dialogue_understanding/stack/utils.py +3 -1
- rasa/dialogue_understanding/utils.py +68 -12
- rasa/dialogue_understanding_test/command_metric_calculation.py +7 -40
- rasa/dialogue_understanding_test/command_metrics.py +38 -0
- rasa/dialogue_understanding_test/du_test_case.py +58 -25
- rasa/dialogue_understanding_test/du_test_result.py +228 -132
- rasa/dialogue_understanding_test/du_test_runner.py +11 -2
- rasa/dialogue_understanding_test/io.py +35 -8
- rasa/e2e_test/e2e_test_runner.py +1 -1
- rasa/engine/constants.py +1 -1
- rasa/engine/graph.py +2 -2
- rasa/engine/recipes/default_recipe.py +1 -1
- rasa/engine/validation.py +3 -2
- rasa/hooks.py +2 -85
- rasa/llm_fine_tuning/paraphrasing/conversation_rephraser.py +1 -5
- rasa/llm_fine_tuning/utils.py +2 -4
- rasa/model_manager/model_api.py +90 -2
- rasa/model_manager/socket_bridge.py +0 -7
- rasa/model_manager/trainer_service.py +15 -12
- rasa/plugin.py +2 -15
- rasa/privacy/__init__.py +0 -0
- rasa/privacy/constants.py +83 -0
- rasa/privacy/event_broker_utils.py +77 -0
- rasa/privacy/privacy_config.py +281 -0
- rasa/privacy/privacy_config_schema.json +86 -0
- rasa/privacy/privacy_filter.py +340 -0
- rasa/privacy/privacy_manager.py +576 -0
- rasa/server.py +23 -2
- rasa/shared/constants.py +13 -4
- rasa/shared/core/command_payload_reader.py +1 -5
- rasa/shared/core/constants.py +4 -3
- rasa/shared/core/domain.py +172 -11
- rasa/shared/core/events.py +100 -6
- rasa/shared/core/flows/flow.py +35 -8
- rasa/shared/core/flows/flow_step.py +26 -4
- rasa/shared/core/flows/flow_step_links.py +15 -0
- rasa/shared/core/flows/flow_step_sequence.py +6 -0
- rasa/shared/core/flows/flows_yaml_schema.json +3 -0
- rasa/shared/core/flows/nlu_trigger.py +13 -0
- rasa/shared/core/flows/steps/action.py +7 -4
- rasa/shared/core/flows/steps/call.py +11 -4
- rasa/shared/core/flows/steps/collect.py +71 -6
- rasa/shared/core/flows/steps/internal.py +6 -1
- rasa/shared/core/flows/steps/link.py +7 -4
- rasa/shared/core/flows/steps/no_operation.py +7 -4
- rasa/shared/core/flows/steps/set_slots.py +8 -4
- rasa/shared/core/flows/validation.py +16 -3
- rasa/shared/core/flows/yaml_flows_io.py +106 -5
- rasa/shared/core/slots.py +33 -1
- rasa/shared/core/trackers.py +4 -10
- rasa/shared/core/training_data/story_reader/yaml_story_reader.py +1 -4
- rasa/shared/importers/importer.py +14 -0
- rasa/shared/importers/static.py +63 -0
- rasa/shared/providers/constants.py +0 -9
- rasa/shared/providers/llm/_base_litellm_client.py +4 -14
- rasa/shared/providers/llm/default_litellm_llm_client.py +2 -2
- rasa/shared/providers/llm/litellm_router_llm_client.py +7 -17
- rasa/shared/providers/llm/llm_client.py +15 -24
- rasa/shared/providers/llm/self_hosted_llm_client.py +2 -10
- rasa/shared/utils/common.py +43 -1
- rasa/shared/utils/llm.py +155 -3
- rasa/shared/utils/yaml.py +32 -0
- rasa/studio/data_handler.py +3 -3
- rasa/studio/download/__init__.py +0 -0
- rasa/studio/download/domains.py +49 -0
- rasa/studio/download/download.py +416 -0
- rasa/studio/download/flows.py +351 -0
- rasa/studio/link.py +200 -0
- rasa/studio/pull.py +94 -0
- rasa/studio/push.py +131 -0
- rasa/studio/results_logger.py +6 -1
- rasa/studio/upload.py +185 -71
- rasa/telemetry.py +83 -26
- rasa/tracing/config.py +4 -5
- rasa/tracing/constants.py +19 -1
- rasa/tracing/instrumentation/attribute_extractors.py +49 -11
- rasa/tracing/instrumentation/instrumentation.py +54 -3
- rasa/tracing/instrumentation/metrics.py +98 -15
- rasa/tracing/metric_instrument_provider.py +75 -3
- rasa/utils/common.py +37 -27
- rasa/utils/endpoints.py +22 -1
- rasa/utils/licensing.py +2 -3
- rasa/utils/log_utils.py +1 -45
- rasa/validator.py +9 -11
- rasa/version.py +1 -1
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.13.0a1.dev1.dist-info}/METADATA +12 -14
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.13.0a1.dev1.dist-info}/RECORD +318 -294
- rasa/anonymization/__init__.py +0 -2
- rasa/anonymization/anonymisation_rule_yaml_reader.py +0 -91
- rasa/anonymization/anonymization_pipeline.py +0 -286
- rasa/anonymization/anonymization_rule_executor.py +0 -266
- rasa/anonymization/anonymization_rule_orchestrator.py +0 -119
- rasa/anonymization/schemas/config.yml +0 -47
- rasa/anonymization/utils.py +0 -118
- rasa/cli/project_templates/calm/config.yml +0 -10
- rasa/cli/project_templates/calm/credentials.yml +0 -33
- rasa/cli/project_templates/calm/endpoints.yml +0 -58
- rasa/cli/project_templates/default/actions/actions.py +0 -27
- rasa/cli/project_templates/default/data/nlu.yml +0 -91
- rasa/cli/project_templates/default/data/rules.yml +0 -13
- rasa/cli/project_templates/default/data/stories.yml +0 -30
- rasa/cli/project_templates/default/domain.yml +0 -34
- rasa/cli/project_templates/default/tests/test_stories.yml +0 -91
- rasa/core/channels/inspector/dist/assets/channel-dfa68278.js +0 -1
- rasa/core/channels/inspector/dist/assets/clone-edb7f119.js +0 -1
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-96b9c2cf-65e7c670.js +0 -1
- rasa/core/channels/inspector/src/helpers/audiostream.ts +0 -191
- rasa/core/tracker_store.py +0 -1792
- rasa/monkey_patches.py +0 -91
- rasa/studio/download.py +0 -489
- /rasa/{cli/project_templates/calm/actions → builder}/__init__.py +0 -0
- /rasa/cli/project_templates/{calm → default}/actions/action_template.py +0 -0
- /rasa/cli/project_templates/{calm → default}/actions/add_contact.py +0 -0
- /rasa/cli/project_templates/{calm → default}/actions/db.py +0 -0
- /rasa/cli/project_templates/{calm → default}/actions/list_contacts.py +0 -0
- /rasa/cli/project_templates/{calm → default}/actions/remove_contact.py +0 -0
- /rasa/cli/project_templates/{calm → default}/data/flows/add_contact.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/data/flows/list_contacts.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/data/flows/remove_contact.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/db/contacts.json +0 -0
- /rasa/cli/project_templates/{calm → default}/domain/add_contact.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/domain/list_contacts.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/domain/remove_contact.yml +0 -0
- /rasa/cli/project_templates/{calm → default}/domain/shared.yml +0 -0
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.13.0a1.dev1.dist-info}/NOTICE +0 -0
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.13.0a1.dev1.dist-info}/WHEEL +0 -0
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.13.0a1.dev1.dist-info}/entry_points.txt +0 -0
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
from typing import Any, Dict, List, Literal, Optional, Text
|
|
1
|
+
from typing import Any, Dict, Literal, Optional, Text
|
|
3
2
|
|
|
4
3
|
import structlog
|
|
5
4
|
|
|
6
|
-
import rasa.shared.utils.io
|
|
7
|
-
from rasa.dialogue_understanding.commands import (
|
|
8
|
-
CannotHandleCommand,
|
|
9
|
-
Command,
|
|
10
|
-
ErrorCommand,
|
|
11
|
-
SetSlotCommand,
|
|
12
|
-
)
|
|
13
5
|
from rasa.dialogue_understanding.commands.command_syntax_manager import (
|
|
14
|
-
CommandSyntaxManager,
|
|
15
6
|
CommandSyntaxVersion,
|
|
16
7
|
)
|
|
17
|
-
from rasa.dialogue_understanding.generator import LLMBasedCommandGenerator
|
|
18
|
-
from rasa.dialogue_understanding.generator.command_parser import (
|
|
19
|
-
parse_commands as parse_commands_using_command_parsers,
|
|
20
|
-
)
|
|
21
8
|
from rasa.dialogue_understanding.generator.constants import (
|
|
22
|
-
COMMAND_PROMPT_FILE_NAME,
|
|
23
9
|
DEFAULT_OPENAI_MAX_GENERATED_TOKENS,
|
|
24
|
-
FLOW_RETRIEVAL_KEY,
|
|
25
|
-
LLM_BASED_COMMAND_GENERATOR_CONFIG_FILE,
|
|
26
10
|
LLM_CONFIG_KEY,
|
|
27
11
|
MODEL_CONFIG_KEY,
|
|
28
12
|
MODEL_NAME_CLAUDE_3_5_SONNET_20240620,
|
|
@@ -30,15 +14,10 @@ from rasa.dialogue_understanding.generator.constants import (
|
|
|
30
14
|
OPENAI_PROVIDER,
|
|
31
15
|
PROVIDER_CONFIG_KEY,
|
|
32
16
|
TIMEOUT_CONFIG_KEY,
|
|
33
|
-
USER_INPUT_CONFIG_KEY,
|
|
34
17
|
)
|
|
35
|
-
from rasa.dialogue_understanding.generator.
|
|
36
|
-
|
|
37
|
-
from rasa.dialogue_understanding.utils import (
|
|
38
|
-
add_commands_to_message_parse_data,
|
|
39
|
-
add_prompt_to_message_parse_data,
|
|
18
|
+
from rasa.dialogue_understanding.generator.single_step.single_step_based_llm_command_generator import ( # noqa: E501
|
|
19
|
+
SingleStepBasedLLMCommandGenerator,
|
|
40
20
|
)
|
|
41
|
-
from rasa.engine.graph import ExecutionContext
|
|
42
21
|
from rasa.engine.recipes.default_recipe import DefaultV1Recipe
|
|
43
22
|
from rasa.engine.storage.resource import Resource
|
|
44
23
|
from rasa.engine.storage.storage import ModelStorage
|
|
@@ -46,36 +25,14 @@ from rasa.shared.constants import (
|
|
|
46
25
|
ANTHROPIC_PROVIDER,
|
|
47
26
|
AWS_BEDROCK_PROVIDER,
|
|
48
27
|
AZURE_OPENAI_PROVIDER,
|
|
49
|
-
EMBEDDINGS_CONFIG_KEY,
|
|
50
|
-
LANGFUSE_CUSTOM_METADATA_DICT,
|
|
51
|
-
LANGFUSE_METADATA_SESSION_ID,
|
|
52
|
-
LANGFUSE_TAGS,
|
|
53
28
|
MAX_COMPLETION_TOKENS_CONFIG_KEY,
|
|
54
29
|
PROMPT_TEMPLATE_CONFIG_KEY,
|
|
55
|
-
ROUTE_TO_CALM_SLOT,
|
|
56
30
|
TEMPERATURE_CONFIG_KEY,
|
|
57
31
|
)
|
|
58
|
-
from rasa.shared.core.flows import FlowsList
|
|
59
|
-
from rasa.shared.core.trackers import DialogueStateTracker
|
|
60
|
-
from rasa.shared.exceptions import ProviderClientAPIException
|
|
61
|
-
from rasa.shared.nlu.constants import LLM_COMMANDS, LLM_PROMPT, TEXT
|
|
62
|
-
from rasa.shared.nlu.training_data.message import Message
|
|
63
|
-
from rasa.shared.providers.llm.llm_response import LLMResponse
|
|
64
|
-
from rasa.shared.utils.constants import (
|
|
65
|
-
LOG_COMPONENT_SOURCE_METHOD_FINGERPRINT_ADDON,
|
|
66
|
-
LOG_COMPONENT_SOURCE_METHOD_INIT,
|
|
67
|
-
)
|
|
68
|
-
from rasa.shared.utils.io import deep_container_fingerprint
|
|
69
32
|
from rasa.shared.utils.llm import (
|
|
70
|
-
allowed_values_for_slot,
|
|
71
33
|
get_default_prompt_template_based_on_model,
|
|
72
34
|
get_prompt_template,
|
|
73
|
-
resolve_model_client_config,
|
|
74
|
-
sanitize_message_for_prompt,
|
|
75
|
-
tracker_as_readable_transcript,
|
|
76
35
|
)
|
|
77
|
-
from rasa.utils.beta import BetaNotEnabledException, ensure_beta_feature_is_enabled
|
|
78
|
-
from rasa.utils.log_utils import log_llm
|
|
79
36
|
|
|
80
37
|
structlogger = structlog.get_logger()
|
|
81
38
|
|
|
@@ -114,67 +71,13 @@ FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME = (
|
|
|
114
71
|
)
|
|
115
72
|
|
|
116
73
|
|
|
117
|
-
class CommandParserValidatorSingleton:
|
|
118
|
-
"""Singleton class to validate the command parser.
|
|
119
|
-
|
|
120
|
-
This class is used to validate the command parser. It keeps track of the number of
|
|
121
|
-
consecutive turns where no commands are parsed by the command parser. If the
|
|
122
|
-
number of consecutive turns exceeds a certain threshold, a warning is logged.
|
|
123
|
-
The prompt can use a DSL syntax that can be incompatible with the command syntax
|
|
124
|
-
used by the command parser. This class helps to detect such incompatibilities.
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
MAX_CONSECUTIVE_TURNS_NO_COMMAND_PREDICTED = 5
|
|
128
|
-
_NO_COMMAND_PREDICTED_TURN_COUNTER = 0
|
|
129
|
-
_command_parser_validated = False
|
|
130
|
-
|
|
131
|
-
@classmethod
|
|
132
|
-
def get_no_command_predicted_turn_counter(cls) -> int:
|
|
133
|
-
return cls._NO_COMMAND_PREDICTED_TURN_COUNTER
|
|
134
|
-
|
|
135
|
-
@classmethod
|
|
136
|
-
def should_validate_command_parser(cls) -> bool:
|
|
137
|
-
return not cls._command_parser_validated
|
|
138
|
-
|
|
139
|
-
@classmethod
|
|
140
|
-
def reset_command_parser_validation(cls) -> None:
|
|
141
|
-
cls._NO_COMMAND_PREDICTED_TURN_COUNTER = 0
|
|
142
|
-
cls._command_parser_validated = False
|
|
143
|
-
|
|
144
|
-
@classmethod
|
|
145
|
-
def validate_if_commands_are_parsed_from_llm_response(
|
|
146
|
-
cls, commands: List[Command], llm_response: str
|
|
147
|
-
) -> None:
|
|
148
|
-
if llm_response and not commands:
|
|
149
|
-
cls._NO_COMMAND_PREDICTED_TURN_COUNTER += 1
|
|
150
|
-
else:
|
|
151
|
-
# Reset the counter if commands are generated, and mark
|
|
152
|
-
# the command parser as validated.
|
|
153
|
-
cls._NO_COMMAND_PREDICTED_TURN_COUNTER = 0
|
|
154
|
-
cls._command_parser_validated = True
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
cls._NO_COMMAND_PREDICTED_TURN_COUNTER
|
|
159
|
-
>= cls.MAX_CONSECUTIVE_TURNS_NO_COMMAND_PREDICTED
|
|
160
|
-
):
|
|
161
|
-
structlogger.warning(
|
|
162
|
-
"llm_command_generator.predict_commands.command_parser_not_working",
|
|
163
|
-
event_info=(
|
|
164
|
-
f"No commands were generated by the command parser for the last "
|
|
165
|
-
f"{cls._NO_COMMAND_PREDICTED_TURN_COUNTER} times. Check if you "
|
|
166
|
-
"are running incompatible prompt and LLM command generator."
|
|
167
|
-
),
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
|
|
171
74
|
@DefaultV1Recipe.register(
|
|
172
75
|
[
|
|
173
76
|
DefaultV1Recipe.ComponentType.COMMAND_GENERATOR,
|
|
174
77
|
],
|
|
175
78
|
is_trainable=True,
|
|
176
79
|
)
|
|
177
|
-
class CompactLLMCommandGenerator(
|
|
80
|
+
class CompactLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
178
81
|
"""A single step LLM-based command generator."""
|
|
179
82
|
|
|
180
83
|
def __init__(
|
|
@@ -193,376 +96,20 @@ class CompactLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
193
96
|
**kwargs,
|
|
194
97
|
)
|
|
195
98
|
|
|
196
|
-
# Get the prompt template from the config or the default prompt template.
|
|
197
|
-
self.prompt_template = self._resolve_component_prompt_template(
|
|
198
|
-
self.config, prompt_template, log_context=LOG_COMPONENT_SOURCE_METHOD_INIT
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
# Set the command syntax version to v2
|
|
202
|
-
CommandSyntaxManager.set_syntax_version(
|
|
203
|
-
self.get_component_command_syntax_version()
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
self.trace_prompt_tokens = self.config.get("trace_prompt_tokens", False)
|
|
207
|
-
self.repeat_command_enabled = self.is_repeat_command_enabled()
|
|
208
|
-
|
|
209
|
-
### Implementations of LLMBasedCommandGenerator parent
|
|
210
99
|
@staticmethod
|
|
211
|
-
def
|
|
212
|
-
"""
|
|
213
|
-
return
|
|
214
|
-
PROMPT_TEMPLATE_CONFIG_KEY: None,
|
|
215
|
-
USER_INPUT_CONFIG_KEY: None,
|
|
216
|
-
LLM_CONFIG_KEY: None,
|
|
217
|
-
FLOW_RETRIEVAL_KEY: FlowRetrieval.get_default_config(),
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
def persist(self) -> None:
|
|
221
|
-
"""Persist this component to disk for future loading."""
|
|
222
|
-
self._persist_prompt_template()
|
|
223
|
-
self._persist_config()
|
|
224
|
-
if self.flow_retrieval is not None:
|
|
225
|
-
self.flow_retrieval.persist()
|
|
226
|
-
|
|
227
|
-
def _persist_prompt_template(self) -> None:
|
|
228
|
-
"""Persist prompt template for future loading."""
|
|
229
|
-
with self._model_storage.write_to(self._resource) as path:
|
|
230
|
-
rasa.shared.utils.io.write_text_file(
|
|
231
|
-
self.prompt_template, path / COMMAND_PROMPT_FILE_NAME
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
def _persist_config(self) -> None:
|
|
235
|
-
"""Persist config as a source of truth for resolved clients."""
|
|
236
|
-
with self._model_storage.write_to(self._resource) as path:
|
|
237
|
-
rasa.shared.utils.io.dump_obj_as_json_to_file(
|
|
238
|
-
path / LLM_BASED_COMMAND_GENERATOR_CONFIG_FILE, self.config
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
@classmethod
|
|
242
|
-
def load(
|
|
243
|
-
cls: Any,
|
|
244
|
-
config: Dict[str, Any],
|
|
245
|
-
model_storage: ModelStorage,
|
|
246
|
-
resource: Resource,
|
|
247
|
-
execution_context: ExecutionContext,
|
|
248
|
-
**kwargs: Any,
|
|
249
|
-
) -> "CompactLLMCommandGenerator":
|
|
250
|
-
"""Loads trained component (see parent class for full docstring)."""
|
|
251
|
-
# Perform health check of the LLM API endpoint
|
|
252
|
-
llm_config = resolve_model_client_config(config.get(LLM_CONFIG_KEY, {}))
|
|
253
|
-
cls.perform_llm_health_check(
|
|
254
|
-
llm_config,
|
|
255
|
-
cls.get_default_llm_config(),
|
|
256
|
-
"compact_llm_command_generator.load",
|
|
257
|
-
cls.__name__,
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
# load prompt template from the model storage.
|
|
261
|
-
prompt_template = cls.load_prompt_template_from_model_storage(
|
|
262
|
-
model_storage, resource, COMMAND_PROMPT_FILE_NAME
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
# init base command generator
|
|
266
|
-
command_generator = cls(config, model_storage, resource, prompt_template)
|
|
267
|
-
# load flow retrieval if enabled
|
|
268
|
-
if command_generator.enabled_flow_retrieval:
|
|
269
|
-
command_generator.flow_retrieval = cls.load_flow_retrival(
|
|
270
|
-
command_generator.config, model_storage, resource
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
return command_generator
|
|
274
|
-
|
|
275
|
-
async def predict_commands(
|
|
276
|
-
self,
|
|
277
|
-
message: Message,
|
|
278
|
-
flows: FlowsList,
|
|
279
|
-
tracker: Optional[DialogueStateTracker] = None,
|
|
280
|
-
**kwargs: Any,
|
|
281
|
-
) -> List[Command]:
|
|
282
|
-
"""Predict commands using the LLM.
|
|
283
|
-
|
|
284
|
-
Args:
|
|
285
|
-
message: The message from the user.
|
|
286
|
-
flows: The flows available to the user.
|
|
287
|
-
tracker: The tracker containing the current state of the conversation.
|
|
288
|
-
**kwargs: Keyword arguments for forward compatibility.
|
|
289
|
-
|
|
290
|
-
Returns:
|
|
291
|
-
The commands generated by the llm.
|
|
292
|
-
"""
|
|
293
|
-
prior_commands = self._get_prior_commands(message)
|
|
294
|
-
|
|
295
|
-
if tracker is None or flows.is_empty():
|
|
296
|
-
# cannot do anything if there are no flows or no tracker
|
|
297
|
-
return prior_commands
|
|
298
|
-
|
|
299
|
-
if self._should_skip_llm_call(prior_commands, flows, tracker):
|
|
300
|
-
return prior_commands
|
|
301
|
-
|
|
302
|
-
try:
|
|
303
|
-
commands = await self._predict_commands(message, flows, tracker)
|
|
304
|
-
except ProviderClientAPIException:
|
|
305
|
-
# if command predictions resulted in API exception
|
|
306
|
-
# "predict" the ErrorCommand
|
|
307
|
-
commands = [ErrorCommand()]
|
|
308
|
-
structlogger.warning(
|
|
309
|
-
"llm_command_generator.predict_commands.api_exception",
|
|
310
|
-
event_info=(
|
|
311
|
-
"ProviderClientAPIException occurred while predicting commands."
|
|
312
|
-
),
|
|
313
|
-
commands=commands,
|
|
314
|
-
)
|
|
315
|
-
|
|
316
|
-
if not commands and not prior_commands:
|
|
317
|
-
# no commands are parsed or there's an invalid command
|
|
318
|
-
structlogger.warning(
|
|
319
|
-
"llm_command_generator.predict_commands",
|
|
320
|
-
message="No commands were predicted as the LLM response could "
|
|
321
|
-
"not be parsed or the LLM responded with an invalid command. "
|
|
322
|
-
"Returning a CannotHandleCommand instead.",
|
|
323
|
-
)
|
|
324
|
-
commands = [CannotHandleCommand()]
|
|
325
|
-
|
|
326
|
-
if tracker.has_coexistence_routing_slot:
|
|
327
|
-
# if coexistence feature is used, set the routing slot
|
|
328
|
-
commands += [SetSlotCommand(ROUTE_TO_CALM_SLOT, True)]
|
|
329
|
-
|
|
330
|
-
log_llm(
|
|
331
|
-
logger=structlogger,
|
|
332
|
-
log_module=self.__class__.__name__,
|
|
333
|
-
log_event="llm_command_generator.predict_commands.finished",
|
|
334
|
-
commands=commands,
|
|
335
|
-
)
|
|
336
|
-
|
|
337
|
-
domain = kwargs.get("domain")
|
|
338
|
-
commands = self._check_commands_against_slot_mappings(commands, tracker, domain)
|
|
339
|
-
|
|
340
|
-
return self._check_commands_overlap(prior_commands, commands)
|
|
341
|
-
|
|
342
|
-
async def _predict_commands(
|
|
343
|
-
self,
|
|
344
|
-
message: Message,
|
|
345
|
-
flows: FlowsList,
|
|
346
|
-
tracker: Optional[DialogueStateTracker] = None,
|
|
347
|
-
) -> List[Command]:
|
|
348
|
-
"""Predict commands using the LLM.
|
|
349
|
-
|
|
350
|
-
Args:
|
|
351
|
-
message: The message from the user.
|
|
352
|
-
flows: The flows available to the user.
|
|
353
|
-
tracker: The tracker containing the current state of the conversation.
|
|
354
|
-
|
|
355
|
-
Returns:
|
|
356
|
-
The commands generated by the llm.
|
|
357
|
-
|
|
358
|
-
Raises:
|
|
359
|
-
ProviderClientAPIException: If API calls raised an error.
|
|
360
|
-
"""
|
|
361
|
-
# retrieve flows
|
|
362
|
-
filtered_flows = await self.filter_flows(message, flows, tracker)
|
|
363
|
-
|
|
364
|
-
flow_prompt = self.render_template(message, tracker, filtered_flows, flows)
|
|
365
|
-
log_llm(
|
|
366
|
-
logger=structlogger,
|
|
367
|
-
log_module=self.__class__.__name__,
|
|
368
|
-
log_event="llm_command_generator.predict_commands.prompt_rendered",
|
|
369
|
-
prompt=flow_prompt,
|
|
370
|
-
)
|
|
371
|
-
|
|
372
|
-
if tracker:
|
|
373
|
-
session_id = str(await self._get_or_create_session_id(tracker.sender_id))
|
|
374
|
-
else:
|
|
375
|
-
session_id = "unknown"
|
|
376
|
-
metadata = {
|
|
377
|
-
LANGFUSE_METADATA_SESSION_ID: session_id,
|
|
378
|
-
LANGFUSE_CUSTOM_METADATA_DICT: {"component": self.__class__.__name__},
|
|
379
|
-
LANGFUSE_TAGS: [self.__class__.__name__],
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
response = await self.invoke_llm(flow_prompt, metadata)
|
|
383
|
-
llm_response = LLMResponse.ensure_llm_response(response)
|
|
384
|
-
# The check for 'None' maintains compatibility with older versions
|
|
385
|
-
# of LLMCommandGenerator. In previous implementations, 'invoke_llm'
|
|
386
|
-
# might return 'None' to indicate a failure to generate actions.
|
|
387
|
-
if llm_response is None or not llm_response.choices:
|
|
388
|
-
structlogger.warning(
|
|
389
|
-
"llm_command_generator.predict_commands.no_actions_generated",
|
|
390
|
-
event_info=(
|
|
391
|
-
"No actions were generated by the LLM. Returning an ErrorCommand."
|
|
392
|
-
),
|
|
393
|
-
)
|
|
394
|
-
return [ErrorCommand()]
|
|
395
|
-
|
|
396
|
-
action_list = llm_response.choices[0]
|
|
397
|
-
|
|
398
|
-
log_llm(
|
|
399
|
-
logger=structlogger,
|
|
400
|
-
log_module=self.__class__.__name__,
|
|
401
|
-
log_event="llm_command_generator.predict_commands.actions_generated",
|
|
402
|
-
action_list=action_list,
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
commands = self.parse_commands(action_list, tracker, flows)
|
|
406
|
-
|
|
407
|
-
if CommandParserValidatorSingleton.should_validate_command_parser():
|
|
408
|
-
CommandParserValidatorSingleton.validate_if_commands_are_parsed_from_llm_response(
|
|
409
|
-
commands, action_list
|
|
410
|
-
)
|
|
411
|
-
|
|
412
|
-
self._update_message_parse_data_for_fine_tuning(message, commands, flow_prompt)
|
|
413
|
-
add_commands_to_message_parse_data(message, self.__class__.__name__, commands)
|
|
414
|
-
add_prompt_to_message_parse_data(
|
|
415
|
-
message=message,
|
|
416
|
-
component_name=self.__class__.__name__,
|
|
417
|
-
prompt_name="command_generator_prompt",
|
|
418
|
-
user_prompt=flow_prompt,
|
|
419
|
-
llm_response=llm_response,
|
|
420
|
-
)
|
|
421
|
-
|
|
422
|
-
return commands
|
|
100
|
+
def get_default_prompt_template_file_name() -> str:
|
|
101
|
+
"""Get the default prompt template file name for the command generator."""
|
|
102
|
+
return DEFAULT_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
423
103
|
|
|
424
104
|
@staticmethod
|
|
425
|
-
def
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
from rasa.llm_fine_tuning.annotation_module import preparing_fine_tuning_data
|
|
429
|
-
|
|
430
|
-
if preparing_fine_tuning_data:
|
|
431
|
-
# Add commands and prompt to the message object in order to create
|
|
432
|
-
# prompt -> commands pairs for fine-tuning
|
|
433
|
-
message.set(
|
|
434
|
-
LLM_COMMANDS,
|
|
435
|
-
[command.as_dict() for command in commands],
|
|
436
|
-
add_to_output=True,
|
|
437
|
-
)
|
|
438
|
-
message.set(LLM_PROMPT, prompt, add_to_output=True)
|
|
439
|
-
|
|
440
|
-
@classmethod
|
|
441
|
-
def parse_commands(
|
|
442
|
-
cls, actions: Optional[str], tracker: DialogueStateTracker, flows: FlowsList
|
|
443
|
-
) -> List[Command]:
|
|
444
|
-
"""Parse the actions returned by the llm into intent and entities.
|
|
445
|
-
|
|
446
|
-
Args:
|
|
447
|
-
actions: The actions returned by the llm.
|
|
448
|
-
tracker: The tracker containing the current state of the conversation.
|
|
449
|
-
flows: the list of flows
|
|
450
|
-
|
|
451
|
-
Returns:
|
|
452
|
-
The parsed commands.
|
|
453
|
-
"""
|
|
454
|
-
commands = parse_commands_using_command_parsers(actions, flows)
|
|
455
|
-
if not commands:
|
|
456
|
-
structlogger.warning(
|
|
457
|
-
f"{cls.__name__}.parse_commands",
|
|
458
|
-
message="No commands were parsed from the LLM actions.",
|
|
459
|
-
actions=actions,
|
|
460
|
-
)
|
|
105
|
+
def get_fallback_prompt_template_file_name() -> str:
|
|
106
|
+
"""Get the fallback prompt template file name for the command generator."""
|
|
107
|
+
return FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
461
108
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
self,
|
|
467
|
-
message: Message,
|
|
468
|
-
tracker: DialogueStateTracker,
|
|
469
|
-
startable_flows: FlowsList,
|
|
470
|
-
all_flows: FlowsList,
|
|
471
|
-
) -> str:
|
|
472
|
-
"""Render the jinja template to create the prompt for the LLM.
|
|
473
|
-
|
|
474
|
-
Args:
|
|
475
|
-
message: The current message from the user.
|
|
476
|
-
tracker: The tracker containing the current state of the conversation.
|
|
477
|
-
startable_flows: The flows startable at this point in time by the user.
|
|
478
|
-
all_flows: all flows present in the assistant
|
|
479
|
-
|
|
480
|
-
Returns:
|
|
481
|
-
The rendered prompt template.
|
|
482
|
-
"""
|
|
483
|
-
# need to make this distinction here because current step of the
|
|
484
|
-
# top_calling_frame would be the call step, but we need the collect step from
|
|
485
|
-
# the called frame. If no call is active calling and called frame are the same.
|
|
486
|
-
top_calling_frame = top_flow_frame(tracker.stack)
|
|
487
|
-
top_called_frame = top_flow_frame(tracker.stack, ignore_call_frames=False)
|
|
488
|
-
|
|
489
|
-
top_flow = top_calling_frame.flow(all_flows) if top_calling_frame else None
|
|
490
|
-
current_step = top_called_frame.step(all_flows) if top_called_frame else None
|
|
491
|
-
|
|
492
|
-
flow_slots = self.prepare_current_flow_slots_for_template(
|
|
493
|
-
top_flow, current_step, tracker
|
|
494
|
-
)
|
|
495
|
-
current_slot, current_slot_description = self.prepare_current_slot_for_template(
|
|
496
|
-
current_step
|
|
497
|
-
)
|
|
498
|
-
current_slot_type = None
|
|
499
|
-
current_slot_allowed_values = None
|
|
500
|
-
if current_slot:
|
|
501
|
-
current_slot_type = (
|
|
502
|
-
slot.type_name
|
|
503
|
-
if (slot := tracker.slots.get(current_slot)) is not None
|
|
504
|
-
else None
|
|
505
|
-
)
|
|
506
|
-
current_slot_allowed_values = allowed_values_for_slot(
|
|
507
|
-
tracker.slots.get(current_slot)
|
|
508
|
-
)
|
|
509
|
-
current_conversation = tracker_as_readable_transcript(tracker)
|
|
510
|
-
latest_user_message = sanitize_message_for_prompt(message.get(TEXT))
|
|
511
|
-
current_conversation += f"\nUSER: {latest_user_message}"
|
|
512
|
-
|
|
513
|
-
inputs = {
|
|
514
|
-
"available_flows": self.prepare_flows_for_template(
|
|
515
|
-
startable_flows, tracker
|
|
516
|
-
),
|
|
517
|
-
"current_conversation": current_conversation,
|
|
518
|
-
"flow_slots": flow_slots,
|
|
519
|
-
"current_flow": top_flow.id if top_flow is not None else None,
|
|
520
|
-
"current_slot": current_slot,
|
|
521
|
-
"current_slot_description": current_slot_description,
|
|
522
|
-
"current_slot_type": current_slot_type,
|
|
523
|
-
"current_slot_allowed_values": current_slot_allowed_values,
|
|
524
|
-
"user_message": latest_user_message,
|
|
525
|
-
"is_repeat_command_enabled": self.repeat_command_enabled,
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return self.compile_template(self.prompt_template).render(**inputs)
|
|
529
|
-
|
|
530
|
-
def is_repeat_command_enabled(self) -> bool:
|
|
531
|
-
"""Check for feature flag"""
|
|
532
|
-
RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME = "RASA_PRO_BETA_REPEAT_COMMAND"
|
|
533
|
-
try:
|
|
534
|
-
ensure_beta_feature_is_enabled(
|
|
535
|
-
"Repeat Command",
|
|
536
|
-
env_flag=RASA_PRO_BETA_REPEAT_COMMAND_ENV_VAR_NAME,
|
|
537
|
-
)
|
|
538
|
-
except BetaNotEnabledException:
|
|
539
|
-
return False
|
|
540
|
-
|
|
541
|
-
return True
|
|
542
|
-
|
|
543
|
-
@classmethod
|
|
544
|
-
def fingerprint_addon(cls: Any, config: Dict[str, Any]) -> Optional[str]:
|
|
545
|
-
"""Add a fingerprint for the graph."""
|
|
546
|
-
# Get the default prompt template based on the model name
|
|
547
|
-
llm_config = resolve_model_client_config(
|
|
548
|
-
config.get(LLM_CONFIG_KEY), CompactLLMCommandGenerator.__name__
|
|
549
|
-
)
|
|
550
|
-
embedding_config = resolve_model_client_config(
|
|
551
|
-
config.get(FLOW_RETRIEVAL_KEY, {}).get(EMBEDDINGS_CONFIG_KEY),
|
|
552
|
-
FlowRetrieval.__name__,
|
|
553
|
-
)
|
|
554
|
-
|
|
555
|
-
# Create a copy of the config to avoid modifying the original config
|
|
556
|
-
# and update the llm config with the resolved llm config.
|
|
557
|
-
_config_copy = copy.deepcopy(config)
|
|
558
|
-
_config_copy[LLM_CONFIG_KEY] = llm_config
|
|
559
|
-
prompt_template = cls._resolve_component_prompt_template(
|
|
560
|
-
_config_copy, log_context=LOG_COMPONENT_SOURCE_METHOD_FINGERPRINT_ADDON
|
|
561
|
-
)
|
|
562
|
-
|
|
563
|
-
return deep_container_fingerprint(
|
|
564
|
-
[prompt_template, llm_config, embedding_config]
|
|
565
|
-
)
|
|
109
|
+
@staticmethod
|
|
110
|
+
def get_model_prompt_mapper() -> Dict[str, str]:
|
|
111
|
+
"""Get the model prompt mapper for the command generator."""
|
|
112
|
+
return MODEL_PROMPT_MAPPER
|
|
566
113
|
|
|
567
114
|
@staticmethod
|
|
568
115
|
def get_default_llm_config() -> Dict[str, Any]:
|
|
@@ -573,27 +120,32 @@ class CompactLLMCommandGenerator(LLMBasedCommandGenerator):
|
|
|
573
120
|
def get_component_command_syntax_version() -> CommandSyntaxVersion:
|
|
574
121
|
return CommandSyntaxVersion.v2
|
|
575
122
|
|
|
576
|
-
@
|
|
123
|
+
@classmethod
|
|
577
124
|
def _resolve_component_prompt_template(
|
|
125
|
+
cls,
|
|
578
126
|
config: Dict[str, Any],
|
|
579
127
|
prompt_template: Optional[str] = None,
|
|
580
128
|
log_context: Optional[Literal["init", "fingerprint_addon"]] = None,
|
|
129
|
+
log_source_component: Optional[str] = "CompactLLMCommandGenerator",
|
|
581
130
|
) -> Optional[str]:
|
|
582
131
|
"""Get the prompt template from the config or the default prompt template."""
|
|
132
|
+
if prompt_template is not None:
|
|
133
|
+
return prompt_template
|
|
134
|
+
|
|
583
135
|
# Get the default prompt template based on the model name.
|
|
584
136
|
default_command_prompt_template = get_default_prompt_template_based_on_model(
|
|
585
137
|
llm_config=config.get(LLM_CONFIG_KEY, {}) or {},
|
|
586
|
-
model_prompt_mapping=
|
|
587
|
-
default_prompt_path=
|
|
588
|
-
fallback_prompt_path=
|
|
589
|
-
log_source_component=
|
|
138
|
+
model_prompt_mapping=cls.get_model_prompt_mapper(),
|
|
139
|
+
default_prompt_path=cls.get_default_prompt_template_file_name(),
|
|
140
|
+
fallback_prompt_path=cls.get_fallback_prompt_template_file_name(),
|
|
141
|
+
log_source_component=log_source_component,
|
|
590
142
|
log_source_method=log_context,
|
|
591
143
|
)
|
|
592
144
|
|
|
593
145
|
# Return the prompt template either from the config or the default prompt.
|
|
594
|
-
return
|
|
146
|
+
return get_prompt_template(
|
|
595
147
|
config.get(PROMPT_TEMPLATE_CONFIG_KEY),
|
|
596
148
|
default_command_prompt_template,
|
|
597
|
-
log_source_component=
|
|
149
|
+
log_source_component=log_source_component,
|
|
598
150
|
log_source_method=log_context,
|
|
599
151
|
)
|