rasa-pro 3.12.18.dev1__py3-none-any.whl → 3.12.19__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/core/actions/action.py +1 -4
- rasa/core/policies/intentless_policy.py +1 -3
- rasa/core/processor.py +50 -5
- rasa/core/utils.py +11 -2
- rasa/dialogue_understanding/coexistence/llm_based_router.py +1 -0
- rasa/dialogue_understanding/commands/__init__.py +4 -0
- rasa/dialogue_understanding/commands/cancel_flow_command.py +3 -1
- rasa/dialogue_understanding/commands/set_slot_command.py +6 -0
- rasa/dialogue_understanding/commands/utils.py +26 -2
- rasa/dialogue_understanding/generator/command_generator.py +11 -1
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +4 -15
- 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/single_step/compact_llm_command_generator.py +1 -14
- rasa/dialogue_understanding/processor/command_processor.py +5 -5
- 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/du_test_schema.yml +3 -3
- rasa/e2e_test/e2e_test_schema.yml +3 -3
- rasa/hooks.py +0 -55
- rasa/llm_fine_tuning/utils.py +2 -4
- rasa/shared/constants.py +0 -5
- rasa/shared/providers/constants.py +0 -9
- rasa/shared/providers/llm/_base_litellm_client.py +4 -14
- 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/tracing/instrumentation/attribute_extractors.py +2 -2
- rasa/version.py +1 -1
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.12.19.dist-info}/METADATA +1 -2
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.12.19.dist-info}/RECORD +36 -37
- rasa/monkey_patches.py +0 -91
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.12.19.dist-info}/NOTICE +0 -0
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.12.19.dist-info}/WHEEL +0 -0
- {rasa_pro-3.12.18.dev1.dist-info → rasa_pro-3.12.19.dist-info}/entry_points.txt +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
2
|
from typing import Any, Dict, Generator, List, Optional, Text
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import structlog
|
|
5
|
+
|
|
6
|
+
from rasa.dialogue_understanding.commands import Command, NoopCommand, SetSlotCommand
|
|
5
7
|
from rasa.dialogue_understanding.constants import (
|
|
6
8
|
RASA_RECORD_COMMANDS_AND_PROMPTS_ENV_VAR_NAME,
|
|
7
9
|
)
|
|
@@ -16,7 +18,6 @@ from rasa.shared.nlu.constants import (
|
|
|
16
18
|
KEY_USER_PROMPT,
|
|
17
19
|
PREDICTED_COMMANDS,
|
|
18
20
|
PROMPTS,
|
|
19
|
-
SET_SLOT_COMMAND,
|
|
20
21
|
)
|
|
21
22
|
from rasa.shared.nlu.training_data.message import Message
|
|
22
23
|
from rasa.shared.providers.llm.llm_response import LLMResponse
|
|
@@ -26,6 +27,8 @@ record_commands_and_prompts = get_bool_env_variable(
|
|
|
26
27
|
RASA_RECORD_COMMANDS_AND_PROMPTS_ENV_VAR_NAME, False
|
|
27
28
|
)
|
|
28
29
|
|
|
30
|
+
structlogger = structlog.get_logger()
|
|
31
|
+
|
|
29
32
|
|
|
30
33
|
@contextmanager
|
|
31
34
|
def set_record_commands_and_prompts() -> Generator:
|
|
@@ -144,21 +147,74 @@ def _handle_via_nlu_in_coexistence(
|
|
|
144
147
|
if not tracker:
|
|
145
148
|
return False
|
|
146
149
|
|
|
150
|
+
commands = message.get(COMMANDS, [])
|
|
151
|
+
|
|
152
|
+
# If coexistence routing slot is not active, this setup doesn't
|
|
153
|
+
# support dual routing -> default to CALM
|
|
147
154
|
if not tracker.has_coexistence_routing_slot:
|
|
155
|
+
structlogger.debug(
|
|
156
|
+
"utils.handle_via_nlu_in_coexistence"
|
|
157
|
+
".tracker_missing_route_session_to_calm_slot",
|
|
158
|
+
event_info=(
|
|
159
|
+
f"Tracker doesn't have the '{ROUTE_TO_CALM_SLOT}' slot."
|
|
160
|
+
f"Routing to CALM."
|
|
161
|
+
),
|
|
162
|
+
route_session_to_calm=commands,
|
|
163
|
+
)
|
|
148
164
|
return False
|
|
149
165
|
|
|
166
|
+
# Check if the routing decision is stored in the tracker slot
|
|
167
|
+
# If slot is true -> route to CALM
|
|
168
|
+
# If slot is false -> route to DM1
|
|
150
169
|
value = tracker.get_slot(ROUTE_TO_CALM_SLOT)
|
|
151
170
|
if value is not None:
|
|
171
|
+
structlogger.debug(
|
|
172
|
+
"utils.handle_via_nlu_in_coexistence"
|
|
173
|
+
".tracker_route_session_to_calm_slot_value",
|
|
174
|
+
event_info=(
|
|
175
|
+
f"Tracker slot '{ROUTE_TO_CALM_SLOT}' set to '{value}'. "
|
|
176
|
+
f"Routing to "
|
|
177
|
+
f"{'CALM' if value else 'NLU system'}."
|
|
178
|
+
),
|
|
179
|
+
route_session_to_calm_value_in_tracker=value,
|
|
180
|
+
)
|
|
152
181
|
return not value
|
|
153
182
|
|
|
154
|
-
# routing
|
|
155
|
-
#
|
|
156
|
-
if
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
183
|
+
# Non-sticky routing to DM1 is only allowed if NoopCommand is the sole predicted
|
|
184
|
+
# command. In that case, route to DM1
|
|
185
|
+
if len(commands) == 1 and commands[0].get("command") == NoopCommand.command():
|
|
186
|
+
structlogger.debug(
|
|
187
|
+
"utils.handle_via_nlu_in_coexistence.noop_command_detected",
|
|
188
|
+
event_info="NoopCommand found. Routing to NLU system non-sticky.",
|
|
189
|
+
commands=commands,
|
|
190
|
+
)
|
|
191
|
+
return True
|
|
192
|
+
|
|
193
|
+
# If the slot was reset (e.g. new session), try to infer routing from
|
|
194
|
+
# attached commands. Look for a SetSlotCommand targeting the ROUTE_TO_CALM_SLOT
|
|
195
|
+
for command in message.get(COMMANDS, []):
|
|
196
|
+
# If slot is true -> route to CALM
|
|
197
|
+
# If slot is false -> route to DM1
|
|
198
|
+
if (
|
|
199
|
+
command.get("command") == SetSlotCommand.command()
|
|
200
|
+
and command.get("name") == ROUTE_TO_CALM_SLOT
|
|
201
|
+
):
|
|
202
|
+
structlogger.debug(
|
|
203
|
+
"utils.handle_via_nlu_in_coexistence.set_slot_command_detected",
|
|
204
|
+
event_info=(
|
|
205
|
+
f"SetSlotCommand setting the '{ROUTE_TO_CALM_SLOT}' to "
|
|
206
|
+
f"'{command.get('value')}'. "
|
|
207
|
+
f"Routing to "
|
|
208
|
+
f"{'CALM' if command.get('value') else 'NLU system'}."
|
|
209
|
+
),
|
|
210
|
+
commands=commands,
|
|
211
|
+
)
|
|
212
|
+
return not command.get("value")
|
|
213
|
+
|
|
214
|
+
# If no routing info is available -> default to CALM
|
|
215
|
+
structlogger.debug(
|
|
216
|
+
"utils.handle_via_nlu_in_coexistence.no_routing_info_available",
|
|
217
|
+
event_info="No routing info available. Routing to CALM.",
|
|
218
|
+
commands=commands,
|
|
219
|
+
)
|
|
164
220
|
return False
|
|
@@ -5,12 +5,12 @@ mapping:
|
|
|
5
5
|
sequence:
|
|
6
6
|
- type: map
|
|
7
7
|
mapping:
|
|
8
|
-
regex;(^[a-zA-Z_]+[a-zA-Z0-9_]*$):
|
|
8
|
+
regex;(^[a-zA-Z_]+[a-zA-Z0-9_\-]*$):
|
|
9
9
|
type: "seq"
|
|
10
10
|
sequence:
|
|
11
11
|
- type: map
|
|
12
12
|
mapping:
|
|
13
|
-
regex;(^[a-zA-Z_]+[a-zA-Z0-9_]*$):
|
|
13
|
+
regex;(^[a-zA-Z_]+[a-zA-Z0-9_\-]*$):
|
|
14
14
|
type: any
|
|
15
15
|
|
|
16
16
|
metadata:
|
|
@@ -129,7 +129,7 @@ mapping:
|
|
|
129
129
|
type: "seq"
|
|
130
130
|
sequence:
|
|
131
131
|
- type: "str"
|
|
132
|
-
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_]*$
|
|
132
|
+
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_\-]*$
|
|
133
133
|
metadata:
|
|
134
134
|
type: "str"
|
|
135
135
|
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_]*$
|
|
@@ -5,12 +5,12 @@ mapping:
|
|
|
5
5
|
sequence:
|
|
6
6
|
- type: map
|
|
7
7
|
mapping:
|
|
8
|
-
regex;(^[a-zA-Z_]+[a-zA-Z0-9_]*$):
|
|
8
|
+
regex;(^[a-zA-Z_]+[a-zA-Z0-9_\-]*$):
|
|
9
9
|
type: "seq"
|
|
10
10
|
sequence:
|
|
11
11
|
- type: map
|
|
12
12
|
mapping:
|
|
13
|
-
regex;(^[a-zA-Z_]+[a-zA-Z0-9_]*$):
|
|
13
|
+
regex;(^[a-zA-Z_]+[a-zA-Z0-9_\-]*$):
|
|
14
14
|
type: any
|
|
15
15
|
|
|
16
16
|
metadata:
|
|
@@ -129,7 +129,7 @@ mapping:
|
|
|
129
129
|
type: "seq"
|
|
130
130
|
sequence:
|
|
131
131
|
- type: "str"
|
|
132
|
-
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_]*$
|
|
132
|
+
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_\-]*$
|
|
133
133
|
metadata:
|
|
134
134
|
type: "str"
|
|
135
135
|
pattern: ^[a-zA-Z_]+[a-zA-Z0-9_]*$
|
rasa/hooks.py
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import logging
|
|
3
|
-
import os
|
|
4
3
|
from typing import TYPE_CHECKING, List, Optional, Text, Union
|
|
5
4
|
|
|
6
|
-
import litellm
|
|
7
5
|
import pluggy
|
|
8
|
-
import structlog
|
|
9
|
-
|
|
10
|
-
from rasa.shared.providers.constants import (
|
|
11
|
-
LANGFUSE_CALLBACK_NAME,
|
|
12
|
-
LANGFUSE_HOST_ENV_VAR,
|
|
13
|
-
LANGFUSE_PROJECT_ID_ENV_VAR,
|
|
14
|
-
LANGFUSE_PUBLIC_KEY_ENV_VAR,
|
|
15
|
-
LANGFUSE_SECRET_KEY_ENV_VAR,
|
|
16
|
-
RASA_LANGFUSE_INTEGRATION_ENABLED_ENV_VAR,
|
|
17
|
-
)
|
|
18
6
|
|
|
19
7
|
# IMPORTANT: do not import anything from rasa here - use scoped imports
|
|
20
8
|
# this avoids circular imports, as the hooks are used in different places
|
|
@@ -30,7 +18,6 @@ if TYPE_CHECKING:
|
|
|
30
18
|
|
|
31
19
|
hookimpl = pluggy.HookimplMarker("rasa")
|
|
32
20
|
logger = logging.getLogger(__name__)
|
|
33
|
-
structlogger = structlog.get_logger()
|
|
34
21
|
|
|
35
22
|
|
|
36
23
|
@hookimpl # type: ignore[misc]
|
|
@@ -70,8 +57,6 @@ def configure_commandline(cmdline_arguments: argparse.Namespace) -> Optional[Tex
|
|
|
70
57
|
config.configure_tracing(tracer_provider)
|
|
71
58
|
config.configure_metrics(endpoints_file)
|
|
72
59
|
|
|
73
|
-
_init_langfuse_integration()
|
|
74
|
-
|
|
75
60
|
return endpoints_file
|
|
76
61
|
|
|
77
62
|
|
|
@@ -130,43 +115,3 @@ def after_server_stop() -> None:
|
|
|
130
115
|
|
|
131
116
|
if anon_pipeline is not None:
|
|
132
117
|
anon_pipeline.stop()
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _is_langfuse_integration_enabled() -> bool:
|
|
136
|
-
return (
|
|
137
|
-
os.environ.get(RASA_LANGFUSE_INTEGRATION_ENABLED_ENV_VAR, "false").lower()
|
|
138
|
-
== "true"
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def _init_langfuse_integration() -> None:
|
|
143
|
-
if not _is_langfuse_integration_enabled():
|
|
144
|
-
structlogger.info(
|
|
145
|
-
"hooks._init_langfuse_integration.disabled",
|
|
146
|
-
event_info="Langfuse integration is disabled.",
|
|
147
|
-
)
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
not os.environ.get(LANGFUSE_HOST_ENV_VAR)
|
|
152
|
-
or not os.environ.get(LANGFUSE_PROJECT_ID_ENV_VAR)
|
|
153
|
-
or not os.environ.get(LANGFUSE_PUBLIC_KEY_ENV_VAR)
|
|
154
|
-
or not os.environ.get(LANGFUSE_SECRET_KEY_ENV_VAR)
|
|
155
|
-
):
|
|
156
|
-
structlogger.warning(
|
|
157
|
-
"hooks._init_langfuse_integration.missing_langfuse_keys",
|
|
158
|
-
event_info=(
|
|
159
|
-
"Langfuse integration is enabled, but some environment variables "
|
|
160
|
-
"are missing. Please set LANGFUSE_HOST, LANGFUSE_PROJECT_ID, "
|
|
161
|
-
"LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY environment "
|
|
162
|
-
"variables to use Langfuse integration."
|
|
163
|
-
),
|
|
164
|
-
)
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
litellm.success_callback = [LANGFUSE_CALLBACK_NAME]
|
|
168
|
-
litellm.failure_callback = [LANGFUSE_CALLBACK_NAME]
|
|
169
|
-
structlogger.info(
|
|
170
|
-
"hooks.langfuse_callbacks_initialized",
|
|
171
|
-
event_info="Langfuse integration initialized.",
|
|
172
|
-
)
|
rasa/llm_fine_tuning/utils.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
2
|
from datetime import datetime
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Callable, Generator, List, Union
|
|
4
4
|
|
|
5
5
|
import structlog
|
|
6
6
|
|
|
@@ -24,9 +24,7 @@ def make_mock_invoke_llm(commands: str) -> Callable:
|
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
26
|
async def _mock_invoke_llm(
|
|
27
|
-
self: LLMBasedCommandGenerator,
|
|
28
|
-
prompt: Union[List[dict], List[str], str],
|
|
29
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
27
|
+
self: LLMBasedCommandGenerator, prompt: Union[List[dict], List[str], str]
|
|
30
28
|
) -> LLMResponse:
|
|
31
29
|
structlogger.debug(
|
|
32
30
|
f"LLM call intercepted, response mocked. "
|
rasa/shared/constants.py
CHANGED
|
@@ -342,8 +342,3 @@ ROLE_SYSTEM = "system"
|
|
|
342
342
|
# Used for key values in ValidateSlotPatternFlowStackFrame
|
|
343
343
|
REFILL_UTTER = "refill_utter"
|
|
344
344
|
REJECTIONS = "rejections"
|
|
345
|
-
|
|
346
|
-
LANGFUSE_METADATA_USER_ID = "trace_user_id"
|
|
347
|
-
LANGFUSE_METADATA_SESSION_ID = "session_id"
|
|
348
|
-
LANGFUSE_CUSTOM_METADATA_DICT = "trace_metadata"
|
|
349
|
-
LANGFUSE_TAGS = "tags"
|
|
@@ -4,12 +4,3 @@ LITE_LLM_API_KEY_FIELD = "api_key"
|
|
|
4
4
|
LITE_LLM_API_VERSION_FIELD = "api_version"
|
|
5
5
|
LITE_LLM_MODEL_FIELD = "model"
|
|
6
6
|
LITE_LLM_AZURE_AD_TOKEN = "azure_ad_token"
|
|
7
|
-
|
|
8
|
-
# Enable or disable Langfuse integration
|
|
9
|
-
RASA_LANGFUSE_INTEGRATION_ENABLED_ENV_VAR = "RASA_LANGFUSE_INTEGRATION_ENABLED"
|
|
10
|
-
# Langfuse configuration
|
|
11
|
-
LANGFUSE_CALLBACK_NAME = "langfuse"
|
|
12
|
-
LANGFUSE_HOST_ENV_VAR = "LANGFUSE_HOST"
|
|
13
|
-
LANGFUSE_PROJECT_ID_ENV_VAR = "LANGFUSE_PROJECT_ID"
|
|
14
|
-
LANGFUSE_PUBLIC_KEY_ENV_VAR = "LANGFUSE_PUBLIC_KEY"
|
|
15
|
-
LANGFUSE_SECRET_KEY_ENV_VAR = "LANGFUSE_SECRET_KEY"
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
from abc import abstractmethod
|
|
5
|
-
from typing import Any, Dict, List,
|
|
5
|
+
from typing import Any, Dict, List, Union, cast
|
|
6
6
|
|
|
7
7
|
import structlog
|
|
8
8
|
from litellm import acompletion, completion, validate_environment
|
|
@@ -126,11 +126,7 @@ class _BaseLiteLLMClient:
|
|
|
126
126
|
raise ProviderClientValidationError(event_info)
|
|
127
127
|
|
|
128
128
|
@suppress_logs(log_level=logging.WARNING)
|
|
129
|
-
def completion(
|
|
130
|
-
self,
|
|
131
|
-
messages: Union[List[dict], List[str], str],
|
|
132
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
133
|
-
) -> LLMResponse:
|
|
129
|
+
def completion(self, messages: Union[List[dict], List[str], str]) -> LLMResponse:
|
|
134
130
|
"""Synchronously generate completions for given list of messages.
|
|
135
131
|
|
|
136
132
|
Args:
|
|
@@ -142,7 +138,6 @@ class _BaseLiteLLMClient:
|
|
|
142
138
|
- a list of messages. Each message is a string and will be formatted
|
|
143
139
|
as a user message.
|
|
144
140
|
- a single message as a string which will be formatted as user message.
|
|
145
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
146
141
|
|
|
147
142
|
Returns:
|
|
148
143
|
List of message completions.
|
|
@@ -160,9 +155,7 @@ class _BaseLiteLLMClient:
|
|
|
160
155
|
|
|
161
156
|
@suppress_logs(log_level=logging.WARNING)
|
|
162
157
|
async def acompletion(
|
|
163
|
-
self,
|
|
164
|
-
messages: Union[List[dict], List[str], str],
|
|
165
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
158
|
+
self, messages: Union[List[dict], List[str], str]
|
|
166
159
|
) -> LLMResponse:
|
|
167
160
|
"""Asynchronously generate completions for given list of messages.
|
|
168
161
|
|
|
@@ -175,7 +168,6 @@ class _BaseLiteLLMClient:
|
|
|
175
168
|
- a list of messages. Each message is a string and will be formatted
|
|
176
169
|
as a user message.
|
|
177
170
|
- a single message as a string which will be formatted as user message.
|
|
178
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
179
171
|
|
|
180
172
|
Returns:
|
|
181
173
|
List of message completions.
|
|
@@ -186,9 +178,7 @@ class _BaseLiteLLMClient:
|
|
|
186
178
|
try:
|
|
187
179
|
formatted_messages = self._get_formatted_messages(messages)
|
|
188
180
|
arguments = resolve_environment_variables(self._completion_fn_args)
|
|
189
|
-
response = await acompletion(
|
|
190
|
-
messages=formatted_messages, metadata=metadata, **arguments
|
|
191
|
-
)
|
|
181
|
+
response = await acompletion(messages=formatted_messages, **arguments)
|
|
192
182
|
return self._format_response(response)
|
|
193
183
|
except Exception as e:
|
|
194
184
|
message = ""
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
-
from typing import Any, Dict, List,
|
|
4
|
+
from typing import Any, Dict, List, Union
|
|
5
5
|
|
|
6
6
|
import structlog
|
|
7
7
|
|
|
@@ -122,12 +122,9 @@ class LiteLLMRouterLLMClient(_BaseLiteLLMRouterClient, _BaseLiteLLMClient):
|
|
|
122
122
|
raise ProviderClientAPIException(e)
|
|
123
123
|
|
|
124
124
|
@suppress_logs(log_level=logging.WARNING)
|
|
125
|
-
def completion(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
129
|
-
) -> LLMResponse:
|
|
130
|
-
"""Synchronously generate completions for given list of messages.
|
|
125
|
+
def completion(self, messages: Union[List[dict], List[str], str]) -> LLMResponse:
|
|
126
|
+
"""
|
|
127
|
+
Synchronously generate completions for given list of messages.
|
|
131
128
|
|
|
132
129
|
Method overrides the base class method to call the appropriate
|
|
133
130
|
completion method based on the configuration. If the chat completions
|
|
@@ -143,11 +140,8 @@ class LiteLLMRouterLLMClient(_BaseLiteLLMRouterClient, _BaseLiteLLMClient):
|
|
|
143
140
|
- a list of messages. Each message is a string and will be formatted
|
|
144
141
|
as a user message.
|
|
145
142
|
- a single message as a string which will be formatted as user message.
|
|
146
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
147
|
-
|
|
148
143
|
Returns:
|
|
149
144
|
List of message completions.
|
|
150
|
-
|
|
151
145
|
Raises:
|
|
152
146
|
ProviderClientAPIException: If the API request fails.
|
|
153
147
|
"""
|
|
@@ -164,11 +158,10 @@ class LiteLLMRouterLLMClient(_BaseLiteLLMRouterClient, _BaseLiteLLMClient):
|
|
|
164
158
|
|
|
165
159
|
@suppress_logs(log_level=logging.WARNING)
|
|
166
160
|
async def acompletion(
|
|
167
|
-
self,
|
|
168
|
-
messages: Union[List[dict], List[str], str],
|
|
169
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
161
|
+
self, messages: Union[List[dict], List[str], str]
|
|
170
162
|
) -> LLMResponse:
|
|
171
|
-
"""
|
|
163
|
+
"""
|
|
164
|
+
Asynchronously generate completions for given list of messages.
|
|
172
165
|
|
|
173
166
|
Method overrides the base class method to call the appropriate
|
|
174
167
|
completion method based on the configuration. If the chat completions
|
|
@@ -184,11 +177,8 @@ class LiteLLMRouterLLMClient(_BaseLiteLLMRouterClient, _BaseLiteLLMClient):
|
|
|
184
177
|
- a list of messages. Each message is a string and will be formatted
|
|
185
178
|
as a user message.
|
|
186
179
|
- a single message as a string which will be formatted as user message.
|
|
187
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
188
|
-
|
|
189
180
|
Returns:
|
|
190
181
|
List of message completions.
|
|
191
|
-
|
|
192
182
|
Raises:
|
|
193
183
|
ProviderClientAPIException: If the API request fails.
|
|
194
184
|
"""
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Dict, List, Protocol, Union, runtime_checkable
|
|
4
4
|
|
|
5
5
|
from rasa.shared.providers.llm.llm_response import LLMResponse
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
@runtime_checkable
|
|
9
9
|
class LLMClient(Protocol):
|
|
10
|
-
"""
|
|
10
|
+
"""
|
|
11
|
+
Protocol for an LLM client that specifies the interface for interacting
|
|
11
12
|
with the API.
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
15
|
@classmethod
|
|
15
16
|
def from_config(cls, config: dict) -> LLMClient:
|
|
16
|
-
"""
|
|
17
|
+
"""
|
|
18
|
+
Initializes the llm client with the given configuration.
|
|
17
19
|
|
|
18
20
|
This class method should be implemented to parse the given
|
|
19
21
|
configuration and create an instance of an llm client.
|
|
@@ -22,24 +24,17 @@ class LLMClient(Protocol):
|
|
|
22
24
|
|
|
23
25
|
@property
|
|
24
26
|
def config(self) -> Dict:
|
|
25
|
-
"""
|
|
27
|
+
"""
|
|
28
|
+
Returns the configuration for that the llm client is initialized with.
|
|
26
29
|
|
|
27
30
|
This property should be implemented to return a dictionary containing
|
|
28
31
|
the configuration settings for the llm client.
|
|
29
32
|
"""
|
|
30
33
|
...
|
|
31
34
|
|
|
32
|
-
def completion(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
36
|
-
) -> LLMResponse:
|
|
37
|
-
"""Synchronously generate completions for given list of messages.
|
|
38
|
-
def completion(
|
|
39
|
-
self,
|
|
40
|
-
messages: Union[List[dict], List[str], str],
|
|
41
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
42
|
-
) -> LLMResponse:
|
|
35
|
+
def completion(self, messages: Union[List[dict], List[str], str]) -> LLMResponse:
|
|
36
|
+
"""
|
|
37
|
+
Synchronously generate completions for given list of messages.
|
|
43
38
|
|
|
44
39
|
This method should be implemented to take a list of messages (as
|
|
45
40
|
strings) and return a list of completions (as strings).
|
|
@@ -53,19 +48,16 @@ class LLMClient(Protocol):
|
|
|
53
48
|
- a list of messages. Each message is a string and will be formatted
|
|
54
49
|
as a user message.
|
|
55
50
|
- a single message as a string which will be formatted as user message.
|
|
56
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
57
|
-
|
|
58
51
|
Returns:
|
|
59
52
|
LLMResponse
|
|
60
53
|
"""
|
|
61
54
|
...
|
|
62
55
|
|
|
63
56
|
async def acompletion(
|
|
64
|
-
self,
|
|
65
|
-
messages: Union[List[dict], List[str], str],
|
|
66
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
57
|
+
self, messages: Union[List[dict], List[str], str]
|
|
67
58
|
) -> LLMResponse:
|
|
68
|
-
"""
|
|
59
|
+
"""
|
|
60
|
+
Asynchronously generate completions for given list of messages.
|
|
69
61
|
|
|
70
62
|
This method should be implemented to take a list of messages (as
|
|
71
63
|
strings) and return a list of completions (as strings).
|
|
@@ -79,15 +71,14 @@ class LLMClient(Protocol):
|
|
|
79
71
|
- a list of messages. Each message is a string and will be formatted
|
|
80
72
|
as a user message.
|
|
81
73
|
- a single message as a string which will be formatted as user message.
|
|
82
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
83
|
-
|
|
84
74
|
Returns:
|
|
85
75
|
LLMResponse
|
|
86
76
|
"""
|
|
87
77
|
...
|
|
88
78
|
|
|
89
79
|
def validate_client_setup(self, *args, **kwargs) -> None: # type: ignore
|
|
90
|
-
"""
|
|
80
|
+
"""
|
|
81
|
+
Perform client setup validation.
|
|
91
82
|
|
|
92
83
|
This method should be implemented to validate whether the client can be
|
|
93
84
|
used with the parameters provided through configuration or environment
|
|
@@ -237,9 +237,7 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
237
237
|
raise ProviderClientAPIException(e)
|
|
238
238
|
|
|
239
239
|
async def acompletion(
|
|
240
|
-
self,
|
|
241
|
-
messages: Union[List[dict], List[str], str],
|
|
242
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
240
|
+
self, messages: Union[List[dict], List[str], str]
|
|
243
241
|
) -> LLMResponse:
|
|
244
242
|
"""Asynchronous completion of the model with the given messages.
|
|
245
243
|
|
|
@@ -257,7 +255,6 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
257
255
|
- a list of messages. Each message is a string and will be formatted
|
|
258
256
|
as a user message.
|
|
259
257
|
- a single message as a string which will be formatted as user message.
|
|
260
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
261
258
|
|
|
262
259
|
Returns:
|
|
263
260
|
The completion response.
|
|
@@ -266,11 +263,7 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
266
263
|
return await super().acompletion(messages)
|
|
267
264
|
return await self._atext_completion(messages)
|
|
268
265
|
|
|
269
|
-
def completion(
|
|
270
|
-
self,
|
|
271
|
-
messages: Union[List[dict], List[str], str],
|
|
272
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
273
|
-
) -> LLMResponse:
|
|
266
|
+
def completion(self, messages: Union[List[dict], List[str], str]) -> LLMResponse:
|
|
274
267
|
"""Completion of the model with the given messages.
|
|
275
268
|
|
|
276
269
|
Method overrides the base class method to call the appropriate
|
|
@@ -280,7 +273,6 @@ class SelfHostedLLMClient(_BaseLiteLLMClient):
|
|
|
280
273
|
|
|
281
274
|
Args:
|
|
282
275
|
messages: The messages to be used for completion.
|
|
283
|
-
metadata: Optional metadata to be passed to the LLM call.
|
|
284
276
|
|
|
285
277
|
Returns:
|
|
286
278
|
The completion response.
|
|
@@ -372,7 +372,6 @@ def extract_llm_config(
|
|
|
372
372
|
def extract_attrs_for_llm_based_command_generator(
|
|
373
373
|
self: "LLMBasedCommandGenerator",
|
|
374
374
|
prompt: str,
|
|
375
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
376
375
|
) -> Dict[str, Any]:
|
|
377
376
|
from rasa.dialogue_understanding.generator.flow_retrieval import (
|
|
378
377
|
DEFAULT_EMBEDDINGS_CONFIG,
|
|
@@ -388,7 +387,8 @@ def extract_attrs_for_llm_based_command_generator(
|
|
|
388
387
|
|
|
389
388
|
|
|
390
389
|
def extract_attrs_for_contextual_response_rephraser(
|
|
391
|
-
self: Any,
|
|
390
|
+
self: Any,
|
|
391
|
+
prompt: str,
|
|
392
392
|
) -> Dict[str, Any]:
|
|
393
393
|
from rasa.core.nlg.contextual_response_rephraser import DEFAULT_LLM_CONFIG
|
|
394
394
|
|
rasa/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: rasa-pro
|
|
3
|
-
Version: 3.12.
|
|
3
|
+
Version: 3.12.19
|
|
4
4
|
Summary: State-of-the-art open-core Conversational AI framework for Enterprises that natively leverages generative AI for effortless assistant development.
|
|
5
5
|
Keywords: nlp,machine-learning,machine-learning-library,bot,bots,botkit,rasa conversational-agents,conversational-ai,chatbot,chatbot-framework,bot-framework
|
|
6
6
|
Author: Rasa Technologies GmbH
|
|
@@ -63,7 +63,6 @@ Requires-Dist: keras (==2.14.0)
|
|
|
63
63
|
Requires-Dist: langchain (>=0.2.17,<0.3.0)
|
|
64
64
|
Requires-Dist: langchain-community (>=0.2.19,<0.3.0)
|
|
65
65
|
Requires-Dist: langcodes (>=3.5.0,<4.0.0)
|
|
66
|
-
Requires-Dist: langfuse (>=2.60.2,<2.61.0)
|
|
67
66
|
Requires-Dist: litellm (>=1.69.0,<1.70.0)
|
|
68
67
|
Requires-Dist: matplotlib (>=3.7,<3.8)
|
|
69
68
|
Requires-Dist: mattermostwrapper (>=2.2,<2.3)
|