rasa-pro 3.8.18__py3-none-any.whl → 3.9.14__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 +6 -42
- rasa/__main__.py +14 -9
- rasa/anonymization/anonymization_pipeline.py +0 -1
- rasa/anonymization/anonymization_rule_executor.py +3 -3
- rasa/anonymization/utils.py +4 -3
- rasa/api.py +2 -2
- rasa/cli/arguments/default_arguments.py +1 -1
- rasa/cli/arguments/run.py +2 -2
- rasa/cli/arguments/test.py +1 -1
- rasa/cli/arguments/train.py +10 -10
- rasa/cli/e2e_test.py +27 -7
- rasa/cli/export.py +0 -1
- rasa/cli/license.py +3 -3
- rasa/cli/project_templates/calm/actions/action_template.py +1 -1
- rasa/cli/project_templates/calm/config.yml +1 -1
- rasa/cli/project_templates/calm/credentials.yml +1 -1
- rasa/cli/project_templates/calm/data/flows/add_contact.yml +1 -1
- rasa/cli/project_templates/calm/data/flows/remove_contact.yml +1 -1
- rasa/cli/project_templates/calm/domain/add_contact.yml +8 -2
- rasa/cli/project_templates/calm/domain/list_contacts.yml +3 -0
- rasa/cli/project_templates/calm/domain/remove_contact.yml +9 -2
- rasa/cli/project_templates/calm/domain/shared.yml +5 -0
- rasa/cli/project_templates/calm/endpoints.yml +4 -4
- rasa/cli/project_templates/default/actions/actions.py +1 -1
- rasa/cli/project_templates/default/config.yml +5 -5
- rasa/cli/project_templates/default/credentials.yml +1 -1
- rasa/cli/project_templates/default/endpoints.yml +4 -4
- rasa/cli/project_templates/default/tests/test_stories.yml +1 -1
- rasa/cli/project_templates/tutorial/config.yml +1 -1
- rasa/cli/project_templates/tutorial/credentials.yml +1 -1
- rasa/cli/project_templates/tutorial/data/patterns.yml +6 -0
- rasa/cli/project_templates/tutorial/domain.yml +4 -0
- rasa/cli/project_templates/tutorial/endpoints.yml +6 -6
- rasa/cli/run.py +0 -1
- rasa/cli/scaffold.py +3 -2
- rasa/cli/studio/download.py +11 -0
- rasa/cli/studio/studio.py +180 -24
- rasa/cli/studio/upload.py +0 -8
- rasa/cli/telemetry.py +18 -6
- rasa/cli/utils.py +21 -10
- rasa/cli/x.py +3 -2
- rasa/constants.py +1 -1
- rasa/core/actions/action.py +90 -315
- rasa/core/actions/action_exceptions.py +24 -0
- rasa/core/actions/constants.py +3 -0
- rasa/core/actions/custom_action_executor.py +188 -0
- rasa/core/actions/forms.py +11 -7
- rasa/core/actions/grpc_custom_action_executor.py +251 -0
- rasa/core/actions/http_custom_action_executor.py +140 -0
- rasa/core/actions/loops.py +3 -0
- rasa/core/actions/two_stage_fallback.py +1 -1
- rasa/core/agent.py +2 -4
- rasa/core/brokers/pika.py +1 -2
- rasa/core/channels/audiocodes.py +1 -1
- rasa/core/channels/botframework.py +0 -1
- rasa/core/channels/callback.py +0 -1
- rasa/core/channels/console.py +6 -8
- rasa/core/channels/development_inspector.py +1 -1
- rasa/core/channels/facebook.py +0 -3
- rasa/core/channels/hangouts.py +0 -6
- rasa/core/channels/inspector/dist/assets/{arc-5623b6dc.js → arc-b6e548fe.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{c4Diagram-d0fbc5ce-685c106a.js → c4Diagram-d0fbc5ce-fa03ac9e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-936ed81e-8cbed007.js → classDiagram-936ed81e-ee67392a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{classDiagram-v2-c3cb15f1-5889cf12.js → classDiagram-v2-c3cb15f1-9b283fae.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{createText-62fc7601-24c249d7.js → createText-62fc7601-8b6fcc2a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{edges-f2ad444c-7dd06a75.js → edges-f2ad444c-22e77f4f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{erDiagram-9d236eb7-62c1e54c.js → erDiagram-9d236eb7-60ffc87f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDb-1972c806-ce49b86f.js → flowDb-1972c806-9dd802e4.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{flowDiagram-7ea5b25a-4067e48f.js → flowDiagram-7ea5b25a-5fa1912f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-1844e5a5.js +1 -0
- rasa/core/channels/inspector/dist/assets/{flowchart-elk-definition-abe16c3d-59fe4051.js → flowchart-elk-definition-abe16c3d-622a1fd2.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{ganttDiagram-9b5ea136-47e3a43b.js → ganttDiagram-9b5ea136-e285a63a.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{gitGraphDiagram-99d0ae7c-5a2ac0d9.js → gitGraphDiagram-99d0ae7c-f237bdca.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-2c4b9a3b-dfb8efc4.js → index-2c4b9a3b-4b03d70e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{index-268a75c0.js → index-a5d3e69d.js} +4 -4
- rasa/core/channels/inspector/dist/assets/{infoDiagram-736b4530-b0c470f2.js → infoDiagram-736b4530-72a0fa5f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{journeyDiagram-df861f2b-2edb829a.js → journeyDiagram-df861f2b-82218c41.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{layout-b6873d69.js → layout-78cff630.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{line-1efc5781.js → line-5038b469.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{linear-661e9b94.js → linear-c4fc4098.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{mindmap-definition-beec6740-2d2e727f.js → mindmap-definition-beec6740-c33c8ea6.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{pieDiagram-dbbf0591-9d3ea93d.js → pieDiagram-dbbf0591-a8d03059.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{quadrantDiagram-4d7f4fd6-06a178a2.js → quadrantDiagram-4d7f4fd6-6a0e56b2.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{requirementDiagram-6fc4c22a-0bfedffc.js → requirementDiagram-6fc4c22a-2dc7c7bd.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sankeyDiagram-8f13d901-d76d0a04.js → sankeyDiagram-8f13d901-2360fe39.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{sequenceDiagram-b655622a-37bb4341.js → sequenceDiagram-b655622a-41b9f9ad.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-59f0c015-f52f7f57.js → stateDiagram-59f0c015-0aad326f.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{stateDiagram-v2-2b26beab-4a986a20.js → stateDiagram-v2-2b26beab-9847d984.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-080da4f6-7dd9ae12.js → styles-080da4f6-564d890e.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-3dcbcfbf-46e1ca14.js → styles-3dcbcfbf-38957613.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{styles-9c745c82-4a97439a.js → styles-9c745c82-f0fc6921.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{svgDrawCommon-4835440b-823917a3.js → svgDrawCommon-4835440b-ef3c5a77.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{timeline-definition-5b62e21b-9ea72896.js → timeline-definition-5b62e21b-bf3e91c1.js} +1 -1
- rasa/core/channels/inspector/dist/assets/{xychartDiagram-2b33534f-b631a8b6.js → xychartDiagram-2b33534f-4d4026c0.js} +1 -1
- rasa/core/channels/inspector/dist/index.html +1 -1
- rasa/core/channels/inspector/src/components/DiagramFlow.tsx +10 -0
- rasa/core/channels/inspector/src/helpers/formatters.test.ts +4 -7
- rasa/core/channels/inspector/src/helpers/formatters.ts +3 -2
- rasa/core/channels/rest.py +36 -21
- rasa/core/channels/rocketchat.py +0 -1
- rasa/core/channels/socketio.py +1 -1
- rasa/core/channels/telegram.py +3 -3
- rasa/core/channels/webexteams.py +0 -1
- rasa/core/concurrent_lock_store.py +1 -1
- rasa/core/evaluation/marker_base.py +1 -3
- rasa/core/evaluation/marker_stats.py +1 -2
- rasa/core/featurizers/single_state_featurizer.py +3 -26
- rasa/core/featurizers/tracker_featurizers.py +18 -122
- rasa/core/information_retrieval/__init__.py +7 -0
- rasa/core/information_retrieval/faiss.py +9 -4
- rasa/core/information_retrieval/information_retrieval.py +64 -7
- rasa/core/information_retrieval/milvus.py +7 -14
- rasa/core/information_retrieval/qdrant.py +8 -15
- rasa/core/lock_store.py +0 -1
- rasa/core/migrate.py +1 -2
- rasa/core/nlg/callback.py +3 -4
- rasa/core/policies/enterprise_search_policy.py +86 -22
- rasa/core/policies/enterprise_search_prompt_template.jinja2 +4 -41
- rasa/core/policies/enterprise_search_prompt_with_citation_template.jinja2 +60 -0
- rasa/core/policies/flows/flow_executor.py +104 -2
- rasa/core/policies/intentless_policy.py +7 -9
- rasa/core/policies/memoization.py +3 -3
- rasa/core/policies/policy.py +18 -9
- rasa/core/policies/rule_policy.py +8 -11
- rasa/core/policies/ted_policy.py +61 -88
- rasa/core/policies/unexpected_intent_policy.py +8 -17
- rasa/core/processor.py +136 -47
- rasa/core/run.py +41 -25
- rasa/core/secrets_manager/endpoints.py +2 -2
- rasa/core/secrets_manager/vault.py +6 -8
- rasa/core/test.py +3 -5
- rasa/core/tracker_store.py +49 -14
- rasa/core/train.py +1 -3
- rasa/core/training/interactive.py +9 -6
- rasa/core/utils.py +5 -10
- rasa/dialogue_understanding/coexistence/intent_based_router.py +11 -4
- rasa/dialogue_understanding/coexistence/llm_based_router.py +2 -3
- rasa/dialogue_understanding/commands/__init__.py +4 -0
- rasa/dialogue_understanding/commands/can_not_handle_command.py +9 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +9 -0
- rasa/dialogue_understanding/commands/change_flow_command.py +38 -0
- rasa/dialogue_understanding/commands/chit_chat_answer_command.py +9 -0
- rasa/dialogue_understanding/commands/clarify_command.py +9 -0
- rasa/dialogue_understanding/commands/correct_slots_command.py +9 -0
- rasa/dialogue_understanding/commands/error_command.py +12 -0
- rasa/dialogue_understanding/commands/handle_code_change_command.py +9 -0
- rasa/dialogue_understanding/commands/human_handoff_command.py +9 -0
- rasa/dialogue_understanding/commands/knowledge_answer_command.py +9 -0
- rasa/dialogue_understanding/commands/noop_command.py +9 -0
- rasa/dialogue_understanding/commands/set_slot_command.py +34 -3
- rasa/dialogue_understanding/commands/skip_question_command.py +9 -0
- rasa/dialogue_understanding/commands/start_flow_command.py +9 -0
- rasa/dialogue_understanding/generator/__init__.py +16 -1
- rasa/dialogue_understanding/generator/command_generator.py +92 -6
- rasa/dialogue_understanding/generator/constants.py +18 -0
- rasa/dialogue_understanding/generator/flow_retrieval.py +7 -5
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +467 -0
- rasa/dialogue_understanding/generator/llm_command_generator.py +39 -609
- 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 +827 -0
- rasa/dialogue_understanding/generator/nlu_command_adapter.py +69 -8
- rasa/dialogue_understanding/generator/single_step/__init__.py +0 -0
- rasa/dialogue_understanding/generator/single_step/single_step_llm_command_generator.py +345 -0
- rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +44 -39
- rasa/dialogue_understanding/processor/command_processor.py +111 -3
- rasa/e2e_test/constants.py +1 -0
- rasa/e2e_test/e2e_test_case.py +44 -0
- rasa/e2e_test/e2e_test_runner.py +114 -11
- rasa/e2e_test/e2e_test_schema.yml +18 -0
- rasa/engine/caching.py +0 -1
- rasa/engine/graph.py +18 -6
- rasa/engine/recipes/config_files/default_config.yml +3 -3
- rasa/engine/recipes/default_components.py +1 -1
- rasa/engine/recipes/default_recipe.py +4 -5
- rasa/engine/recipes/recipe.py +1 -1
- rasa/engine/runner/dask.py +3 -9
- rasa/engine/storage/local_model_storage.py +0 -2
- rasa/engine/validation.py +179 -145
- rasa/exceptions.py +2 -2
- rasa/graph_components/validators/default_recipe_validator.py +3 -5
- rasa/hooks.py +0 -1
- rasa/model.py +1 -1
- rasa/model_training.py +1 -0
- rasa/nlu/classifiers/diet_classifier.py +33 -52
- rasa/nlu/classifiers/logistic_regression_classifier.py +9 -22
- rasa/nlu/classifiers/sklearn_intent_classifier.py +16 -37
- rasa/nlu/extractors/crf_entity_extractor.py +54 -97
- rasa/nlu/extractors/duckling_entity_extractor.py +1 -1
- rasa/nlu/featurizers/dense_featurizer/convert_featurizer.py +1 -5
- rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py +0 -4
- rasa/nlu/featurizers/featurizer.py +1 -1
- rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +18 -49
- rasa/nlu/featurizers/sparse_featurizer/lexical_syntactic_featurizer.py +26 -64
- rasa/nlu/featurizers/sparse_featurizer/regex_featurizer.py +3 -5
- rasa/nlu/persistor.py +68 -26
- rasa/nlu/selectors/response_selector.py +7 -10
- rasa/nlu/test.py +0 -3
- rasa/nlu/utils/hugging_face/registry.py +1 -1
- rasa/nlu/utils/spacy_utils.py +1 -3
- rasa/server.py +22 -7
- rasa/shared/constants.py +12 -1
- rasa/shared/core/command_payload_reader.py +109 -0
- rasa/shared/core/constants.py +4 -5
- rasa/shared/core/domain.py +57 -56
- rasa/shared/core/events.py +4 -7
- rasa/shared/core/flows/flow.py +9 -0
- rasa/shared/core/flows/flows_list.py +12 -0
- rasa/shared/core/flows/steps/action.py +7 -2
- rasa/shared/core/generator.py +12 -11
- rasa/shared/core/slot_mappings.py +315 -24
- rasa/shared/core/slots.py +4 -2
- rasa/shared/core/trackers.py +32 -14
- rasa/shared/core/training_data/loading.py +0 -1
- rasa/shared/core/training_data/story_reader/story_reader.py +3 -3
- rasa/shared/core/training_data/story_reader/yaml_story_reader.py +11 -11
- rasa/shared/core/training_data/story_writer/yaml_story_writer.py +5 -3
- rasa/shared/core/training_data/structures.py +1 -1
- rasa/shared/core/training_data/visualization.py +1 -1
- rasa/shared/data.py +58 -1
- rasa/shared/exceptions.py +36 -2
- rasa/shared/importers/importer.py +1 -2
- rasa/shared/importers/rasa.py +0 -1
- rasa/shared/nlu/constants.py +2 -0
- rasa/shared/nlu/training_data/entities_parser.py +1 -2
- rasa/shared/nlu/training_data/features.py +2 -120
- rasa/shared/nlu/training_data/formats/dialogflow.py +3 -2
- rasa/shared/nlu/training_data/formats/rasa_yaml.py +3 -5
- rasa/shared/nlu/training_data/formats/readerwriter.py +0 -1
- rasa/shared/nlu/training_data/message.py +13 -0
- rasa/shared/nlu/training_data/training_data.py +0 -2
- rasa/shared/providers/openai/session_handler.py +2 -2
- rasa/shared/utils/constants.py +3 -0
- rasa/shared/utils/io.py +11 -1
- rasa/shared/utils/llm.py +1 -2
- rasa/shared/utils/pykwalify_extensions.py +1 -0
- rasa/shared/utils/schemas/domain.yml +3 -0
- rasa/shared/utils/yaml.py +44 -35
- rasa/studio/auth.py +26 -10
- rasa/studio/constants.py +2 -0
- rasa/studio/data_handler.py +114 -107
- rasa/studio/download.py +160 -27
- rasa/studio/results_logger.py +137 -0
- rasa/studio/train.py +6 -7
- rasa/studio/upload.py +159 -134
- rasa/telemetry.py +188 -34
- rasa/tracing/config.py +18 -3
- rasa/tracing/constants.py +26 -2
- rasa/tracing/instrumentation/attribute_extractors.py +50 -41
- rasa/tracing/instrumentation/instrumentation.py +290 -44
- rasa/tracing/instrumentation/intentless_policy_instrumentation.py +7 -5
- rasa/tracing/instrumentation/metrics.py +109 -21
- rasa/tracing/metric_instrument_provider.py +83 -3
- rasa/utils/cli.py +2 -1
- rasa/utils/common.py +1 -1
- rasa/utils/endpoints.py +1 -2
- rasa/utils/io.py +72 -6
- rasa/utils/licensing.py +246 -31
- rasa/utils/ml_utils.py +1 -1
- rasa/utils/tensorflow/data_generator.py +1 -1
- rasa/utils/tensorflow/environment.py +1 -1
- rasa/utils/tensorflow/model_data.py +201 -12
- rasa/utils/tensorflow/model_data_utils.py +499 -500
- rasa/utils/tensorflow/models.py +5 -6
- rasa/utils/tensorflow/rasa_layers.py +15 -15
- rasa/utils/train_utils.py +1 -1
- rasa/utils/url_tools.py +53 -0
- rasa/validator.py +305 -3
- rasa/version.py +1 -1
- {rasa_pro-3.8.18.dist-info → rasa_pro-3.9.14.dist-info}/METADATA +25 -61
- {rasa_pro-3.8.18.dist-info → rasa_pro-3.9.14.dist-info}/RECORD +276 -259
- rasa/core/channels/inspector/dist/assets/flowDiagram-v2-855bc5b3-85583a23.js +0 -1
- rasa/utils/tensorflow/feature_array.py +0 -370
- /rasa/dialogue_understanding/generator/{command_prompt_template.jinja2 → single_step/command_prompt_template.jinja2} +0 -0
- {rasa_pro-3.8.18.dist-info → rasa_pro-3.9.14.dist-info}/NOTICE +0 -0
- {rasa_pro-3.8.18.dist-info → rasa_pro-3.9.14.dist-info}/WHEEL +0 -0
- {rasa_pro-3.8.18.dist-info → rasa_pro-3.9.14.dist-info}/entry_points.txt +0 -0
|
@@ -5,11 +5,23 @@ import psutil
|
|
|
5
5
|
from rasa.core.nlg.contextual_response_rephraser import ContextualResponseRephraser
|
|
6
6
|
from rasa.core.policies.enterprise_search_policy import EnterpriseSearchPolicy
|
|
7
7
|
from rasa.core.policies.intentless_policy import IntentlessPolicy
|
|
8
|
-
from rasa.dialogue_understanding.generator import
|
|
8
|
+
from rasa.dialogue_understanding.generator import (
|
|
9
|
+
LLMCommandGenerator,
|
|
10
|
+
SingleStepLLMCommandGenerator,
|
|
11
|
+
MultiStepLLMCommandGenerator,
|
|
12
|
+
)
|
|
9
13
|
from rasa.tracing.constants import (
|
|
10
14
|
LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
11
15
|
LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
12
16
|
LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
17
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
18
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
19
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
20
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
21
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
22
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
23
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
24
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
13
25
|
PROMPT_TOKEN_LENGTH_ATTRIBUTE_NAME,
|
|
14
26
|
LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
15
27
|
ENTERPRISE_SEARCH_POLICY_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
@@ -17,14 +29,15 @@ from rasa.tracing.constants import (
|
|
|
17
29
|
CONTEXTUAL_RESPONSE_REPHRASER_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
18
30
|
RASA_CLIENT_REQUEST_BODY_SIZE_METRIC_NAME,
|
|
19
31
|
RASA_CLIENT_REQUEST_DURATION_METRIC_NAME,
|
|
20
|
-
|
|
32
|
+
REQUEST_BODY_SIZE_IN_BYTES_ATTRIBUTE_NAME,
|
|
21
33
|
)
|
|
22
34
|
from rasa.tracing.metric_instrument_provider import MetricInstrumentProvider
|
|
23
35
|
from rasa.utils.endpoints import EndpointConfig
|
|
24
36
|
|
|
25
37
|
|
|
26
|
-
def
|
|
38
|
+
def record_llm_based_command_generator_cpu_usage(
|
|
27
39
|
metric_instrument_provider: MetricInstrumentProvider,
|
|
40
|
+
metric_name: str,
|
|
28
41
|
) -> None:
|
|
29
42
|
"""Record CPU usage as a percentage.
|
|
30
43
|
|
|
@@ -32,11 +45,10 @@ def record_llm_command_generator_cpu_usage(
|
|
|
32
45
|
This instrument is registered to the MetricInstrumentProvider internal singleton.
|
|
33
46
|
|
|
34
47
|
:param metric_instrument_provider: The MetricInstrumentProvider instance
|
|
48
|
+
:param metric_name: The name of the metric instrument
|
|
35
49
|
:return: None
|
|
36
50
|
"""
|
|
37
|
-
metric_instrument = metric_instrument_provider.get_instrument(
|
|
38
|
-
LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME
|
|
39
|
-
)
|
|
51
|
+
metric_instrument = metric_instrument_provider.get_instrument(metric_name)
|
|
40
52
|
if not metric_instrument:
|
|
41
53
|
return None
|
|
42
54
|
|
|
@@ -44,8 +56,9 @@ def record_llm_command_generator_cpu_usage(
|
|
|
44
56
|
metric_instrument.record(amount=cpu_usage)
|
|
45
57
|
|
|
46
58
|
|
|
47
|
-
def
|
|
59
|
+
def record_llm_based_command_generator_memory_usage(
|
|
48
60
|
metric_instrument_provider: MetricInstrumentProvider,
|
|
61
|
+
metric_name: str,
|
|
49
62
|
) -> None:
|
|
50
63
|
"""Record memory usage as a percentage.
|
|
51
64
|
|
|
@@ -53,11 +66,10 @@ def record_llm_command_generator_memory_usage(
|
|
|
53
66
|
This instrument is registered to the MetricInstrumentProvider internal singleton.
|
|
54
67
|
|
|
55
68
|
:param metric_instrument_provider: The MetricInstrumentProvider instance
|
|
69
|
+
:param metric_name: The name of the metric instrument
|
|
56
70
|
:return: None
|
|
57
71
|
"""
|
|
58
|
-
metric_instrument = metric_instrument_provider.get_instrument(
|
|
59
|
-
LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME
|
|
60
|
-
)
|
|
72
|
+
metric_instrument = metric_instrument_provider.get_instrument(metric_name)
|
|
61
73
|
if not metric_instrument:
|
|
62
74
|
return None
|
|
63
75
|
|
|
@@ -65,9 +77,10 @@ def record_llm_command_generator_memory_usage(
|
|
|
65
77
|
metric_instrument.record(amount=memory_usage)
|
|
66
78
|
|
|
67
79
|
|
|
68
|
-
def
|
|
80
|
+
def record_llm_based_command_generator_prompt_token(
|
|
69
81
|
metric_instrument_provider: MetricInstrumentProvider,
|
|
70
82
|
attributes: Dict[str, Any],
|
|
83
|
+
metric_name: str,
|
|
71
84
|
) -> None:
|
|
72
85
|
"""
|
|
73
86
|
Record prompt token length.
|
|
@@ -77,14 +90,13 @@ def record_llm_command_generator_prompt_token(
|
|
|
77
90
|
|
|
78
91
|
:param metric_instrument_provider: The MetricInstrumentProvider instance
|
|
79
92
|
:param attributes: Extracted tracing attributes
|
|
93
|
+
:param metric_name: The name of the metric instrument
|
|
80
94
|
:return: None
|
|
81
95
|
"""
|
|
82
96
|
if PROMPT_TOKEN_LENGTH_ATTRIBUTE_NAME not in attributes:
|
|
83
97
|
return None
|
|
84
98
|
|
|
85
|
-
metric_instrument = metric_instrument_provider.get_instrument(
|
|
86
|
-
LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME
|
|
87
|
-
)
|
|
99
|
+
metric_instrument = metric_instrument_provider.get_instrument(metric_name)
|
|
88
100
|
if not metric_instrument:
|
|
89
101
|
return None
|
|
90
102
|
|
|
@@ -115,9 +127,75 @@ def record_llm_command_generator_metrics(attributes: Dict[str, Any]) -> None:
|
|
|
115
127
|
if not instrument_provider.instruments:
|
|
116
128
|
return None
|
|
117
129
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
record_llm_based_command_generator_cpu_usage(
|
|
131
|
+
instrument_provider, LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME
|
|
132
|
+
)
|
|
133
|
+
record_llm_based_command_generator_memory_usage(
|
|
134
|
+
instrument_provider, LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME
|
|
135
|
+
)
|
|
136
|
+
record_llm_based_command_generator_prompt_token(
|
|
137
|
+
instrument_provider,
|
|
138
|
+
attributes,
|
|
139
|
+
LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def record_single_step_llm_command_generator_metrics(
|
|
144
|
+
attributes: Dict[str, Any],
|
|
145
|
+
) -> None:
|
|
146
|
+
"""
|
|
147
|
+
Record measurements for SingleStepLLMCommandGenerator specific metrics.
|
|
148
|
+
|
|
149
|
+
The recording is done by the opentelemetry.metrics.Histogram instruments.
|
|
150
|
+
These instruments are registered to the MetricInstrumentProvider internal singleton.
|
|
151
|
+
|
|
152
|
+
:param attributes: Extracted tracing attributes
|
|
153
|
+
:return: None
|
|
154
|
+
"""
|
|
155
|
+
instrument_provider = MetricInstrumentProvider()
|
|
156
|
+
|
|
157
|
+
if not instrument_provider.instruments:
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
record_llm_based_command_generator_cpu_usage(
|
|
161
|
+
instrument_provider, SINGLE_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME
|
|
162
|
+
)
|
|
163
|
+
record_llm_based_command_generator_memory_usage(
|
|
164
|
+
instrument_provider, SINGLE_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME
|
|
165
|
+
)
|
|
166
|
+
record_llm_based_command_generator_prompt_token(
|
|
167
|
+
instrument_provider,
|
|
168
|
+
attributes,
|
|
169
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def record_multi_step_llm_command_generator_metrics(attributes: Dict[str, Any]) -> None:
|
|
174
|
+
"""
|
|
175
|
+
Record measurements for MultiStepLLMCommandGenerator specific metrics.
|
|
176
|
+
|
|
177
|
+
The recording is done by the opentelemetry.metrics.Histogram instruments.
|
|
178
|
+
These instruments are registered to the MetricInstrumentProvider internal singleton.
|
|
179
|
+
|
|
180
|
+
:param attributes: Extracted tracing attributes
|
|
181
|
+
:return: None
|
|
182
|
+
"""
|
|
183
|
+
instrument_provider = MetricInstrumentProvider()
|
|
184
|
+
|
|
185
|
+
if not instrument_provider.instruments:
|
|
186
|
+
return None
|
|
187
|
+
|
|
188
|
+
record_llm_based_command_generator_cpu_usage(
|
|
189
|
+
instrument_provider, MULTI_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME
|
|
190
|
+
)
|
|
191
|
+
record_llm_based_command_generator_memory_usage(
|
|
192
|
+
instrument_provider, MULTI_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME
|
|
193
|
+
)
|
|
194
|
+
record_llm_based_command_generator_prompt_token(
|
|
195
|
+
instrument_provider,
|
|
196
|
+
attributes,
|
|
197
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
198
|
+
)
|
|
121
199
|
|
|
122
200
|
|
|
123
201
|
def record_callable_duration_metrics(
|
|
@@ -126,6 +204,8 @@ def record_callable_duration_metrics(
|
|
|
126
204
|
"""
|
|
127
205
|
Record duration of instrumented method calls invoked for the following components:
|
|
128
206
|
- LLMCommandGenerator
|
|
207
|
+
- SingleStepLLMCommandGenerator
|
|
208
|
+
- MultiStepLLMCommandGenerator
|
|
129
209
|
- EnterpriseSearchPolicy
|
|
130
210
|
- IntentlessPolicy
|
|
131
211
|
- ContextualResponseRephraser
|
|
@@ -145,11 +225,21 @@ def record_callable_duration_metrics(
|
|
|
145
225
|
metric_instrument = None
|
|
146
226
|
attributes = {}
|
|
147
227
|
|
|
148
|
-
if
|
|
228
|
+
if type(self) == LLMCommandGenerator:
|
|
149
229
|
metric_instrument = instrument_provider.get_instrument(
|
|
150
230
|
LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME
|
|
151
231
|
)
|
|
152
232
|
|
|
233
|
+
if type(self) == SingleStepLLMCommandGenerator:
|
|
234
|
+
metric_instrument = instrument_provider.get_instrument(
|
|
235
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
if type(self) == MultiStepLLMCommandGenerator:
|
|
239
|
+
metric_instrument = instrument_provider.get_instrument(
|
|
240
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME
|
|
241
|
+
)
|
|
242
|
+
|
|
153
243
|
if isinstance(self, EnterpriseSearchPolicy):
|
|
154
244
|
metric_instrument = instrument_provider.get_instrument(
|
|
155
245
|
ENTERPRISE_SEARCH_POLICY_LLM_RESPONSE_DURATION_METRIC_NAME
|
|
@@ -200,7 +290,5 @@ def record_request_size_in_bytes(attributes: Dict[str, Any]) -> None:
|
|
|
200
290
|
if not metric_instrument:
|
|
201
291
|
return None
|
|
202
292
|
|
|
203
|
-
request_body_size = attributes.pop(
|
|
204
|
-
ENDPOINT_REQUEST_BODY_SIZE_IN_BYTES_ATTRIBUTE_NAME, 0
|
|
205
|
-
)
|
|
293
|
+
request_body_size = attributes.pop(REQUEST_BODY_SIZE_IN_BYTES_ATTRIBUTE_NAME, 0)
|
|
206
294
|
metric_instrument.record(amount=request_body_size, attributes=attributes)
|
|
@@ -9,7 +9,15 @@ from rasa.tracing.constants import (
|
|
|
9
9
|
LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
10
10
|
LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
11
11
|
LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
12
|
-
|
|
12
|
+
LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
13
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
14
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
15
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
16
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
17
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
18
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
19
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
20
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
13
21
|
DURATION_UNIT_NAME,
|
|
14
22
|
ENTERPRISE_SEARCH_POLICY_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
15
23
|
INTENTLESS_POLICY_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
@@ -34,6 +42,8 @@ class MetricInstrumentProvider(metaclass=Singleton):
|
|
|
34
42
|
|
|
35
43
|
instruments = {
|
|
36
44
|
**self._create_llm_command_generator_instruments(meter),
|
|
45
|
+
**self._create_single_step_llm_command_generator_instruments(meter),
|
|
46
|
+
**self._create_multi_step_llm_command_generator_instruments(meter),
|
|
37
47
|
**self._create_llm_response_duration_instruments(meter),
|
|
38
48
|
**self._create_client_request_instruments(meter),
|
|
39
49
|
}
|
|
@@ -49,13 +59,13 @@ class MetricInstrumentProvider(metaclass=Singleton):
|
|
|
49
59
|
llm_command_generator_cpu_usage = meter.create_histogram(
|
|
50
60
|
name=LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
51
61
|
description="CPU percentage for LLMCommandGenerator",
|
|
52
|
-
unit=
|
|
62
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
53
63
|
)
|
|
54
64
|
|
|
55
65
|
llm_command_generator_memory_usage = meter.create_histogram(
|
|
56
66
|
name=LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
57
67
|
description="RAM memory usage for LLMCommandGenerator",
|
|
58
|
-
unit=
|
|
68
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
59
69
|
)
|
|
60
70
|
|
|
61
71
|
llm_command_generator_prompt_token_usage = meter.create_histogram(
|
|
@@ -77,6 +87,76 @@ class MetricInstrumentProvider(metaclass=Singleton):
|
|
|
77
87
|
LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME: llm_response_duration_llm_command_generator, # noqa: E501
|
|
78
88
|
}
|
|
79
89
|
|
|
90
|
+
@staticmethod
|
|
91
|
+
def _create_single_step_llm_command_generator_instruments(
|
|
92
|
+
meter: Meter,
|
|
93
|
+
) -> Dict[str, Any]:
|
|
94
|
+
single_step_llm_command_generator_cpu_usage = meter.create_histogram(
|
|
95
|
+
name=SINGLE_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
96
|
+
description="CPU percentage for SingleStepLLMCommandGenerator",
|
|
97
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
single_step_llm_command_generator_memory_usage = meter.create_histogram(
|
|
101
|
+
name=SINGLE_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
102
|
+
description="RAM memory usage for SingleStepLLMCommandGenerator",
|
|
103
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
single_step_llm_command_generator_prompt_token_usage = meter.create_histogram(
|
|
107
|
+
name=SINGLE_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
108
|
+
description="SingleStepLLMCommandGenerator prompt token length",
|
|
109
|
+
unit="1",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
single_step_llm_response_duration_llm_command_generator = meter.create_histogram( # noqa: E501
|
|
113
|
+
name=SINGLE_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
114
|
+
description="The duration of SingleStepLLMCommandGenerator's LLM call",
|
|
115
|
+
unit=DURATION_UNIT_NAME,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME: single_step_llm_command_generator_cpu_usage, # noqa: E501
|
|
120
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME: single_step_llm_command_generator_memory_usage, # noqa: E501
|
|
121
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME: single_step_llm_command_generator_prompt_token_usage, # noqa: E501
|
|
122
|
+
SINGLE_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME: single_step_llm_response_duration_llm_command_generator, # noqa: E501
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def _create_multi_step_llm_command_generator_instruments(
|
|
127
|
+
meter: Meter,
|
|
128
|
+
) -> Dict[str, Any]:
|
|
129
|
+
multi_step_llm_command_generator_cpu_usage = meter.create_histogram(
|
|
130
|
+
name=MULTI_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME,
|
|
131
|
+
description="CPU percentage for MultiStepLLMCommandGenerator",
|
|
132
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
multi_step_llm_command_generator_memory_usage = meter.create_histogram(
|
|
136
|
+
name=MULTI_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME,
|
|
137
|
+
description="RAM memory usage for MultiStepLLMCommandGenerator",
|
|
138
|
+
unit=LLM_BASED_COMMAND_GENERATOR_CPU_MEMORY_USAGE_UNIT_NAME,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
multi_step_llm_command_generator_prompt_token_usage = meter.create_histogram(
|
|
142
|
+
name=MULTI_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME,
|
|
143
|
+
description="MultiStepLLMCommandGenerator prompt token length",
|
|
144
|
+
unit="1",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
multi_step_llm_response_duration_llm_command_generator = meter.create_histogram(
|
|
148
|
+
name=MULTI_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME,
|
|
149
|
+
description="The duration of MultiStepLLMCommandGenerator's LLM call",
|
|
150
|
+
unit=DURATION_UNIT_NAME,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_CPU_USAGE_METRIC_NAME: multi_step_llm_command_generator_cpu_usage, # noqa: E501
|
|
155
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_MEMORY_USAGE_METRIC_NAME: multi_step_llm_command_generator_memory_usage, # noqa: E501
|
|
156
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_PROMPT_TOKEN_USAGE_METRIC_NAME: multi_step_llm_command_generator_prompt_token_usage, # noqa: E501
|
|
157
|
+
MULTI_STEP_LLM_COMMAND_GENERATOR_LLM_RESPONSE_DURATION_METRIC_NAME: multi_step_llm_response_duration_llm_command_generator, # noqa: E501
|
|
158
|
+
}
|
|
159
|
+
|
|
80
160
|
@staticmethod
|
|
81
161
|
def _create_llm_response_duration_instruments(meter: Meter) -> Dict[str, Any]:
|
|
82
162
|
llm_response_duration_enterprise_search = meter.create_histogram(
|
rasa/utils/cli.py
CHANGED
rasa/utils/common.py
CHANGED
|
@@ -520,7 +520,7 @@ class RepeatedLogFilter(logging.Filter):
|
|
|
520
520
|
|
|
521
521
|
|
|
522
522
|
async def call_potential_coroutine(
|
|
523
|
-
coroutine_or_return_value: Union[Any, Coroutine]
|
|
523
|
+
coroutine_or_return_value: Union[Any, Coroutine],
|
|
524
524
|
) -> Any:
|
|
525
525
|
"""Awaits coroutine or returns value directly if it's not a coroutine.
|
|
526
526
|
|
rasa/utils/endpoints.py
CHANGED
|
@@ -17,7 +17,7 @@ structlogger = structlog.get_logger()
|
|
|
17
17
|
def read_endpoint_config(
|
|
18
18
|
filename: Text, endpoint_type: Text
|
|
19
19
|
) -> Optional["EndpointConfig"]:
|
|
20
|
-
"""Read an endpoint configuration file from disk and extract one config."""
|
|
20
|
+
"""Read an endpoint configuration file from disk and extract one config."""
|
|
21
21
|
if not filename:
|
|
22
22
|
return None
|
|
23
23
|
|
|
@@ -298,6 +298,5 @@ def int_arg(
|
|
|
298
298
|
try:
|
|
299
299
|
return int(str(arg))
|
|
300
300
|
except (ValueError, TypeError):
|
|
301
|
-
|
|
302
301
|
structlogger.warning("endpoint.int_arg.convert_failed", arg=arg, key=key)
|
|
303
302
|
return default
|
rasa/utils/io.py
CHANGED
|
@@ -2,6 +2,7 @@ import asyncio
|
|
|
2
2
|
import filecmp
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
|
+
import pickle
|
|
5
6
|
import tempfile
|
|
6
7
|
import warnings
|
|
7
8
|
import re
|
|
@@ -97,6 +98,29 @@ def enable_async_loop_debugging(
|
|
|
97
98
|
return event_loop
|
|
98
99
|
|
|
99
100
|
|
|
101
|
+
def pickle_dump(filename: Union[Text, Path], obj: Any) -> None:
|
|
102
|
+
"""Saves object to file.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
filename: the filename to save the object to
|
|
106
|
+
obj: the object to store
|
|
107
|
+
"""
|
|
108
|
+
with open(filename, "wb") as f:
|
|
109
|
+
pickle.dump(obj, f)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def pickle_load(filename: Union[Text, Path]) -> Any:
|
|
113
|
+
"""Loads an object from a file.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
filename: the filename to load the object from
|
|
117
|
+
|
|
118
|
+
Returns: the loaded object
|
|
119
|
+
"""
|
|
120
|
+
with open(filename, "rb") as f:
|
|
121
|
+
return pickle.load(f)
|
|
122
|
+
|
|
123
|
+
|
|
100
124
|
def create_temporary_file(data: Any, suffix: Text = "", mode: Text = "w+") -> Text:
|
|
101
125
|
"""Creates a tempfile.NamedTemporaryFile object for data."""
|
|
102
126
|
encoding = None if "b" in mode else rasa.shared.utils.io.DEFAULT_ENCODING
|
|
@@ -167,16 +191,58 @@ def create_validator(
|
|
|
167
191
|
return FunctionValidator
|
|
168
192
|
|
|
169
193
|
|
|
194
|
+
def json_unpickle(
|
|
195
|
+
file_name: Union[Text, Path], encode_non_string_keys: bool = False
|
|
196
|
+
) -> Any:
|
|
197
|
+
"""Unpickle an object from file using json.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
file_name: the file to load the object from
|
|
201
|
+
encode_non_string_keys: If set to `True` then jsonpickle will encode non-string
|
|
202
|
+
dictionary keys instead of coercing them into strings via `repr()`.
|
|
203
|
+
|
|
204
|
+
Returns: the object
|
|
205
|
+
"""
|
|
206
|
+
import jsonpickle.ext.numpy as jsonpickle_numpy
|
|
207
|
+
import jsonpickle
|
|
208
|
+
|
|
209
|
+
jsonpickle_numpy.register_handlers()
|
|
210
|
+
|
|
211
|
+
file_content = rasa.shared.utils.io.read_file(file_name)
|
|
212
|
+
return jsonpickle.loads(file_content, keys=encode_non_string_keys)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def json_pickle(
|
|
216
|
+
file_name: Union[Text, Path], obj: Any, encode_non_string_keys: bool = False
|
|
217
|
+
) -> None:
|
|
218
|
+
"""Pickle an object to a file using json.
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
file_name: the file to store the object to
|
|
222
|
+
obj: the object to store
|
|
223
|
+
encode_non_string_keys: If set to `True` then jsonpickle will encode non-string
|
|
224
|
+
dictionary keys instead of coercing them into strings via `repr()`.
|
|
225
|
+
"""
|
|
226
|
+
import jsonpickle.ext.numpy as jsonpickle_numpy
|
|
227
|
+
import jsonpickle
|
|
228
|
+
|
|
229
|
+
jsonpickle_numpy.register_handlers()
|
|
230
|
+
|
|
231
|
+
rasa.shared.utils.io.write_text_file(
|
|
232
|
+
jsonpickle.dumps(obj, keys=encode_non_string_keys), file_name
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
170
236
|
def get_emoji_regex() -> Pattern:
|
|
171
237
|
"""Returns regex to identify emojis."""
|
|
172
238
|
return re.compile(
|
|
173
239
|
"["
|
|
174
|
-
"\
|
|
175
|
-
"\
|
|
176
|
-
"\
|
|
177
|
-
"\
|
|
178
|
-
"\U00002702-\
|
|
179
|
-
"\
|
|
240
|
+
"\U0001f600-\U0001f64f" # emoticons
|
|
241
|
+
"\U0001f300-\U0001f5ff" # symbols & pictographs
|
|
242
|
+
"\U0001f680-\U0001f6ff" # transport & map symbols
|
|
243
|
+
"\U0001f1e0-\U0001f1ff" # flags (iOS)
|
|
244
|
+
"\U00002702-\U000027b0"
|
|
245
|
+
"\U000024c2-\U0001f251"
|
|
180
246
|
"\u200d" # zero width joiner
|
|
181
247
|
"\u200c" # zero width non-joiner
|
|
182
248
|
"]+",
|