Skip to content

Commit 466da04

Browse files
authored
Merge pull request #578 from NVIDIA/feature/improve-bot-action-generation
Feature/improve bot action generation
2 parents a45b71a + 557f293 commit 466da04

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

nemoguardrails/actions/llm/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,23 @@ def get_first_bot_intent(strings: List[str]) -> Optional[str]:
508508

509509
def get_first_bot_action(strings: List[str]) -> Optional[str]:
510510
"""Returns first bot action."""
511-
action: Optional[str] = None
511+
action_started = False
512+
action: str = ""
512513
for string in strings:
513514
if string.startswith("bot action: "):
514-
action = string.replace("bot action: ", "")
515-
elif action and (string.startswith(" and") or string.startswith(" or")):
515+
if action != "":
516+
action += "\n"
517+
action += string.replace("bot action: ", "")
518+
action_started = True
519+
elif (
520+
string.startswith(" and") or string.startswith(" or")
521+
) and action_started:
516522
action = action + string
523+
elif string == "":
524+
action_started = False
525+
continue
526+
elif action != "":
527+
return action
517528
return action
518529

519530

nemoguardrails/actions/v2_x/generation.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ async def create_flow(
569569
events: List[dict],
570570
name: str,
571571
body: str,
572+
decorators: Optional[str] = None,
572573
) -> dict:
573574
"""Create a new flow during runtime."""
574575

@@ -578,10 +579,14 @@ async def create_flow(
578579
flow_name = f"_dynamic_{uuid} {name}"
579580
# TODO: parse potential parameters from flow name with a regex
580581

582+
body = f"flow {flow_name}\n " + body
583+
if decorators:
584+
body = decorators + "\n" + body
585+
581586
return {
582587
"name": flow_name,
583588
"parameters": [],
584-
"body": f"flow {flow_name}\n " + body,
589+
"body": body,
585590
}
586591

587592
@action(name="GenerateValueAction", is_system_action=True, execute_async=True)

nemoguardrails/colang/v2_x/library/llm.co

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,18 @@ flow continuation on unhandled user utterance
104104
# Create and start new flow or an existing on with same name as bot intent
105105
$flow_exists = False
106106
if $bot_intent is None
107-
$bot_intent = "bot custom action"
107+
$bot_intent = "bot reacts accordingly"
108108
else
109109
$flow_exists = await CheckValidFlowExistsAction(flow_id=$bot_intent)
110110

111111
if $flow_exists == False and $bot_action is not None
112-
$flow_info = await CreateFlowAction(name=$bot_intent, body=$bot_action)
112+
$flow_info = await CreateFlowAction(name=$bot_intent, body=$bot_action, decorators='@meta(bot_intent="{$bot_intent}")\n')
113113
$flows = await AddFlowsAction(config=$flow_info.body)
114114
if len($flows) == 0
115115
print "Failed parsing created bot action flow!"
116116
return
117-
# Start
118-
await await_flow_by_name $flow_info.name
119-
await RemoveFlowsAction(flow_ids=[$flow_info.name])
117+
await await_flow_by_name $flow_info.name
118+
await RemoveFlowsAction(flow_ids=[$flow_info.name])
120119

121120

122121
flow unhandled user intent -> $intent

0 commit comments

Comments
 (0)