Removed closest_value logic

This commit is contained in:
Eric Traut
2026-01-12 13:14:58 -08:00
parent 7baa1870b0
commit 30a26ce7b6

View File

@@ -513,48 +513,14 @@ fn sanitize_reasoning_effort_table(
table.remove("model_reasoning_effort");
let suggestion = closest_value(&normalized, allowed);
let suggestion_text = suggestion
.as_deref()
.map(|value| format!(" Did you mean \"{value}\"?"))
.unwrap_or_default();
let allowed_text = allowed.join(", ");
warnings.push(ConfigWarning {
message: format!(
"Invalid config value for {path}: \"{raw}\". Allowed values: {allowed_text}.{suggestion_text} Falling back to default."
"Invalid config value for {path}: \"{raw}\". Allowed values: {allowed_text}. Falling back to default."
),
});
}
fn closest_value(input: &str, options: &[String]) -> Option<String> {
let mut best: Option<(&String, usize)> = None;
for option in options {
let distance = edit_distance(input, option);
match best {
Some((_, best_distance)) if distance >= best_distance => {}
_ => best = Some((option, distance)),
}
}
best.map(|(option, _)| option.clone())
}
fn edit_distance(a: &str, b: &str) -> usize {
let mut costs = (0..=b.len()).collect::<Vec<_>>();
for (i, ca) in a.chars().enumerate() {
let mut last = i;
costs[0] = i + 1;
for (j, cb) in b.chars().enumerate() {
let next = costs[j + 1];
let replace_cost = if ca == cb { last } else { last + 1 };
let insert_cost = costs[j] + 1;
let delete_cost = costs[j + 1] + 1;
costs[j + 1] = replace_cost.min(insert_cost).min(delete_cost);
last = next;
}
}
costs[b.len()]
}
impl Config {
/// This is the preferred way to create an instance of [Config].
pub async fn load_with_cli_overrides(