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

[LG] Inject LG templates as a global expression function #3802

Merged
merged 14 commits into from
Apr 29, 2020

Conversation

cosmicshuai
Copy link
Contributor

@cosmicshuai cosmicshuai commented Apr 24, 2020

close: #3652
In this PR, users can register namespace for a lg file. Also, they can register some templates as a expression functions, which can be applied easily in dialog.
Here is an example to use these options,

!# @namespace = foo
!# @exports = template1, template2

After registration, in a dialog file, such usage "property": "=foo.template1()" is enabled, foo.template1() just behaves like a customized function.

The limitation is this kind of 'LG template function' can not read any scope from dialogStateManager, which is the same as prebuilt functions.

For example,
we have a memory in dialogStateManager:
user.tasks: [ "car", "washing", "food", "laundry" ]
if you to join the list of user.tasks, you have to define the LG file as

> !# @namespace = foo
> !# @Export s= joinList

#joinList(tasks)
- ${join(tasks, " ,")} 

Then call the function as

=foo.joinList(user.tasks)

tomlm
tomlm previously requested changes Apr 24, 2020
Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@tomlm tomlm dismissed their stale review April 24, 2020 14:42

revoking review

@tomlm tomlm added the Draft PR label Apr 24, 2020
@xieofxie
Copy link
Contributor

Will this apply for the dialogs under dialog having this lg or all dialogs? Thanks

@cosmicshuai
Copy link
Contributor Author

@xieofxie, all dialogs

@xieofxie
Copy link
Contributor

xieofxie commented Apr 26, 2020

@xieofxie, all dialogs

So we will load all lgs when bot is starting? And if it is for all lgs, it means we could use another lg's function without import it?

@cosmicshuai
Copy link
Contributor Author

@xieofxie, all dialogs

So we will load all lgs when bot is starting?

Yes, all LGs are loaded when bot starting. All exported templates can be used as a prebuilt functions under all dialogs.

@cosmicshuai cosmicshuai marked this pull request as ready for review April 27, 2020 09:33
Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@boydc2014
Copy link
Contributor

@cosmicshuai let's make sure our options are not case-sensitive before we take this in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use lg instead of expression in value, condition etc.
5 participants