Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ __test-cli-port-override = []
__skip-implicit-config = ["nemo-relay/__skip-implicit-config"]

[dependencies]
nemo-relay = { workspace = true, features = ["guardrails-remote", "object-store", "worker-grpc"] }
nemo-relay = { workspace = true, features = ["object-store", "worker-grpc"] }
nemo-relay-adaptive = { workspace = true, features = ["redis-backend"] }
nemo-relay-pii-redaction.workspace = true
async-stream = "0.3"
Expand Down
118 changes: 0 additions & 118 deletions crates/cli/src/plugins/editor_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ use serde_json::{Map, Value, json};

use crate::error::CliError;

#[allow(
deprecated,
reason = "the CLI must edit existing Guardrails configuration until the built-in plugin is removed"
)]
mod guardrails_compat {
pub(super) type Config = nemo_relay::plugins::nemo_guardrails::component::NeMoGuardrailsConfig;
pub(super) const PLUGIN_KIND: &str =
nemo_relay::plugins::nemo_guardrails::component::NEMO_GUARDRAILS_PLUGIN_KIND;
}

use guardrails_compat::{
Config as NeMoGuardrailsConfig, PLUGIN_KIND as NEMO_GUARDRAILS_PLUGIN_KIND,
};

pub(super) const POLICY_SECTION: &str = "policy";

#[derive(Debug, Clone)]
Expand All @@ -47,7 +33,6 @@ pub(super) struct ComponentEditorState<T> {
pub(super) enum EditableComponent {
Observability(Box<ComponentEditorState<ObservabilityConfig>>),
Adaptive(Box<ComponentEditorState<AdaptiveConfig>>),
NemoGuardrails(Box<ComponentEditorState<NeMoGuardrailsConfig>>),
PiiRedaction(Box<ComponentEditorState<PiiRedactionConfig>>),
}

Expand All @@ -56,7 +41,6 @@ impl EditableComponent {
match self {
Self::Observability(_) => "Observability",
Self::Adaptive(_) => "Adaptive",
Self::NemoGuardrails(_) => "NeMo Guardrails (Deprecated)",
Self::PiiRedaction(_) => "PII Redaction",
}
}
Expand All @@ -65,7 +49,6 @@ impl EditableComponent {
match self {
Self::Observability(_) => ObservabilityConfig::editor_schema().fields,
Self::Adaptive(_) => AdaptiveConfig::editor_schema().fields,
Self::NemoGuardrails(_) => NeMoGuardrailsConfig::editor_schema().fields,
Self::PiiRedaction(_) => PiiRedactionConfig::editor_schema().fields,
}
}
Expand All @@ -74,7 +57,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => state.enabled,
Self::Adaptive(state) => state.enabled,
Self::NemoGuardrails(state) => state.enabled,
Self::PiiRedaction(state) => state.enabled,
}
}
Expand All @@ -83,7 +65,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => state.toggle_enabled(),
Self::Adaptive(state) => state.toggle_enabled(),
Self::NemoGuardrails(state) => state.toggle_enabled(),
Self::PiiRedaction(state) => state.toggle_enabled(),
}
}
Expand All @@ -92,7 +73,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => state.set_enabled(enabled),
Self::Adaptive(state) => state.set_enabled(enabled),
Self::NemoGuardrails(state) => state.set_enabled(enabled),
Self::PiiRedaction(state) => state.set_enabled(enabled),
}
}
Expand All @@ -101,7 +81,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => state.reset_enabled(),
Self::Adaptive(state) => state.reset_enabled(),
Self::NemoGuardrails(state) => state.reset_enabled(),
Self::PiiRedaction(state) => state.reset_enabled(),
}
}
Expand All @@ -110,7 +89,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => observability_summary(state),
Self::Adaptive(state) => adaptive_summary(state),
Self::NemoGuardrails(state) => nemo_guardrails_summary(state),
Self::PiiRedaction(state) => pii_redaction_summary(state),
}
}
Expand All @@ -119,9 +97,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => section_configured(&state.config, field),
Self::Adaptive(state) => config_field_configured(&state.config, field).unwrap_or(false),
Self::NemoGuardrails(state) => {
config_field_configured(&state.config, field).unwrap_or(false)
}
Self::PiiRedaction(state) => {
config_field_configured(&state.config, field).unwrap_or(false)
}
Expand All @@ -138,10 +113,6 @@ impl EditableComponent {
reset_config_field(&mut state.config, field)?;
state.mark_config_touched();
}
Self::NemoGuardrails(state) => {
reset_config_field(&mut state.config, field)?;
state.mark_config_touched();
}
Self::PiiRedaction(state) => {
reset_config_field(&mut state.config, field)?;
state.mark_config_touched();
Expand All @@ -163,10 +134,6 @@ impl EditableComponent {
remove_struct_field(&mut state.config, field.name)?;
state.mark_config_touched();
}
Self::NemoGuardrails(state) => {
remove_struct_field(&mut state.config, field.name)?;
state.mark_config_touched();
}
Self::PiiRedaction(state) => {
remove_struct_field(&mut state.config, field.name)?;
state.mark_config_touched();
Expand All @@ -179,7 +146,6 @@ impl EditableComponent {
match self {
Self::Observability(state) => store_observability_state(config, state),
Self::Adaptive(state) => store_adaptive_state(config, state),
Self::NemoGuardrails(state) => store_nemo_guardrails_state(config, state),
Self::PiiRedaction(state) => store_pii_redaction_state(config, state),
}
}
Expand Down Expand Up @@ -207,7 +173,6 @@ pub(super) fn editable_components(
let components = vec![
EditableComponent::Observability(Box::new(component_observability_state(config)?)),
EditableComponent::Adaptive(Box::new(component_adaptive_state(config)?)),
EditableComponent::NemoGuardrails(Box::new(component_nemo_guardrails_state(config)?)),
EditableComponent::PiiRedaction(Box::new(component_pii_redaction_state(config)?)),
];
Ok(components)
Expand Down Expand Up @@ -403,12 +368,6 @@ pub(super) fn component_adaptive_state(
component_editor_state(config, ADAPTIVE_PLUGIN_KIND, false)
}

pub(super) fn component_nemo_guardrails_state(
config: &PluginConfig,
) -> Result<ComponentEditorState<NeMoGuardrailsConfig>, CliError> {
component_editor_state(config, NEMO_GUARDRAILS_PLUGIN_KIND, false)
}

pub(super) fn component_pii_redaction_state(
config: &PluginConfig,
) -> Result<ComponentEditorState<PiiRedactionConfig>, CliError> {
Expand Down Expand Up @@ -447,22 +406,6 @@ pub(super) fn store_adaptive_state(
Ok(())
}

pub(super) fn store_nemo_guardrails_state(
config: &mut PluginConfig,
state: &ComponentEditorState<NeMoGuardrailsConfig>,
) -> Result<(), CliError> {
if state.should_store(state.config_touched || nemo_guardrails_configured(&state.config)) {
store_component_editor_config(
config,
NEMO_GUARDRAILS_PLUGIN_KIND,
state.enabled,
nemo_guardrails_config_map(&state.config)?,
merge_nemo_guardrails_editor_config,
);
}
Ok(())
}

pub(super) fn store_pii_redaction_state(
config: &mut PluginConfig,
state: &ComponentEditorState<PiiRedactionConfig>,
Expand Down Expand Up @@ -793,23 +736,6 @@ pub(super) fn adaptive_config_map(config: &AdaptiveConfig) -> Result<Map<String,
}
}

pub(super) fn nemo_guardrails_config_map(
config: &NeMoGuardrailsConfig,
) -> Result<Map<String, Value>, CliError> {
let value = serde_json::to_value(config).map_err(serde_error)?;
match value {
Value::Object(mut map) => {
if is_version_one(map.get("version")) {
map.remove("version");
}
Ok(map)
}
_ => Err(CliError::Config(
"nemo_guardrails config must serialize to an object".into(),
)),
}
}

pub(super) fn pii_redaction_config_map(
config: &PiiRedactionConfig,
) -> Result<Map<String, Value>, CliError> {
Expand Down Expand Up @@ -854,21 +780,6 @@ pub(super) fn merge_adaptive_editor_config(
);
}

pub(super) fn merge_nemo_guardrails_editor_config(
existing: &mut Map<String, Value>,
edited: Map<String, Value>,
) {
if is_version_one(existing.get("version")) {
existing.remove("version");
}
merge_known_editor_object(
existing,
edited,
&nested_editor_keys(NeMoGuardrailsConfig::editor_schema()),
NeMoGuardrailsConfig::editor_schema(),
);
}

pub(super) fn merge_pii_redaction_editor_config(
existing: &mut Map<String, Value>,
edited: Map<String, Value>,
Expand Down Expand Up @@ -1084,35 +995,6 @@ pub(super) fn adaptive_summary(state: &ComponentEditorState<AdaptiveConfig>) ->
)
}

pub(super) fn nemo_guardrails_configured(config: &NeMoGuardrailsConfig) -> bool {
NeMoGuardrailsConfig::editor_schema()
.fields
.iter()
.filter(|field| field.name != POLICY_SECTION)
.any(|field| config_field_configured(config, *field).unwrap_or(false))
}

pub(super) fn nemo_guardrails_summary(
state: &ComponentEditorState<NeMoGuardrailsConfig>,
) -> String {
let configured_fields = NeMoGuardrailsConfig::editor_schema()
.fields
.iter()
.filter(|field| field.name != POLICY_SECTION)
.filter(|field| config_field_configured(&state.config, **field).unwrap_or(false))
.map(|field| field.label)
.collect::<Vec<_>>();
format!(
"component {}, fields {}",
if state.enabled { "enabled" } else { "disabled" },
if configured_fields.is_empty() {
"none".into()
} else {
configured_fields.join(", ")
}
)
}

pub(super) fn pii_redaction_configured(config: &PiiRedactionConfig) -> bool {
PiiRedactionConfig::editor_schema()
.fields
Expand Down
4 changes: 0 additions & 4 deletions crates/cli/src/plugins/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ fn edit_component_field(
edit_config_field(theme, &mut state.config, field)?;
state.mark_config_touched();
}
EditableComponent::NemoGuardrails(state) => {
edit_config_field(theme, &mut state.config, field)?;
state.mark_config_touched();
}
EditableComponent::PiiRedaction(state) => {
edit_config_field(theme, &mut state.config, field)?;
state.mark_config_touched();
Expand Down
12 changes: 12 additions & 0 deletions crates/cli/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ pub(crate) struct ServerPluginActivation {
}

const REMOVED_SWITCHYARD_MESSAGE: &str = "the built-in Switchyard service integration was removed in NeMo Relay >=0.8.0; remove this `[[components]]` entry and refer to the NeMo Relay migration guides for current Switchyard migration information: https://docs.nvidia.com/nemo/relay/reference/migration-guides";
const REMOVED_NEMO_GUARDRAILS_MESSAGE: &str = "the built-in NeMo Guardrails integration was removed in NeMo Relay >=0.10.0; remove this `[[components]]` entry and refer to the migration guide: https://docs.nvidia.com/nemo/relay/reference/migration-guides#remove-the-built-in-nemo-guardrails-component";

impl ServerPluginActivation {
pub(crate) fn clear(mut self) -> Result<(), CliError> {
Expand All @@ -1012,6 +1013,7 @@ impl ServerPluginActivation {
pub(crate) enum PluginComponentSetupError {
Adaptive(String),
PiiRedaction(String),
RemovedNemoGuardrails,
RemovedSwitchyard,
}

Expand All @@ -1020,6 +1022,7 @@ impl PluginComponentSetupError {
match self {
Self::Adaptive(_) => "Adaptive plugin",
Self::PiiRedaction(_) => "PII redaction plugin",
Self::RemovedNemoGuardrails => "NeMo Guardrails migration",
Self::RemovedSwitchyard => "Switchyard migration",
}
}
Expand All @@ -1029,6 +1032,7 @@ impl PluginComponentSetupError {
Self::Adaptive(error) | Self::PiiRedaction(error) => {
format!("registration failed: {error}")
}
Self::RemovedNemoGuardrails => REMOVED_NEMO_GUARDRAILS_MESSAGE.into(),
Self::RemovedSwitchyard => REMOVED_SWITCHYARD_MESSAGE.into(),
}
}
Expand All @@ -1046,6 +1050,7 @@ impl std::fmt::Display for PluginComponentSetupError {
"PII redaction plugin registration failed: {error}"
)
}
Self::RemovedNemoGuardrails => formatter.write_str(REMOVED_NEMO_GUARDRAILS_MESSAGE),
Self::RemovedSwitchyard => formatter.write_str(REMOVED_SWITCHYARD_MESSAGE),
}
}
Expand All @@ -1068,6 +1073,13 @@ pub(crate) fn register_and_validate_plugin_components(
{
errors.push(PluginComponentSetupError::RemovedSwitchyard);
}
if plugin_config
.components
.iter()
.any(|component| component.kind == "nemo_guardrails")
{
errors.push(PluginComponentSetupError::RemovedNemoGuardrails);
}
errors
}

Expand Down
Loading
Loading