nemoguardrails.actions.v2_x.generation

View as Markdown

A set of actions for generating various types of completions using an LLMs.

Module Contents

Classes

NameDescription
LLMGenerationActionsV2dotxAdapted version of LLMGenerationActions for Colang 2.x.

Functions

NameDescription
_remove_leading_empty_linesRemove the leading empty lines if they exist.

Data

log

API

class nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx()

Bases: LLMGenerationActions

Adapted version of LLMGenerationActions for Colang 2.x.

It overrides some methods.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._collect_user_intent_and_examples(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
user_action: str,
max_example_flows: int
) -> typing.Tuple[typing.List[str], str, bool]
async
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._ensure_flows_index()
async
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._ensure_instruction_flows_index()
async
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._init_colang_flows_index(
flows: typing.List[str]
) -> typing.Optional[nemoguardrails.embeddings.index.EmbeddingsIndex]
async

Initialize an index with colang flows.

The flows are expected to have full definition.

Args flows: The list of flows, i.e. the flow definition from the source code.

Returns An initialized index.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx._init_flows_index() -> None
async

Initializes the index of flows.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_for_active_flow_finished_match(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
event_name: str,
arguments: typing.Any = {}
) -> bool
async

Return True if there is a flow waiting for the provided event name and parameters.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_if_flow_defined(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
flow_id: str
) -> bool
async

Return True if a flow with the provided flow_id is defined.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.check_if_flow_exists(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
flow_id: str
) -> bool
async

Return True if a flow with the provided flow_id exists.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.create_flow(
events: typing.List[dict],
name: str,
body: str,
decorators: typing.Optional[str] = None
) -> dict
async

Create a new flow during runtime.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
events: typing.List[dict],
llm: typing.Optional[nemoguardrails.types.LLMModel] = None,
flow_id: typing.Optional[str] = None
) -> dict
async

Generate the body for a flow.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_continuation(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
events: typing.List[dict],
temperature: typing.Optional[float] = None,
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
async

Generate a continuation for the flow representing the current conversation.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_from_instructions(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
instructions: str,
events: typing.List[dict],
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
async

Generate a flow from the provided instructions.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_flow_from_name(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
name: str,
events: typing.List[dict],
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
async

Generate a flow from the provided NAME.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_user_intent(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
events: typing.List[dict],
user_action: str,
max_example_flows: int = 5,
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
async

Generate the canonical form for what the user said i.e. user intent.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_user_intent_and_bot_action(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
events: typing.List[dict],
user_action: str,
max_example_flows: int = 5,
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> dict
async

Generate the canonical form for what the user said i.e. user intent and a suitable bot action.

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.generate_value(
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
instructions: str,
events: typing.List[dict],
var_name: typing.Optional[str] = None,
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> typing.Any
async

Generate a value in the context of the conversation.

:param instructions: The instructions to generate the value. :param events: The full stream of events so far. :param var_name: The name of the variable to generate. :param llm: Custom llm model to generate_value

nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.get_last_user_message(
events: typing.List[dict],
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
) -> str
async
nemoguardrails.actions.v2_x.generation.LLMGenerationActionsV2dotx.passthrough_llm_action(
user_message: str,
state: nemoguardrails.colang.v2_x.runtime.statemachine.State,
events: typing.List[dict],
llm: typing.Optional[nemoguardrails.types.LLMModel] = None
)
async
nemoguardrails.actions.v2_x.generation._remove_leading_empty_lines(
s: str
) -> str

Remove the leading empty lines if they exist.

A line is considered empty if it has only white spaces.

nemoguardrails.actions.v2_x.generation.log = logging.getLogger(__name__)