Skip to content
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

Setting variables in Colang scripts #91

Closed
jamescalam opened this issue Aug 8, 2023 · 2 comments
Closed

Setting variables in Colang scripts #91

jamescalam opened this issue Aug 8, 2023 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jamescalam
Copy link
Contributor

Hi, more of a Colang question (let me know if there's another place for these).

I'm trying to set a variable in a simple example script which looks like:

define user express greeting
    "hello"
    "hi"
    "how are you"

define user give name
    "James"
    "Julio"
    "Mary"
    "Putu"

define bot name greeting
    "Hey $name!"

define flow greeting
    user express greeting
    if $name
        bot name greeting
    else
        bot express greeting
        bot ask name

define flow give name
    user give name
    $name = $last_user_message
    bot name greeting

Here I'd expect $name to be set to the same value as $last_user_message, but it is set to None and returns "Hey None!"

Any idea how this should work? I saw set in the Colang Language Reference doc, but that doesn't seem to do anything. I understand I can use actions to do this, but I was hoping for a simpler way if possible, any idea on how I should set the $name variable here?

@drazvan
Copy link
Collaborator

drazvan commented Aug 8, 2023

Hi @jamescalam! Thanks for reporting this. It is indeed a bug. I've already tested a fix and will be pushed to the main branch in the next day or so.

Meanwhile, you can try an alternative method, which will work even better (although at the cost of an extra LLM call):

define flow give name
    user give name
    # Extract the user's name
    $name = ...
    bot name greeting

It uses the mechanism for extracting user provided values: https://github.com/NVIDIA/NeMo-Guardrails/blob/main/docs/user_guide/advanced/extract-user-provided-values.md.

The advantage of this approach is that if the user responds with "My name is John", in this approach the name will be extracted correctly, whereas in your initial code the name would have been the full sentence.

I'll close this once the fix is pushed.

Thanks again!

@drazvan drazvan self-assigned this Aug 8, 2023
@drazvan drazvan added the bug Something isn't working label Aug 16, 2023
@drazvan
Copy link
Collaborator

drazvan commented Sep 1, 2023

For the record, this is now fixed (1ace2a7).

@drazvan drazvan closed this as completed Sep 1, 2023
@drazvan drazvan added this to the v0.5.0 milestone Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants