CLI#

注意:本节正在进行中。

Guardrails CLI#

出于测试目的,Guardrails 工具包提供了一个命令行聊天工具,可以用来与 LLM 进行交互。

nemoguardrails chat --config examples/ [--verbose] [--verbose-llm-calls]

选项#

  • --config: 应该使用的配置。 可以是文件夹或 .co/.yml 文件。

  • --verbose: 在 verbose 模式下,还会显示详细的调试信息。

  • --verbose-llm-calls: 在 verbose LLM calls 模式下,调试信息包括发送给 LLM 的整个提示词和完成情况。

现在您应该能够调用 nemoguardrails CLI 了。

> nemoguardrails --help

Usage: nemoguardrails [OPTIONS] COMMAND [ARGS]...

Options:
 --install-completion [bash|zsh|fish|powershell|pwsh]
                                 Install completion for the specified shell.
 --show-completion [bash|zsh|fish|powershell|pwsh]
                                 Show completion for the specified shell, to
                                 copy it or customize the installation.
 --help                          Show this message and exit.

Commands:
 actions-server  Starts a NeMo Guardrails actions server.
 chat            Starts an interactive chat session.
 convert         Convert a Colang 1.0 directory to Colang 2.0 format.
 evaluate        Run an evaluation task.
 server          Starts a NeMo Guardrails server.

您还可以使用 --help 标志来了解更多关于每个 nemoguardrails 命令的信息

actions-server#

> nemoguardrails actions-server --help

Usage: nemoguardrails actions-server [OPTIONS]

 Starts a NeMo Guardrails actions server.

Options:
 --port INTEGER  The port that the server should listen on.   [default: 8001]
 --help          Show this message and exit.

chat#

> nemoguardrails chat --help

Usage: nemoguardrails chat [OPTIONS]

 Starts an interactive chat session.

 --config                                       TEXT  Path to a directory containing configuration
                                                      files to use. Can also point to a single
                                                      configuration file.
                                                      [default: config]
 --verbose             --no-verbose                   If the chat should be verbose and output
                                                      detailed logging information.
                                                      [default: no-verbose]
 --verbose-no-llm      --no-verbose-no-llm            If the chat should be verbose and exclude the
                                                      prompts and responses for the LLM calls.
                                                      [default: no-verbose-no-llm]
 --verbose-simplify    --no-verbose-simplify          Simplify further the verbose output.
                                                      [default: no-verbose-simplify]
 --debug-level                                  TEXT  Enable debug mode which prints rich
                                                      information about the flows execution.
                                                      Available levels: WARNING, INFO, DEBUG
 --streaming           --no-streaming                 If the chat should use the streaming mode, if
                                                      possible.
                                                      [default: no-streaming]
 --server-url                                   TEXT  If specified, the chat CLI will interact with
                                                      a server, rather than load the config. In this
                                                      case, the --config-id must also be specified.
                                                      [default: None]
 --config-id                                    TEXT  The config_id to be used when interacting with
                                                      the server.
                                                      [default: None]
 --help                                               Show this message and exit.

server#

> nemoguardrails server --help

Usage: nemoguardrails server [OPTIONS]

Starts a NeMo Guardrails server.

Options:
--port                                        INTEGER  The port that the server should listen on. [default: 8000]
--config                                      TEXT     Path to a directory containing multiple configuration sub-folders.
--verbose           --no-verbose:                      If the server should be verbose and output detailed logs including prompts. [default: no-verbose]
--disable-chat-ui   --no-disable-chat-ui               Weather the ChatUI should be disabled [default: no-disable-chat-ui]
--auto-reload       --no-auto-reload                   Enable auto reload option. [default: no-auto-reload]
--prefix                                      TEXT     A prefix that should be added to all server paths. Should start with '/'.
--help                                                Show this message and exit.

evaluate#

> nemoguardrails evaluate --help

Usage: nemoguardrails evaluate [OPTIONS] COMMAND [ARGS]...

Options:
--help:          Show this message and exit.

Commands:
fact-checking:   Evaluate the performance of the fact-checking rails defined in a Guardrails application.
hallucination:   Evaluate the performance of the hallucination rails defined in a Guardrails application.
moderation:      Evaluate the performance of the moderation rails defined in a Guardrails application.
topical:         Evaluates the performance of the topical rails defined in a Guardrails application. Computes accuracy for canonical form detection, next step generation, and next bot message generation. Only a single Guardrails application can be specified in the config option.

convert#

> nemoguardrails convert --help

Usage: nemoguardrails convert [OPTIONS] PATH

Convert a Colang 1.0 directory to Colang 2.0.

Arguments:
  path TEXT The path to the file or directory to migrate. [default: None] [required]

Options:
--verbose                       --no-verbose                If the migration should be verbose and output detailed logs. [default: no-verbose]
--validate                      --no-validate               If the migration should validate the output using Colang Parser. [default: no-validate]
--use-active-decorator          --no-use-active-decorator   If the migration should use the active decorator. [default: use-active-decorator]
--help                                                      Show this message and exit.

providers#

> nemoguardrails find-providers --help

Usage: nemoguardrails find-providers [OPTIONS]

Interactive provider selection.

This command provides an interactive interface to select between text completion
and chat completion providers. It will guide you through selecting the type of
provider (text completion or chat completion) and then show you the available
providers for that type.

Options:
  --list, -l    Just list all available providers without interactive selection
  --help        Show this message and exit.

查找提供程序命令#

providers 命令提供了一个交互式界面,用于探索和选择 NeMo Guardrails 中可用的 LLM 提供程序。 它支持文本完成和聊天完成提供程序。

nemoguardrails find-providers [--list]

选项#

  • --list, -l: 仅列出所有可用的提供程序,而不进行交互式选择

交互模式#

在不使用 --list 选项运行时,该命令提供一个交互式界面

  1. 首先,系统会提示您选择一个提供程序类型

    • 键入以在“文本完成”和“聊天完成”之间进行过滤,您可以按 Tab 键自动完成。

    • 使用箭头键在匹配项之间导航

    • 按 Tab 键自动完成

    • 按 Enter 键选择

  2. 然后,系统会提示您选择一个特定的提供程序

    • 键入以过滤可用的提供程序

    • 使用箭头键在匹配项之间导航

    • 按 Tab 键自动完成

    • 按 Enter 键选择

用法示例#

# List all available providers
nemoguardrails find-providers --list

# Interactive provider selection
nemoguardrails find-providers

示例输出#

Available Provider Types: (type to filter, use arrows to select)
  • text completion
  • chat completion

Select provider type: text

Available text completion providers: (type to filter, use arrows to select)
  • anthropic
  • google_palm
  • openai
  • ...

Select provider: openai

Selected text completion provider: openai