Skip to content

Commit 63b0fa8

Browse files
committed
refactor: rename reasoning trace function
1 parent ced9b30 commit 63b0fa8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

nemoguardrails/actions/llm/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ def get_colang_history(
172172
history += f'user "{event["text"]}"\n'
173173
elif event["type"] == "UserIntent":
174174
if include_texts:
175-
history += f' {event["intent"]}\n'
175+
history += f" {event['intent']}\n"
176176
else:
177-
history += f'user {event["intent"]}\n'
177+
history += f"user {event['intent']}\n"
178178
elif event["type"] == "BotIntent":
179179
# If we have instructions, we add them before the bot message.
180180
# But we only do that for the last bot message.
181181
if "instructions" in event and idx == last_bot_intent_idx:
182182
history += f"# {event['instructions']}\n"
183-
history += f'bot {event["intent"]}\n'
183+
history += f"bot {event['intent']}\n"
184184
elif event["type"] == "StartUtteranceBotAction" and include_texts:
185185
history += f' "{event["script"]}"\n'
186186
# We skip system actions from this log
@@ -192,7 +192,7 @@ def get_colang_history(
192192
and event["action_name"] == "retrieve_relevant_chunks"
193193
):
194194
continue
195-
history += f'execute {event["action_name"]}\n'
195+
history += f"execute {event['action_name']}\n"
196196
elif event["type"] == "InternalSystemActionFinished" and not event.get(
197197
"is_system_action"
198198
):
@@ -349,9 +349,9 @@ def flow_to_colang(flow: Union[dict, Flow]) -> str:
349349
if "_type" not in element:
350350
raise Exception("bla")
351351
if element["_type"] == "UserIntent":
352-
colang_flow += f'user {element["intent_name"]}\n'
352+
colang_flow += f"user {element['intent_name']}\n"
353353
elif element["_type"] == "run_action" and element["action_name"] == "utter":
354-
colang_flow += f'bot {element["action_params"]["value"]}\n'
354+
colang_flow += f"bot {element['action_params']['value']}\n"
355355

356356
return colang_flow
357357

@@ -579,7 +579,7 @@ def escape_flow_name(name: str) -> str:
579579
return result
580580

581581

582-
def get_and_clear_reasoning_trace() -> Optional[str]:
582+
def get_and_clear_reasoning_trace_contextvar() -> Optional[str]:
583583
"""Get the current reasoning trace and clear it from the context.
584584
585585
Returns:

nemoguardrails/rails/llm/llmrails.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from nemoguardrails.actions.llm.generation import LLMGenerationActions
3434
from nemoguardrails.actions.llm.utils import (
35-
get_and_clear_reasoning_trace,
35+
get_and_clear_reasoning_trace_contextvar,
3636
get_colang_history,
3737
)
3838
from nemoguardrails.actions.output_mapping import is_output_blocked
@@ -850,7 +850,7 @@ async def generate_async(
850850
else:
851851
res = GenerationResponse(response=[new_message])
852852

853-
if reasoning_trace := get_and_clear_reasoning_trace():
853+
if reasoning_trace := get_and_clear_reasoning_trace_contextvar():
854854
res["content"] = reasoning_trace + res["content"]
855855

856856
if self.config.colang_version == "1.0":
@@ -952,7 +952,7 @@ async def generate_async(
952952
else:
953953
# If a prompt is used, we only return the content of the message.
954954

955-
if reasoning_trace := get_and_clear_reasoning_trace():
955+
if reasoning_trace := get_and_clear_reasoning_trace_contextvar():
956956
new_message["content"] = reasoning_trace + new_message["content"]
957957

958958
if prompt:

0 commit comments

Comments
 (0)