Skip to content

Commit

Permalink
Merge pull request #454 from NVIDIA/fix/issue-385
Browse files Browse the repository at this point in the history
Redo the fix for #385.
  • Loading branch information
drazvan authored Apr 15, 2024
2 parents d420e02 + 358425e commit f2456d3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nemoguardrails/rails/llm/llmrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ def _get_events_for_messages(self, messages: List[dict], state: Any):
action_uid = new_uuid()
start_event = new_event_dict(
"StartUtteranceBotAction",
final_transcript=msg["content"],
script=msg["content"],
action_uid=action_uid,
)
finished_event = new_event_dict(
"UtteranceBotActionFinished",
final_transcript=msg["content"],
final_script=msg["content"],
is_success=True,
action_uid=action_uid,
)
Expand Down
49 changes: 49 additions & 0 deletions tests/test_issue_385.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from nemoguardrails import LLMRails, RailsConfig


@pytest.mark.asyncio
async def test_1():
config = RailsConfig.from_content(
colang_content="""
define user express greeting
"hello"
define flow
user express greeting
bot express greeting
define bot express greeting
"Hello World!"
""",
config={
"models": [],
"rails": {"dialog": {"user_messages": {"embeddings_only": True}}},
},
)
rails = LLMRails(config)

# This should not raise an exception
await rails.generate_async(
messages=[
{"role": "user", "content": "hi!"},
{"role": "assistant", "content": "hi!"},
{"role": "user", "content": "hi!"},
]
)

0 comments on commit f2456d3

Please sign in to comment.