-
Notifications
You must be signed in to change notification settings - Fork 561
feat: implement parallel streaming output rails execution #1263
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,7 +66,7 @@ | |||||||||||
| from nemoguardrails.logging.verbose import set_verbose | ||||||||||||
| from nemoguardrails.patch_asyncio import check_sync_call_from_async_loop | ||||||||||||
| from nemoguardrails.rails.llm.buffer import get_buffer_strategy | ||||||||||||
| from nemoguardrails.rails.llm.config import EmbeddingSearchProvider, Model, RailsConfig | ||||||||||||
| from nemoguardrails.rails.llm.config import EmbeddingSearchProvider, RailsConfig | ||||||||||||
| from nemoguardrails.rails.llm.options import ( | ||||||||||||
| GenerationLog, | ||||||||||||
| GenerationOptions, | ||||||||||||
|
|
@@ -1351,6 +1351,32 @@ def _get_latest_user_message( | |||||||||||
| return message | ||||||||||||
| return {} | ||||||||||||
|
|
||||||||||||
| def _prepare_context_for_parallel_rails( | ||||||||||||
|
||||||||||||
| chunk_str: str, | ||||||||||||
| prompt: Optional[str] = None, | ||||||||||||
| messages: Optional[List[dict]] = None, | ||||||||||||
| ) -> dict: | ||||||||||||
| """Prepare context for parallel rails execution.""" | ||||||||||||
| context_message = _get_last_context_message(messages) | ||||||||||||
| user_message = prompt or _get_latest_user_message(messages) | ||||||||||||
|
|
||||||||||||
| context = { | ||||||||||||
| "user_message": user_message, | ||||||||||||
| "bot_message": chunk_str, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if context_message: | ||||||||||||
| context.update(context_message["content"]) | ||||||||||||
Pouyanpi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
|
Comment on lines
+1369
to
+1370
|
||||||||||||
| context.update(context_message["content"]) | |
| if isinstance(context_message.get("content"), dict): | |
| context.update(context_message["content"]) | |
| else: | |
| log.warning("context_message['content'] is not a dictionary and will be ignored.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we try and cancel a task that's already done, will that throw an exception? A task could finish in between the
pending_task.done()andpending_task.cancel()calls. We need to be able to cancel a task that's already done and no Exceptions to be thrownThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling
cancel()on a task that is already done or cancelled will not throw an exception. It simply returnsFalseand has no effect. There is no need to guardcancel()with a try/except for this reason.but this is a point good we might want to document.
it shows a race condition which is the expected behavior, but we can log a warning:
For example
based on our assumptions:
so for content modifying rails one should use sequential execution.
for read only validation rails parallel execution is fine.