nemoguardrails.llm.filters

View as Markdown

Module Contents

Functions

NameDescription
_previous_lineReturns the previous lines, skipping comments.
co_v2Creates a history of user messages and bot responses in colang format.
colangFilter that turns an array of events into a colang history.
colang_without_identifiersFilter that turns an array of events into a colang history.
conversation_to_eventsFilter that given a conversation, returns a list of events.
first_turnsReturns the first n turns from a given colang history.
indentIndents the provided text with the provided number of spaces.
last_turnsReturns the last n turns from a given colang history.
remove_text_messagesFilters that given a history in colang format, removes all texts.
remove_trailing_new_line-
to_chat_messagesFilter that turns an array of events into a sequence of user/assistant messages.
to_intent_messages-
to_intent_messages_2-
to_messagesFilter that given a history in colang format, returns all messages.
to_messages_v2Filter that given a history in colang 2.0 format, returns all messages.
user_assistant_sequenceFilter that turns an array of events into a sequence of user/assistant messages.
verbose_v1Filter that given a history in colang format, returns a verbose version of the history.

API

nemoguardrails.llm.filters._previous_line(
lines: typing.List[str],
i: int
)

Returns the previous lines, skipping comments.

nemoguardrails.llm.filters.co_v2(
events: typing.List[dict]
) -> str

Creates a history of user messages and bot responses in colang format.

user said “Hi, how are you today?” bot say “Greetings! I am the official NVIDIA Benefits Ambassador AI bot and I’m here to assist you.” user said “What can you help me with?” bot say “As an AI, I can provide you with a wide range of services, such as …”

nemoguardrails.llm.filters.colang(
events: typing.List[dict]
) -> str

Filter that turns an array of events into a colang history.

nemoguardrails.llm.filters.colang_without_identifiers(
events: typing.List[dict]
) -> str

Filter that turns an array of events into a colang history.

nemoguardrails.llm.filters.conversation_to_events(
conversation: typing.List
) -> typing.List[dict]

Filter that given a conversation, returns a list of events.

nemoguardrails.llm.filters.first_turns(
colang_history: str,
n: int
) -> str

Returns the first n turns from a given colang history.

nemoguardrails.llm.filters.indent(
text: str,
n_spaces: int
) -> str

Indents the provided text with the provided number of spaces.

nemoguardrails.llm.filters.last_turns(
colang_history: str,
n: int
) -> str

Returns the last n turns from a given colang history.

nemoguardrails.llm.filters.remove_text_messages(
colang_history: str
)

Filters that given a history in colang format, removes all texts.

nemoguardrails.llm.filters.remove_trailing_new_line(
s: str
)
nemoguardrails.llm.filters.to_chat_messages(
events: typing.List[dict]
) -> typing.List[dict]

Filter that turns an array of events into a sequence of user/assistant messages.

Properly handles multimodal content by preserving the structure when the content is in the format of a Message object with potential image_url content.

nemoguardrails.llm.filters.to_intent_messages(
colang_history: str
) -> typing.List[dict]
nemoguardrails.llm.filters.to_intent_messages_2(
colang_history: str
) -> typing.List[dict]
nemoguardrails.llm.filters.to_messages(
colang_history: str
) -> typing.List[dict]

Filter that given a history in colang format, returns all messages.

nemoguardrails.llm.filters.to_messages_v2(
colang_history: str
) -> typing.List[dict]

Filter that given a history in colang 2.0 format, returns all messages.

nemoguardrails.llm.filters.user_assistant_sequence(
events: typing.List[dict]
) -> str

Filter that turns an array of events into a sequence of user/assistant messages.

For multimodal content, it extracts text content and indicates if there were images.

nemoguardrails.llm.filters.verbose_v1(
colang_history: str
) -> str

Filter that given a history in colang format, returns a verbose version of the history.