diff --git a/nemoguardrails/actions/llm/utils.py b/nemoguardrails/actions/llm/utils.py index 5b1ef3d2ce..73e46df7ae 100644 --- a/nemoguardrails/actions/llm/utils.py +++ b/nemoguardrails/actions/llm/utils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import logging import re from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, Union, cast @@ -134,6 +135,10 @@ async def _stream_llm_call( llm_response_metadata_var.set(accumulated_provider_metadata or None) + if tool_calls: + payload = json.dumps({"tool_calls": [tc.to_dict() for tc in tool_calls]}) + await handler.push_chunk(payload) + await handler.finish() llm_call_info = llm_call_info_var.get() @@ -532,10 +537,10 @@ def get_colang_history( history += f"# The result was {return_value}\n" elif event["type"] == "mask_prev_user_message": utterance_to_replace = get_last_user_utterance(events[:idx]) - # We replace the last user utterance that led to jailbreak rail trigger with a placeholder text - split_history = history.rsplit(utterance_to_replace, 1) - placeholder_text = "<<