Skip to content

Commit 70d9858

Browse files
authored
Merge pull request #699
Fix/colang 2 runtime issues
2 parents 48b5b96 + 12b9675 commit 70d9858

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

CHANGELOG-Colang.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1717
### Fixed
1818

1919
* [#672](https://github.com/NVIDIA/NeMo-Guardrails/pull/672) Fixes a event group match bug (e.g. `match $flow_ref.Finished() or $flow_ref.Failed()`)
20+
* [#699](https://github.com/NVIDIA/NeMo-Guardrails/pull/699) Fix issues with ActionUpdated events and user utterance action extraction.
2021

2122
## [2.0-beta.2] - 2024-07-25
2223

nemoguardrails/actions/llm/generation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ def _extract_user_message_example(self, flow: Flow):
145145
if isinstance(el, SpecOp):
146146
if el.op == "match":
147147
spec = cast(SpecOp, el).spec
148-
if spec.name != "UtteranceUserActionFinished":
148+
if (
149+
not hasattr(spec, "name")
150+
or spec.name != "UtteranceUserActionFinished"
151+
):
149152
return
150153

151154
if "final_transcript" not in spec.arguments:

nemoguardrails/colang/v2_x/library/avatars.co

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ flow user gestured $gesture -> $final_gesture
4545
$final_gesture = $event.gesture
4646

4747
@meta(user_action=True)
48-
flow user became present -> $user_id
49-
"""Wait for user to be detected as present (e.g. camera ROI)."""
48+
flow user became absent
49+
"""Wait for user to be detected as absent (e.g. out of camera ROI)."""
5050
match PresenceUserAction.Finished() as $event
51-
$user_id = $event.user_id
51+
52+
@meta(user_action=True)
53+
flow user became present
54+
"""Wait for user to be detected as present (e.g. inside camera ROI)."""
55+
match PresenceUserAction.Started() as $event
5256

5357
@meta(user_intent=True)
54-
flow user interrupted bot talking $sentence_length=15
58+
flow user interrupted bot talking $sentence_length=15 $pattern="stop"
5559
"""Wait for when the user talked while bot is speaking."""
5660
activate tracking bot talking state
5761
global $bot_talking_state
@@ -66,7 +70,7 @@ flow user interrupted bot talking $sentence_length=15
6670
or when bot said something
6771
break
6872

69-
if len($transcript) > $sentence_length
73+
if len($transcript) > $sentence_length or search($pattern,$transcript)
7074
log 'bot interrupted by user with: "{$transcript}"'
7175
return
7276

@@ -165,6 +169,12 @@ flow finish all bot actions
165169
send FinishFlow(flow_id="bot gesture")
166170
send FinishFlow(flow_id="bot posture")
167171

172+
flow fail all bot actions
173+
"""Stops all the current bot actions."""
174+
send StopFlow(flow_id="_bot_say")
175+
send StopFlow(flow_id="bot gesture")
176+
send StopFlow(flow_id="bot posture")
177+
168178
flow finish all scene actions
169179
"""Stops all the current scene actions."""
170180
send FinishFlow(flow_id="scene show choice")
@@ -173,11 +183,13 @@ flow finish all scene actions
173183
send FinishFlow(flow_id="scene show form")
174184

175185
@loop("bot_interruption")
176-
flow handling bot talking interruption $mode="inform"
186+
flow handling bot talking interruption $mode="inform" $stop_pattern="stop|cancel"
177187
"""Handling the bot talking interruption reaction."""
178-
user interrupted bot talking
188+
user interrupted bot talking $sentence_length=15 $pattern=$stop_pattern
179189
if $mode == "interrupt"
180190
finish all bot actions
191+
if $mode == "abort"
192+
fail all bot actions
181193
elif $mode == "inform"
182194
start VisualInformationSceneAction(title="Please wait with talking!", support_prompts=["You should only talk after the avatar."], content=[])
183195
wait 3.0

nemoguardrails/colang/v2_x/library/core.co

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,19 @@ flow bot refuse to respond
163163
flow tracking bot talking state
164164
"""tracking bot talking state in global variable $bot_talking_state."""
165165
global $bot_talking_state
166+
167+
# TODO: keeping both for backwards compatibility reason. To clean up.
168+
global $last_bot_script
166169
global $last_bot_message
170+
167171
if $bot_talking_state == None
168172
$bot_talking_state = False
169173
await bot started saying something
170174
$bot_talking_state = True
171175
await bot said something as $bot_said_flow
172176
$bot_talking_state = False
173177
$last_bot_script = $bot_said_flow.text
178+
$last_bot_message = $bot_said_flow.text
174179

175180
@loop("state_tracking")
176181
flow tracking user talking state

nemoguardrails/colang/v2_x/library/guardrails.co

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ flow _user_said $text -> $event
2222

2323

2424
@override
25-
flow _user_saying -> $event
25+
flow _user_saying $text -> $event
2626
"""Override core flow for when the user is saying something."""
2727
global $user_message
2828
if $text
29-
# This matches to a transcript where after some initial characters it finds $text followed optionally by up to two words
30-
match UtteranceUserAction.TranscriptUpdated(interim_transcript=regex("(?i).*({$text})((\s*\w+\s*){0,2})\W*$")) as $event
29+
if is_regex($text)
30+
match UtteranceUserAction.TranscriptUpdated(interim_transcript=$text) as $event
31+
else
32+
# This matches to a transcript where after some initial characters it finds $text followed optionally by up to two words
33+
match UtteranceUserAction.TranscriptUpdated(interim_transcript=regex("(?i).*({$text})((\s*\w+\s*){{0,2}})\W*$")) as $event
3134
else
3235
match UtteranceUserAction.TranscriptUpdated() as $event
3336

nemoguardrails/colang/v2_x/runtime/flows.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ def process_event(self, event: ActionEvent) -> None:
264264
def get_event(self, name: str, arguments: dict) -> ActionEvent:
265265
"""Returns the corresponding action event."""
266266
if name.endswith("Updated"):
267-
split_name = name.rsplit("Updated", 1)
268-
if split_name[0] == "":
269-
raise ColangSyntaxError(f"Invalid action event {name}!")
270-
arguments.update({"event_parameter_name": split_name[0]})
271-
name = "Updated"
267+
if len(name) > 7:
268+
split_name = name.rsplit("Updated", 1)
269+
if split_name[0] == "":
270+
raise ColangSyntaxError(f"Invalid action event {name}!")
271+
arguments.update({"event_parameter_name": split_name[0]})
272+
name = "Updated"
273+
else:
274+
arguments.update({"event_parameter_name": ""})
272275
if name not in Action._event_name_map:
273276
raise ColangSyntaxError(f"Invalid action event {name}!")
274277
func = getattr(self, Action._event_name_map[name])

nemoguardrails/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ def _has_property(e: Dict[str, Any], p: Property) -> bool:
128128
"UtteranceBotAction": ("bot_speech", "replace"),
129129
"UtteranceUserAction": ("user_speech", "replace"),
130130
"TimerBotAction": ("time", "parallel"),
131+
"FacialGestureBotAction": ("bot_gesture", "override"),
131132
"GestureBotAction": ("bot_gesture", "override"),
132133
"FacialGestureBotAction": ("bot_face", "replace"),
133134
"PostureBotAction": ("bot_posture", "override"),
134135
"VisualChoiceSceneAction": ("information", "override"),
135136
"VisualInformationSceneAction": ("information", "override"),
136137
"VisualFormSceneAction": ("information", "override"),
138+
"MotionEffectCameraAction": ("camera_motion_effect", "override"),
139+
"ShotCameraAction": ("camera_shot", "override"),
137140
}
138141

139142

@@ -142,8 +145,9 @@ def _add_modality_info(event_dict: Dict[str, Any]) -> None:
142145
for action_name, modality_info in _action_to_modality_info.items():
143146
modality_name, modality_policy = modality_info
144147
if action_name in event_dict["type"]:
145-
event_dict["action_info_modality"] = modality_name
146-
event_dict["action_info_modality_policy"] = modality_policy
148+
event_dict.setdefault("action_info_modality", modality_name)
149+
event_dict.setdefault("action_info_modality_policy", modality_policy)
150+
return
147151

148152

149153
def _update_action_properties(event_dict: Dict[str, Any]) -> None:

0 commit comments

Comments
 (0)