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
@@ -7,10 +7,6 @@ from rasa import telemetry
7
7
  from rasa.core.nlg.response import TemplatedNaturalLanguageGenerator
8
8
  from rasa.core.nlg.summarize import summarize_conversation
9
9
  from rasa.shared.constants import (
10
- LANGFUSE_CUSTOM_METADATA_DICT,
11
- LANGFUSE_METADATA_SESSION_ID,
12
- LANGFUSE_METADATA_USER_ID,
13
- LANGFUSE_TAGS,
14
10
  LLM_CONFIG_KEY,
15
11
  MODEL_CONFIG_KEY,
16
12
  MODEL_GROUP_ID_CONFIG_KEY,
@@ -43,7 +39,6 @@ from rasa.shared.utils.llm import (
43
39
  tracker_as_readable_transcript,
44
40
  )
45
41
  from rasa.utils.endpoints import EndpointConfig
46
- from rasa.utils.licensing import get_human_readable_licence_owner
47
42
  from rasa.utils.log_utils import log_llm
48
43
 
49
44
  structlogger = structlog.get_logger()
@@ -135,7 +130,6 @@ class ContextualResponseRephraser(
135
130
  "contextual_response_rephraser.init",
136
131
  ContextualResponseRephraser.__name__,
137
132
  )
138
- self.user_id = get_human_readable_licence_owner()
139
133
 
140
134
  @classmethod
141
135
  def _add_prompt_and_llm_metadata_to_response(
@@ -205,31 +199,20 @@ class ContextualResponseRephraser(
205
199
  return None
206
200
 
207
201
  @measure_llm_latency
208
- async def _generate_llm_response(
209
- self, prompt: str, sender_id: str
210
- ) -> Optional[LLMResponse]:
211
- """Use LLM to generate a response.
212
-
213
- Returns an LLMResponse object containing both the generated text
214
- (choices) and metadata.
202
+ async def _generate_llm_response(self, prompt: str) -> Optional[LLMResponse]:
203
+ """Use LLM to generate a response, returning an LLMResponse object
204
+ containing both the generated text (choices) and metadata.
215
205
 
216
206
  Args:
217
207
  prompt: The prompt to send to the LLM.
218
- sender_id: sender_id from the tracker.
219
208
 
220
209
  Returns:
221
210
  An LLMResponse object if successful, otherwise None.
222
211
  """
223
212
  llm = llm_factory(self.llm_config, DEFAULT_LLM_CONFIG)
224
- metadata = {
225
- LANGFUSE_METADATA_USER_ID: self.user_id,
226
- LANGFUSE_METADATA_SESSION_ID: sender_id,
227
- LANGFUSE_CUSTOM_METADATA_DICT: {"component": self.__class__.__name__},
228
- LANGFUSE_TAGS: [self.__class__.__name__],
229
- }
230
213
 
231
214
  try:
232
- return await llm.acompletion(prompt, metadata)
215
+ return await llm.acompletion(prompt)
233
216
  except Exception as e:
234
217
  # unfortunately, langchain does not wrap LLM exceptions which means
235
218
  # we have to catch all exceptions here
@@ -273,9 +256,7 @@ class ContextualResponseRephraser(
273
256
  The history for the prompt.
274
257
  """
275
258
  llm = llm_factory(self.llm_config, DEFAULT_LLM_CONFIG)
276
- return await summarize_conversation(
277
- tracker, llm, max_turns=5, user_id=self.user_id, sender_id=tracker.sender_id
278
- )
259
+ return await summarize_conversation(tracker, llm, max_turns=5)
279
260
 
280
261
  async def rephrase(
281
262
  self,
@@ -332,7 +313,7 @@ class ContextualResponseRephraser(
332
313
  or self.llm_property(MODEL_NAME_CONFIG_KEY),
333
314
  llm_model_group_id=self.llm_property(MODEL_GROUP_ID_CONFIG_KEY),
334
315
  )
335
- llm_response = await self._generate_llm_response(prompt, tracker.sender_id)
316
+ llm_response = await self._generate_llm_response(prompt)
336
317
  llm_response = LLMResponse.ensure_llm_response(llm_response)
337
318
 
338
319
  response = self._add_prompt_and_llm_metadata_to_response(
@@ -386,9 +367,12 @@ class ContextualResponseRephraser(
386
367
  Returns:
387
368
  The generated response.
388
369
  """
389
- templated_response = await super().generate(
370
+ filled_slots = tracker.current_slot_values()
371
+ stack_context = tracker.stack.current_context()
372
+ templated_response = self.generate_from_slots(
390
373
  utter_action=utter_action,
391
- tracker=tracker,
374
+ filled_slots=filled_slots,
375
+ stack_context=stack_context,
392
376
  output_channel=output_channel,
393
377
  **kwargs,
394
378
  )
@@ -6,8 +6,6 @@ from pypred import Predicate
6
6
 
7
7
  import rasa.shared.utils.common
8
8
  import rasa.shared.utils.io
9
- from rasa.core.nlg.translate import has_translation
10
- from rasa.engine.language import Language
11
9
  from rasa.shared.constants import CHANNEL, RESPONSE_CONDITION
12
10
  from rasa.shared.core.domain import Domain
13
11
  from rasa.shared.core.trackers import DialogueStateTracker
@@ -133,23 +131,11 @@ class ResponseVariationFilter:
133
131
 
134
132
  return True
135
133
 
136
- def _filter_by_language(
137
- self, responses: List[Dict[Text, Any]], language: Optional[Language] = None
138
- ) -> List[Dict[Text, Any]]:
139
- if not language:
140
- return responses
141
-
142
- if filtered := [r for r in responses if has_translation(r, language)]:
143
- return filtered
144
- # if no translation is found, return the original response variations
145
- return responses
146
-
147
134
  def responses_for_utter_action(
148
135
  self,
149
136
  utter_action: Text,
150
137
  output_channel: Text,
151
138
  filled_slots: Dict[Text, Any],
152
- language: Optional[Language] = None,
153
139
  ) -> List[Dict[Text, Any]]:
154
140
  """Returns array of responses that fit the channel, action and condition."""
155
141
  # filter responses without a condition
@@ -190,16 +176,16 @@ class ResponseVariationFilter:
190
176
  )
191
177
 
192
178
  if conditional_channel:
193
- return self._filter_by_language(conditional_channel, language)
179
+ return conditional_channel
194
180
 
195
181
  if default_channel:
196
- return self._filter_by_language(default_channel, language)
182
+ return default_channel
197
183
 
198
184
  if conditional_no_channel:
199
- return self._filter_by_language(conditional_no_channel, language)
185
+ return conditional_no_channel
200
186
 
201
187
  if default_no_channel:
202
- return self._filter_by_language(default_no_channel, language)
188
+ return default_no_channel
203
189
 
204
190
  # if there is no response variation selected,
205
191
  # return the internal error response to prevent
@@ -212,9 +198,7 @@ class ResponseVariationFilter:
212
198
  f"a default variation and that all the conditions are valid. "
213
199
  f"Returning the internal error response.",
214
200
  )
215
- return self._filter_by_language(
216
- self.responses.get("utter_internal_error_rasa", []), language
217
- )
201
+ return self.responses.get("utter_internal_error_rasa", [])
218
202
 
219
203
  def get_response_variation_id(
220
204
  self,
rasa/core/nlg/response.py CHANGED
@@ -5,11 +5,8 @@ from typing import Any, Dict, List, Optional, Text
5
5
  from rasa.core.constants import DEFAULT_TEMPLATE_ENGINE, TEMPLATE_ENGINE_CONFIG_KEY
6
6
  from rasa.core.nlg import interpolator
7
7
  from rasa.core.nlg.generator import NaturalLanguageGenerator, ResponseVariationFilter
8
- from rasa.core.nlg.translate import get_translated_buttons, get_translated_text
9
- from rasa.engine.language import Language
10
- from rasa.shared.constants import BUTTONS, RESPONSE_CONDITION, TEXT
8
+ from rasa.shared.constants import RESPONSE_CONDITION
11
9
  from rasa.shared.core.domain import RESPONSE_KEYS_TO_INTERPOLATE
12
- from rasa.shared.core.flows.constants import KEY_TRANSLATION
13
10
  from rasa.shared.core.trackers import DialogueStateTracker
14
11
  from rasa.shared.nlu.constants import METADATA
15
12
 
@@ -33,11 +30,7 @@ class TemplatedNaturalLanguageGenerator(NaturalLanguageGenerator):
33
30
 
34
31
  # noinspection PyUnusedLocal
35
32
  def _random_response_for(
36
- self,
37
- utter_action: Text,
38
- output_channel: Text,
39
- filled_slots: Dict[Text, Any],
40
- language: Optional[Language] = None,
33
+ self, utter_action: Text, output_channel: Text, filled_slots: Dict[Text, Any]
41
34
  ) -> Optional[Dict[Text, Any]]:
42
35
  """Select random response for the utter action from available ones.
43
36
 
@@ -49,7 +42,7 @@ class TemplatedNaturalLanguageGenerator(NaturalLanguageGenerator):
49
42
  if utter_action in self.responses:
50
43
  response_filter = ResponseVariationFilter(self.responses)
51
44
  suitable_responses = response_filter.responses_for_utter_action(
52
- utter_action, output_channel, filled_slots, language
45
+ utter_action, output_channel, filled_slots
53
46
  )
54
47
 
55
48
  if suitable_responses:
@@ -82,36 +75,9 @@ class TemplatedNaturalLanguageGenerator(NaturalLanguageGenerator):
82
75
  """Generate a response for the requested utter action."""
83
76
  filled_slots = tracker.current_slot_values()
84
77
  stack_context = tracker.stack.current_context()
85
- response = self.generate_from_slots(
86
- utter_action,
87
- filled_slots,
88
- stack_context,
89
- output_channel,
90
- tracker.current_language,
91
- **kwargs,
78
+ return self.generate_from_slots(
79
+ utter_action, filled_slots, stack_context, output_channel, **kwargs
92
80
  )
93
- if response is not None:
94
- return self.translate_response(response, tracker.current_language)
95
- return None
96
-
97
- def translate_response(
98
- self, response: Dict[Text, Any], language: Optional[Language] = None
99
- ) -> Dict[Text, Any]:
100
- message_copy = copy.deepcopy(response)
101
-
102
- text = get_translated_text(
103
- text=message_copy.pop(TEXT, None),
104
- translation=message_copy.pop(KEY_TRANSLATION, {}),
105
- language=language,
106
- )
107
-
108
- buttons = get_translated_buttons(
109
- buttons=message_copy.pop(BUTTONS, None), language=language
110
- )
111
- message_copy[TEXT] = text
112
- if buttons:
113
- message_copy[BUTTONS] = buttons
114
- return message_copy
115
81
 
116
82
  def generate_from_slots(
117
83
  self,
@@ -119,15 +85,12 @@ class TemplatedNaturalLanguageGenerator(NaturalLanguageGenerator):
119
85
  filled_slots: Dict[Text, Any],
120
86
  stack_context: Dict[Text, Any],
121
87
  output_channel: Text,
122
- language: Optional[Language] = None,
123
88
  **kwargs: Any,
124
89
  ) -> Optional[Dict[Text, Any]]:
125
90
  """Generate a response for the requested utter action."""
126
91
  # Fetching a random response for the passed utter action
127
92
  r = copy.deepcopy(
128
- self._random_response_for(
129
- utter_action, output_channel, filled_slots, language
130
- )
93
+ self._random_response_for(utter_action, output_channel, filled_slots)
131
94
  )
132
95
  # Filling the slots in the response with placeholders and returning the response
133
96
  if r is not None:
@@ -4,12 +4,6 @@ import structlog
4
4
  from jinja2 import Template
5
5
 
6
6
  from rasa.core.tracker_store import DialogueStateTracker
7
- from rasa.shared.constants import (
8
- LANGFUSE_CUSTOM_METADATA_DICT,
9
- LANGFUSE_METADATA_SESSION_ID,
10
- LANGFUSE_METADATA_USER_ID,
11
- LANGFUSE_TAGS,
12
- )
13
7
  from rasa.shared.providers.llm.llm_client import LLMClient
14
8
  from rasa.shared.utils.llm import (
15
9
  tracker_as_readable_transcript,
@@ -52,8 +46,6 @@ async def summarize_conversation(
52
46
  tracker: DialogueStateTracker,
53
47
  llm: LLMClient,
54
48
  max_turns: Optional[int] = MAX_TURNS_DEFAULT,
55
- user_id: Optional[str] = None,
56
- sender_id: Optional[str] = None,
57
49
  ) -> str:
58
50
  """Summarizes the dialogue using the LLM.
59
51
 
@@ -66,14 +58,8 @@ async def summarize_conversation(
66
58
  The summary of the dialogue.
67
59
  """
68
60
  prompt = _create_summarization_prompt(tracker, max_turns)
69
- metadata = {
70
- LANGFUSE_METADATA_USER_ID: user_id or "unknown",
71
- LANGFUSE_METADATA_SESSION_ID: sender_id or "",
72
- LANGFUSE_CUSTOM_METADATA_DICT: {"component": "summarize_conversation"},
73
- LANGFUSE_TAGS: ["summarize_conversation"],
74
- }
75
61
  try:
76
- llm_response = await llm.acompletion(prompt, metadata)
62
+ llm_response = await llm.acompletion(prompt)
77
63
  summarization = llm_response.choices[0].strip()
78
64
  structlogger.debug(
79
65
  "summarization.success", summarization=summarization, prompt=prompt
@@ -23,14 +23,6 @@ def get_translated_text(
23
23
  return translation.get(language_code, text)
24
24
 
25
25
 
26
- def has_translation(
27
- message: Dict[Text, Any], language: Optional[Language] = None
28
- ) -> bool:
29
- """Check if the message has a translation for the given language."""
30
- language_code = language.code if language else None
31
- return language_code in message.get(KEY_TRANSLATION, {})
32
-
33
-
34
26
  def get_translated_buttons(
35
27
  buttons: Optional[List[Dict[Text, Any]]], language: Optional[Language] = None
36
28
  ) -> Optional[List[Dict[Text, Any]]]: