|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +import logging |
| 17 | + |
| 18 | +from rich.logging import RichHandler |
| 19 | + |
| 20 | +from nemoguardrails import RailsConfig |
| 21 | +from tests.utils import TestChat |
| 22 | + |
| 23 | +FORMAT = "%(message)s" |
| 24 | +logging.basicConfig( |
| 25 | + level=logging.DEBUG, |
| 26 | + format=FORMAT, |
| 27 | + datefmt="[%X,%f]", |
| 28 | + handlers=[RichHandler(markup=True)], |
| 29 | +) |
| 30 | + |
| 31 | + |
| 32 | +def test_1(): |
| 33 | + """Test use of expression as statements.""" |
| 34 | + config = RailsConfig.from_content( |
| 35 | + colang_content=""" |
| 36 | + flow main |
| 37 | + match UtteranceUserActionFinished() |
| 38 | + $v1 = ..."Generate the company' name\\" from users input" |
| 39 | + $v2 = ...'Generate the company\\' name" from users input' |
| 40 | + $v3 = ...'''Generate the company' name" from users input''' |
| 41 | + $v4 = ...'''Generate the company' |
| 42 | + name" from users input''' |
| 43 | +
|
| 44 | + await UtteranceBotAction(script="{$v1}{$v2}{$v3}{$v4}") |
| 45 | + """, |
| 46 | + yaml_content=""" |
| 47 | + colang_version: "2.x" |
| 48 | + models: |
| 49 | + - type: main |
| 50 | + engine: openai |
| 51 | + model: gpt-3.5-turbo-instruct |
| 52 | + """, |
| 53 | + ) |
| 54 | + |
| 55 | + chat = TestChat( |
| 56 | + config, |
| 57 | + llm_completions=["'1'", "'2'", "'3'", "'4'"], |
| 58 | + ) |
| 59 | + |
| 60 | + chat >> "hi" |
| 61 | + chat << "1234" |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + test_1() |
0 commit comments