rasa-pro 3.12.6.dev2__py3-none-any.whl → 3.13.0.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rasa-pro might be problematic. Click here for more details.

Files changed (92) hide show
  1. rasa/__init__.py +0 -6
  2. rasa/cli/scaffold.py +1 -1
  3. rasa/core/actions/action.py +38 -34
  4. rasa/core/actions/action_run_slot_rejections.py +1 -1
  5. rasa/core/channels/studio_chat.py +16 -43
  6. rasa/core/channels/voice_ready/audiocodes.py +46 -17
  7. rasa/core/information_retrieval/faiss.py +68 -7
  8. rasa/core/information_retrieval/information_retrieval.py +40 -2
  9. rasa/core/information_retrieval/milvus.py +7 -2
  10. rasa/core/information_retrieval/qdrant.py +7 -2
  11. rasa/core/nlg/contextual_response_rephraser.py +11 -27
  12. rasa/core/nlg/generator.py +5 -21
  13. rasa/core/nlg/response.py +6 -43
  14. rasa/core/nlg/summarize.py +1 -15
  15. rasa/core/nlg/translate.py +0 -8
  16. rasa/core/policies/enterprise_search_policy.py +64 -316
  17. rasa/core/policies/flows/flow_executor.py +3 -38
  18. rasa/core/policies/intentless_policy.py +4 -17
  19. rasa/core/policies/policy.py +0 -2
  20. rasa/core/processor.py +27 -6
  21. rasa/core/utils.py +53 -0
  22. rasa/dialogue_understanding/coexistence/llm_based_router.py +4 -18
  23. rasa/dialogue_understanding/commands/cancel_flow_command.py +4 -59
  24. rasa/dialogue_understanding/commands/knowledge_answer_command.py +2 -2
  25. rasa/dialogue_understanding/commands/start_flow_command.py +0 -41
  26. rasa/dialogue_understanding/generator/command_generator.py +67 -0
  27. rasa/dialogue_understanding/generator/command_parser.py +1 -1
  28. rasa/dialogue_understanding/generator/llm_based_command_generator.py +7 -23
  29. rasa/dialogue_understanding/generator/llm_command_generator.py +1 -3
  30. rasa/dialogue_understanding/generator/prompt_templates/command_prompt_template.jinja2 +1 -1
  31. rasa/dialogue_understanding/generator/prompt_templates/command_prompt_v2_claude_3_5_sonnet_20240620_template.jinja2 +1 -1
  32. rasa/dialogue_understanding/generator/prompt_templates/command_prompt_v2_gpt_4o_2024_11_20_template.jinja2 +24 -2
  33. rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +8 -12
  34. rasa/dialogue_understanding/patterns/default_flows_for_patterns.yml +0 -61
  35. rasa/dialogue_understanding/processor/command_processor.py +7 -65
  36. rasa/dialogue_understanding/stack/utils.py +0 -38
  37. rasa/dialogue_understanding_test/command_metric_calculation.py +7 -40
  38. rasa/dialogue_understanding_test/command_metrics.py +38 -0
  39. rasa/dialogue_understanding_test/du_test_case.py +58 -25
  40. rasa/dialogue_understanding_test/du_test_result.py +228 -132
  41. rasa/dialogue_understanding_test/du_test_runner.py +10 -1
  42. rasa/dialogue_understanding_test/io.py +48 -16
  43. rasa/document_retrieval/__init__.py +0 -0
  44. rasa/document_retrieval/constants.py +32 -0
  45. rasa/document_retrieval/document_post_processor.py +351 -0
  46. rasa/document_retrieval/document_post_processor_prompt_template.jinja2 +0 -0
  47. rasa/document_retrieval/document_retriever.py +333 -0
  48. rasa/document_retrieval/knowledge_base_connectors/__init__.py +0 -0
  49. rasa/document_retrieval/knowledge_base_connectors/api_connector.py +39 -0
  50. rasa/document_retrieval/knowledge_base_connectors/knowledge_base_connector.py +34 -0
  51. rasa/document_retrieval/knowledge_base_connectors/vector_store_connector.py +226 -0
  52. rasa/document_retrieval/query_rewriter.py +234 -0
  53. rasa/document_retrieval/query_rewriter_prompt_template.jinja2 +8 -0
  54. rasa/engine/recipes/default_components.py +2 -0
  55. rasa/hooks.py +0 -55
  56. rasa/model_manager/model_api.py +1 -1
  57. rasa/model_manager/socket_bridge.py +0 -7
  58. rasa/shared/constants.py +0 -5
  59. rasa/shared/core/constants.py +0 -8
  60. rasa/shared/core/domain.py +12 -3
  61. rasa/shared/core/flows/flow.py +0 -17
  62. rasa/shared/core/flows/flows_yaml_schema.json +3 -38
  63. rasa/shared/core/flows/steps/collect.py +5 -18
  64. rasa/shared/core/flows/utils.py +1 -16
  65. rasa/shared/core/slot_mappings.py +11 -5
  66. rasa/shared/core/slots.py +1 -1
  67. rasa/shared/core/trackers.py +4 -10
  68. rasa/shared/nlu/constants.py +0 -1
  69. rasa/shared/providers/constants.py +0 -9
  70. rasa/shared/providers/llm/_base_litellm_client.py +4 -14
  71. rasa/shared/providers/llm/default_litellm_llm_client.py +2 -2
  72. rasa/shared/providers/llm/litellm_router_llm_client.py +7 -17
  73. rasa/shared/providers/llm/llm_client.py +15 -24
  74. rasa/shared/providers/llm/self_hosted_llm_client.py +2 -10
  75. rasa/shared/utils/common.py +11 -1
  76. rasa/shared/utils/health_check/health_check.py +1 -7
  77. rasa/shared/utils/llm.py +1 -1
  78. rasa/tracing/instrumentation/attribute_extractors.py +50 -17
  79. rasa/tracing/instrumentation/instrumentation.py +12 -12
  80. rasa/tracing/instrumentation/intentless_policy_instrumentation.py +1 -2
  81. rasa/utils/licensing.py +0 -15
  82. rasa/validator.py +1 -123
  83. rasa/version.py +1 -1
  84. {rasa_pro-3.12.6.dev2.dist-info → rasa_pro-3.13.0.dev2.dist-info}/METADATA +2 -3
  85. {rasa_pro-3.12.6.dev2.dist-info → rasa_pro-3.13.0.dev2.dist-info}/RECORD +88 -80
  86. rasa/core/actions/action_handle_digressions.py +0 -164
  87. rasa/dialogue_understanding/commands/handle_digressions_command.py +0 -144
  88. rasa/dialogue_understanding/patterns/handle_digressions.py +0 -81
  89. rasa/monkey_patches.py +0 -91
  90. {rasa_pro-3.12.6.dev2.dist-info → rasa_pro-3.13.0.dev2.dist-info}/NOTICE +0 -0
  91. {rasa_pro-3.12.6.dev2.dist-info → rasa_pro-3.13.0.dev2.dist-info}/WHEEL +0 -0
  92. {rasa_pro-3.12.6.dev2.dist-info → rasa_pro-3.13.0.dev2.dist-info}/entry_points.txt +0 -0
@@ -1,144 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import Any, Dict, List
5
-
6
- import structlog
7
-
8
- from rasa.dialogue_understanding.commands.command import Command
9
- from rasa.dialogue_understanding.patterns.cannot_handle import (
10
- CannotHandlePatternFlowStackFrame,
11
- )
12
- from rasa.dialogue_understanding.patterns.handle_digressions import (
13
- HandleDigressionsPatternFlowStackFrame,
14
- )
15
- from rasa.dialogue_understanding.stack.utils import (
16
- top_flow_frame,
17
- )
18
- from rasa.shared.core.events import Event
19
- from rasa.shared.core.flows import FlowsList
20
- from rasa.shared.core.flows.steps import CollectInformationFlowStep
21
- from rasa.shared.core.flows.utils import ALL_LABEL
22
- from rasa.shared.core.trackers import DialogueStateTracker
23
- from rasa.shared.nlu.constants import HANDLE_DIGRESSIONS_COMMAND
24
-
25
- structlogger = structlog.get_logger()
26
-
27
-
28
- @dataclass
29
- class HandleDigressionsCommand(Command):
30
- """A command to handle digressions during an active flow."""
31
-
32
- flow: str
33
- """The interrupting flow."""
34
-
35
- @classmethod
36
- def command(cls) -> str:
37
- """Returns the command type."""
38
- return HANDLE_DIGRESSIONS_COMMAND
39
-
40
- @classmethod
41
- def from_dict(cls, data: Dict[str, Any]) -> HandleDigressionsCommand:
42
- """Converts the dictionary to a command.
43
-
44
- Returns:
45
- The converted dictionary.
46
- """
47
- try:
48
- return HandleDigressionsCommand(flow=data["flow"])
49
- except KeyError as e:
50
- raise ValueError(
51
- f"Missing parameter '{e}' while parsing HandleDigressionsCommand."
52
- ) from e
53
-
54
- def run_command_on_tracker(
55
- self,
56
- tracker: DialogueStateTracker,
57
- all_flows: FlowsList,
58
- original_tracker: DialogueStateTracker,
59
- ) -> List[Event]:
60
- """Runs the command on the tracker.
61
-
62
- Args:
63
- tracker: The tracker to run the command on.
64
- all_flows: All flows in the assistant.
65
- original_tracker: The tracker before any command was executed.
66
-
67
- Returns:
68
- The events to apply to the tracker.
69
- """
70
- stack = tracker.stack
71
- original_stack = original_tracker.stack
72
-
73
- if self.flow not in all_flows.flow_ids:
74
- structlogger.debug(
75
- "command_executor.push_cannot_handle.start_invalid_flow_id",
76
- command=self,
77
- )
78
- stack.push(CannotHandlePatternFlowStackFrame())
79
- return tracker.create_stack_updated_events(stack)
80
-
81
- # this allows to include called user flows in the stack search
82
- latest_user_frame = top_flow_frame(original_stack, ignore_call_frames=False)
83
-
84
- if latest_user_frame is None:
85
- structlogger.debug(
86
- "command_executor.skip_command.no_top_flow", command=self
87
- )
88
- return []
89
-
90
- original_top_flow = latest_user_frame.flow(all_flows)
91
- current_step = original_top_flow.step_by_id(latest_user_frame.step_id)
92
- if not isinstance(current_step, CollectInformationFlowStep):
93
- structlogger.debug(
94
- "command_executor.skip_command.not_at_a_collect_step", command=self
95
- )
96
- return []
97
-
98
- ask_confirm_digressions = set(
99
- current_step.ask_confirm_digressions
100
- + original_top_flow.ask_confirm_digressions
101
- )
102
-
103
- block_digressions = set(
104
- current_step.block_digressions + original_top_flow.block_digressions
105
- )
106
-
107
- if block_digressions:
108
- if ALL_LABEL in block_digressions:
109
- block_digressions.remove(ALL_LABEL)
110
- block_digressions.add(self.flow)
111
-
112
- if ask_confirm_digressions:
113
- if ALL_LABEL in ask_confirm_digressions:
114
- ask_confirm_digressions.remove(ALL_LABEL)
115
- ask_confirm_digressions.add(self.flow)
116
-
117
- structlogger.debug(
118
- "command_executor.push_handle_digressions",
119
- interrupting_flow_id=self.flow,
120
- interrupted_flow_id=original_top_flow.id,
121
- interrupted_step_id=current_step.id,
122
- ask_confirm_digressions=ask_confirm_digressions,
123
- block_digressions=block_digressions,
124
- )
125
- stack.push(
126
- HandleDigressionsPatternFlowStackFrame(
127
- interrupting_flow_id=self.flow,
128
- interrupted_flow_id=original_top_flow.id,
129
- interrupted_step_id=current_step.id,
130
- ask_confirm_digressions=ask_confirm_digressions,
131
- block_digressions=block_digressions,
132
- )
133
- )
134
-
135
- return tracker.create_stack_updated_events(stack)
136
-
137
- def __hash__(self) -> int:
138
- return hash(self.flow)
139
-
140
- def __eq__(self, other: object) -> bool:
141
- if not isinstance(other, HandleDigressionsCommand):
142
- return False
143
-
144
- return other.flow == self.flow
@@ -1,81 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass, field
4
- from typing import Any, Dict, Set
5
-
6
- from rasa.dialogue_understanding.stack.frames import PatternFlowStackFrame
7
- from rasa.shared.constants import RASA_DEFAULT_FLOW_PATTERN_PREFIX
8
- from rasa.shared.core.constants import (
9
- KEY_ASK_CONFIRM_DIGRESSIONS,
10
- KEY_BLOCK_DIGRESSIONS,
11
- )
12
-
13
- FLOW_PATTERN_HANDLE_DIGRESSIONS = (
14
- RASA_DEFAULT_FLOW_PATTERN_PREFIX + "handle_digressions"
15
- )
16
-
17
-
18
- @dataclass
19
- class HandleDigressionsPatternFlowStackFrame(PatternFlowStackFrame):
20
- """A pattern flow stack frame that gets added if an interruption is completed."""
21
-
22
- flow_id: str = FLOW_PATTERN_HANDLE_DIGRESSIONS
23
- """The ID of the flow."""
24
- interrupting_flow_id: str = ""
25
- """The ID of the flow that interrupted the active flow."""
26
- interrupted_flow_id: str = ""
27
- """The name of the active flow that was interrupted."""
28
- interrupted_step_id: str = ""
29
- """The ID of the step that was interrupted."""
30
- ask_confirm_digressions: Set[str] = field(default_factory=set)
31
- """The set of interrupting flow names to confirm."""
32
- block_digressions: Set[str] = field(default_factory=set)
33
- """The set of interrupting flow names to block."""
34
-
35
- @classmethod
36
- def type(cls) -> str:
37
- """Returns the type of the frame."""
38
- return FLOW_PATTERN_HANDLE_DIGRESSIONS
39
-
40
- @staticmethod
41
- def from_dict(data: Dict[str, Any]) -> HandleDigressionsPatternFlowStackFrame:
42
- """Creates a `DialogueStackFrame` from a dictionary.
43
-
44
- Args:
45
- data: The dictionary to create the `DialogueStackFrame` from.
46
-
47
- Returns:
48
- The created `DialogueStackFrame`.
49
- """
50
- return HandleDigressionsPatternFlowStackFrame(
51
- frame_id=data["frame_id"],
52
- step_id=data["step_id"],
53
- interrupted_step_id=data["interrupted_step_id"],
54
- interrupted_flow_id=data["interrupted_flow_id"],
55
- interrupting_flow_id=data["interrupting_flow_id"],
56
- ask_confirm_digressions=set(data.get(KEY_ASK_CONFIRM_DIGRESSIONS, [])),
57
- # This attribute must be converted to a set to enable usage
58
- # of subset `contains` pypred operator in the default pattern
59
- # conditional branching
60
- block_digressions=set(data.get(KEY_BLOCK_DIGRESSIONS, [])),
61
- )
62
-
63
- def __eq__(self, other: Any) -> bool:
64
- if not isinstance(other, HandleDigressionsPatternFlowStackFrame):
65
- return False
66
- return (
67
- self.flow_id == other.flow_id
68
- and self.interrupted_step_id == other.interrupted_step_id
69
- and self.interrupted_flow_id == other.interrupted_flow_id
70
- and self.interrupting_flow_id == other.interrupting_flow_id
71
- and self.ask_confirm_digressions == other.ask_confirm_digressions
72
- and self.block_digressions == other.block_digressions
73
- )
74
-
75
- def as_dict(self) -> Dict[str, Any]:
76
- """Returns the frame as a dictionary."""
77
- data = super().as_dict()
78
- # converting back to list to avoid serialization issues
79
- data[KEY_ASK_CONFIRM_DIGRESSIONS] = list(self.ask_confirm_digressions)
80
- data[KEY_BLOCK_DIGRESSIONS] = list(self.block_digressions)
81
- return data
rasa/monkey_patches.py DELETED
@@ -1,91 +0,0 @@
1
- import os
2
- import traceback
3
- from typing import Any, Optional
4
-
5
- from litellm.secret_managers.main import str_to_bool
6
- from packaging.version import Version
7
-
8
-
9
- def litellm_langfuse_logger_init_fixed(
10
- self: Any, # we should not import LangfuseLogger class before we patch it
11
- langfuse_public_key: Optional[str] = None,
12
- langfuse_secret: Optional[str] = None,
13
- langfuse_host: str = "https://cloud.langfuse.com",
14
- flush_interval: int = 1,
15
- ) -> None:
16
- """Monkeypatched version of LangfuseLogger.__init__ from the LiteLLM library.
17
-
18
- This patched version removes a call that fetched the `project_id` from
19
- Langfuse Cloud even when it was already set via environment variables.
20
- In the original implementation, this call was made *before* initializing
21
- the LangfuseClient, which caused the application to freeze for up to 60 seconds.
22
-
23
- By removing this premature call, the monkeypatch avoids the unnecessary network
24
- request and prevents the timeout/freeze issue.
25
-
26
- This workaround can be removed once the underlying bug is resolved in LiteLLM:
27
- https://github.com/BerriAI/litellm/issues/7732
28
- """
29
- try:
30
- import langfuse
31
- from langfuse import Langfuse
32
- except Exception as e:
33
- raise Exception(
34
- f"\033[91mLangfuse not installed, try running 'pip install langfuse' "
35
- f"to fix this error: {e}\n{traceback.format_exc()}\033[0m"
36
- )
37
- # Instance variables
38
- self.secret_key = langfuse_secret or os.getenv("LANGFUSE_SECRET_KEY", "")
39
- self.public_key = langfuse_public_key or os.getenv("LANGFUSE_PUBLIC_KEY", "")
40
-
41
- self.langfuse_host = langfuse_host or os.getenv(
42
- "LANGFUSE_HOST", "https://cloud.langfuse.com"
43
- )
44
- self.langfuse_host.replace("http://", "https://")
45
- if not self.langfuse_host.startswith("https://"):
46
- self.langfuse_host = "https://" + self.langfuse_host
47
-
48
- self.langfuse_release = os.getenv("LANGFUSE_RELEASE")
49
- self.langfuse_debug = os.getenv("LANGFUSE_DEBUG")
50
- self.langfuse_flush_interval = (
51
- os.getenv("LANGFUSE_FLUSH_INTERVAL") or flush_interval
52
- )
53
-
54
- parameters = {
55
- "public_key": self.public_key,
56
- "secret_key": self.secret_key,
57
- "host": self.langfuse_host,
58
- "release": self.langfuse_release,
59
- "debug": self.langfuse_debug,
60
- "flush_interval": self.langfuse_flush_interval, # flush interval in seconds
61
- }
62
-
63
- if Version(langfuse.version.__version__) >= Version("2.6.0"):
64
- parameters["sdk_integration"] = "litellm"
65
-
66
- self.Langfuse = Langfuse(**parameters)
67
-
68
- if os.getenv("UPSTREAM_LANGFUSE_SECRET_KEY") is not None:
69
- upstream_langfuse_debug = (
70
- str_to_bool(self.upstream_langfuse_debug)
71
- if self.upstream_langfuse_debug is not None
72
- else None
73
- )
74
- self.upstream_langfuse_secret_key = os.getenv("UPSTREAM_LANGFUSE_SECRET_KEY")
75
- self.upstream_langfuse_public_key = os.getenv("UPSTREAM_LANGFUSE_PUBLIC_KEY")
76
- self.upstream_langfuse_host = os.getenv("UPSTREAM_LANGFUSE_HOST")
77
- self.upstream_langfuse_release = os.getenv("UPSTREAM_LANGFUSE_RELEASE")
78
- self.upstream_langfuse_debug = os.getenv("UPSTREAM_LANGFUSE_DEBUG")
79
- self.upstream_langfuse = Langfuse(
80
- public_key=self.upstream_langfuse_public_key,
81
- secret_key=self.upstream_langfuse_secret_key,
82
- host=self.upstream_langfuse_host,
83
- release=self.upstream_langfuse_release,
84
- debug=(
85
- upstream_langfuse_debug
86
- if upstream_langfuse_debug is not None
87
- else False
88
- ),
89
- )
90
- else:
91
- self.upstream_langfuse = None