feat(actions): enable streaming in custom actions #735
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚨 Updates in the discussions below
Fixes #646
Problem description
First of all, thanks for NeMo-Guardrails!
Given two consecutive actions. The first one is a custom RAG, and the second one analyzes the answer to render a disclaimer in case the answer is not grounded in the knowledge base. It is like fact-checking, but with streaming enabled. The bot should answer and finish like: "I learn something new every day, so my answers may not always be perfect."
Using streaming currently leads to two errors:
streaming_finished_event
is set, which in turn is caused by an empty chunk (""
) that is passed toon_llm_new_token
. The existing if statement checks for empty chunks, but only when they occur at the beginning. In our case, it happens at the end. I extended the check so that""
is never being processed._process
function by adding an early return in casechunk == self.completion
How to test
I've added an example under
examples/configs/rag/custom_rag_streaming
which you can test like so:Please also follow the
README.md
I've included.I'm happy to hear your feedback!
@drazvan @mikeolubode