|
48 | 48 | get_element_from_head,
|
49 | 49 | get_event_from_element,
|
50 | 50 | )
|
| 51 | +from nemoguardrails.context import llm_call_info_var |
51 | 52 | from nemoguardrails.embeddings.index import EmbeddingsIndex, IndexItem
|
52 | 53 | from nemoguardrails.llm.filters import colang
|
53 | 54 | from nemoguardrails.llm.params import llm_params
|
54 | 55 | from nemoguardrails.llm.types import Task
|
55 | 56 | from nemoguardrails.logging import verbose
|
| 57 | +from nemoguardrails.logging.explain import LLMCallInfo |
56 | 58 | from nemoguardrails.utils import console, new_uuid
|
57 | 59 |
|
58 | 60 | log = logging.getLogger(__name__)
|
@@ -265,6 +267,10 @@ async def generate_user_intent(
|
265 | 267 | if is_embedding_only:
|
266 | 268 | return f"{potential_user_intents[0]}"
|
267 | 269 |
|
| 270 | + llm_call_info_var.set( |
| 271 | + LLMCallInfo(task=Task.GENERATE_USER_INTENT_FROM_USER_ACTION.value) |
| 272 | + ) |
| 273 | + |
268 | 274 | prompt = self.llm_task_manager.render_task_prompt(
|
269 | 275 | task=Task.GENERATE_USER_INTENT_FROM_USER_ACTION,
|
270 | 276 | events=events,
|
@@ -335,6 +341,12 @@ async def generate_user_intent_and_bot_action(
|
335 | 341 | state, user_action, max_example_flows
|
336 | 342 | )
|
337 | 343 |
|
| 344 | + llm_call_info_var.set( |
| 345 | + LLMCallInfo( |
| 346 | + task=Task.GENERATE_USER_INTENT_AND_BOT_ACTION_FROM_USER_ACTION.value |
| 347 | + ) |
| 348 | + ) |
| 349 | + |
338 | 350 | prompt = self.llm_task_manager.render_task_prompt(
|
339 | 351 | task=Task.GENERATE_USER_INTENT_AND_BOT_ACTION_FROM_USER_ACTION,
|
340 | 352 | events=events,
|
@@ -448,6 +460,10 @@ async def generate_flow_from_instructions(
|
448 | 460 | flow_id = new_uuid()[0:4]
|
449 | 461 | flow_name = f"dynamic_{flow_id}"
|
450 | 462 |
|
| 463 | + llm_call_info_var.set( |
| 464 | + LLMCallInfo(task=Task.GENERATE_FLOW_FROM_INSTRUCTIONS.value) |
| 465 | + ) |
| 466 | + |
451 | 467 | prompt = self.llm_task_manager.render_task_prompt(
|
452 | 468 | task=Task.GENERATE_FLOW_FROM_INSTRUCTIONS,
|
453 | 469 | events=events,
|
@@ -511,6 +527,8 @@ async def generate_flow_from_name(
|
511 | 527 | for result in reversed(results):
|
512 | 528 | examples += f"{result.meta['flow']}\n"
|
513 | 529 |
|
| 530 | + llm_call_info_var.set(LLMCallInfo(task=Task.GENERATE_FLOW_FROM_NAME.value)) |
| 531 | + |
514 | 532 | prompt = self.llm_task_manager.render_task_prompt(
|
515 | 533 | task=Task.GENERATE_FLOW_FROM_NAME,
|
516 | 534 | events=events,
|
@@ -572,6 +590,8 @@ async def generate_flow_continuation(
|
572 | 590 |
|
573 | 591 | # TODO: add examples from the actual running flows
|
574 | 592 |
|
| 593 | + llm_call_info_var.set(LLMCallInfo(task=Task.GENERATE_FLOW_CONTINUATION.value)) |
| 594 | + |
575 | 595 | prompt = self.llm_task_manager.render_task_prompt(
|
576 | 596 | task=Task.GENERATE_FLOW_CONTINUATION,
|
577 | 597 | events=events,
|
@@ -687,6 +707,10 @@ async def generate_value(
|
687 | 707 | if "GenerateValueAction" not in result.text:
|
688 | 708 | examples += f"{result.text}\n\n"
|
689 | 709 |
|
| 710 | + llm_call_info_var.set( |
| 711 | + LLMCallInfo(task=Task.GENERATE_VALUE_FROM_INSTRUCTION.value) |
| 712 | + ) |
| 713 | + |
690 | 714 | prompt = self.llm_task_manager.render_task_prompt(
|
691 | 715 | task=Task.GENERATE_VALUE_FROM_INSTRUCTION,
|
692 | 716 | events=events,
|
@@ -793,6 +817,10 @@ async def generate_flow(
|
793 | 817 | textwrap.dedent(docstring), context=render_context, events=events
|
794 | 818 | )
|
795 | 819 |
|
| 820 | + llm_call_info_var.set( |
| 821 | + LLMCallInfo(task=Task.GENERATE_FLOW_CONTINUATION_FROM_NLD.value) |
| 822 | + ) |
| 823 | + |
796 | 824 | prompt = self.llm_task_manager.render_task_prompt(
|
797 | 825 | task=Task.GENERATE_FLOW_CONTINUATION_FROM_NLD,
|
798 | 826 | events=events,
|
|
0 commit comments