Skip to content

Bot action parsing fixes #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion nemoguardrails/actions/llm/utils.py
Original file line number Diff line number Diff line change
@@ -534,6 +534,23 @@ def get_first_user_intent(strings: List[str]) -> Optional[str]:
return None


def quote_bot_say(line: str) -> str:
if line.startswith("bot say "):
message = line[len("bot say "):]
return f"{line}\nbot say \"{message}\""
return line


def correct_bot_action(line: str) -> str:
match = re.search(r'"(.*)"', line, re.DOTALL)
if match:
message = match.group(1).strip()
return f'bot say "{message}"'
else:
# fallback: no quoted part, return as-is or handle differently
return f'bot say "{line.strip()}"'


def get_first_bot_intent(strings: List[str]) -> Optional[str]:
"""Returns first bot intent."""
for string in strings:
@@ -545,8 +562,11 @@ def get_first_bot_intent(strings: List[str]) -> Optional[str]:
def get_first_bot_action(strings: List[str]) -> Optional[str]:
"""Returns first bot action."""
action_started = False
fallback_action: str = ""
action: str = ""

for string in strings:
fallback_action = string
if string.startswith("bot action: "):
if action != "":
action += "\n"
@@ -561,7 +581,12 @@ def get_first_bot_action(strings: List[str]) -> Optional[str]:
continue
elif action != "":
return action
return action

result = action if action != "" else fallback_action

result = correct_bot_action(result)

return result


def escape_flow_name(name: str) -> str: