NVIDIA / NeMo-Guardrails

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

Way to only generate_bot_message #667

Open AadarshBhalerao opened 1 month ago

AadarshBhalerao commented 1 month ago

Hello!

After the input rail, when the library runs the generate_user_intent, is there a way to stop further finding generate_next_step and generate_bot_message. As we have a seprate OpenAI model dedicated to give RAG based answer to the user asked query.

We need NeMo Guardrails at input and then to generate_user_intent only. Once the intend is understood we can then setup another code to take it ahead from there.

kaushikabhishek87 commented 1 month ago

Hey @AadarshBhalerao i dont think current code base directly provide a way to pass by generate_next_step , generate_bot_message or any task that is part of dialog rails. check below https://github.com/NVIDIA/NeMo-Guardrails/blob/4fbddce0a02232af33e4958618914a1d3b4bfd37/nemoguardrails/rails/llm/options.py#L35C1-L43C1 :

To invoke only some specific input/output rails:

    rails.generate(messages=messages, options={
        "rails": {
            "input": ["check jailbreak"],
            "output": ["output moderation v2"]
        }
    })

But mentioned task are part of dialog & dialog is take a boolean value https://github.com/NVIDIA/NeMo-Guardrails/blob/4fbddce0a02232af33e4958618914a1d3b4bfd37/nemoguardrails/rails/llm/options.py#L126

drazvan commented 1 week ago

For reference, pasting this here: https://docs.nvidia.com/nemo/guardrails/user_guides/advanced/generation-options.html#input-rails-only.

res = rails.generate(messages=[{
    "role": "user",
    "content": "Some user input."
}], options={
    "rails": ["input"]
})