NVIDIA / NeMo-Guardrails

NeMo Guardrails is an open-source toolkit for easily adding programmable guardrails to LLM-based conversational systems.
Other
4.16k stars 390 forks source link

How to generate custom events #44

Closed kmj-8 closed 2 months ago

kmj-8 commented 1 year ago

Hi team, Is there any way to write or generate custom event?

drazvan commented 1 year ago

Not yet, but it's a feature that is already on our short list as it's been requested multiple times. Right now you can do a hack and make a convention to define special canonical forms that represent events e.g.

define user event X
  "event X"

So, essentially when you want to trigger the event, you just send the text "event X".

kmj-8 commented 1 year ago

okay, thanks @drazvan

Serbernari commented 7 months ago

any update on that?

drazvan commented 7 months ago

Thanks for the follow up @Serbernari! Yes, it is now possible. It appears this feature is not documented. There's a brief mention in the docstring for the generate_async function: https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/nemoguardrails/rails/llm/llmrails.py#L491.

[
  {"role": "context", "content": {"user_name": "John"}},
  {"role": "user", "content": "Hello! How are you?"},
  {"role": "assistant", "content": "I am fine, thank you!"},
  {"role": "event", "event": {"type": "UserSilent"}},
  ...
]

So, you have to use "role": "event". The type is important as this will be used for matching. For example, in the above example, a flow would match the UserSilent event with:

define flow 
  event UserSilent
  bot ask question again

Let me know if you need more information at this point. We'll update the docs in the coming weeks.