A high-performance inference engine for AI models
remove cli settings hardcode
eugene49bdc9dc9af6
diff --git a/crates/uzu/src/cli/components/preferences.rs b/crates/uzu/src/cli/components/preferences.rsindex 470f0ed73..a1855fc44 100644--- a/crates/uzu/src/cli/components/preferences.rs+++ b/crates/uzu/src/cli/components/preferences.rs@@ -50,7 +50,7 @@ impl SamplingMode {}}-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]+#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]#[serde(default)]pub struct SamplingPreferences {pub mode: SamplingMode,@@ -67,25 +67,6 @@ pub struct SamplingPreferences {pub suffix_repetition_length: i64,}-impl Default for SamplingPreferences {- fn default() -> Self {- Self {- mode: SamplingMode::default(),- temperature_enabled: false,- temperature: 0.8,- top_k_enabled: false,- top_k: 64,- top_p_enabled: false,- top_p: 0.95,- min_p_enabled: false,- min_p: 0.05,- repetition_penalty_enabled: false,- repetition_penalty: 1.1,- suffix_repetition_length: 1024,- }- }-}-impl SamplingPreferences {pub fn suffix_repetition_length_enabled(&self) -> bool {self.repetition_penalty_enabled@@ -190,66 +171,3 @@ pub(super) fn cycle<T: Copy + PartialEq>(let next = (index + delta).rem_euclid(length) as usize;values[next]}--#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn model_default_maps_to_default_policy() {- let prefs = SamplingPreferences {- mode: SamplingMode::ModelDefault,- ..SamplingPreferences::default()- };- assert!(matches!(prefs.policy(), SamplingPolicy::Default {}));- }-- #[test]- fn greedy_maps_to_greedy_method() {- let prefs = SamplingPreferences {- mode: SamplingMode::Greedy,- ..SamplingPreferences::default()- };- assert!(matches!(- prefs.policy(),- SamplingPolicy::Custom {- method: SamplingMethod::Greedy {},- }- ));- }-- #[test]- fn stochastic_only_forwards_enabled_parameters() {- let prefs = SamplingPreferences {- mode: SamplingMode::Stochastic,- temperature_enabled: true,- temperature: 0.7,- top_k_enabled: false,- top_p_enabled: true,- top_p: 0.9,- min_p_enabled: false,- ..SamplingPreferences::default()- };- match prefs.policy() {- SamplingPolicy::Custom {- method:- SamplingMethod::Stochastic {- temperature,- top_k,- top_p,- min_p,- repetition_penalty,- suffix_repetition_length,- },- } => {- assert_eq!(temperature, Some(0.7));- assert_eq!(top_k, None);- assert_eq!(top_p, Some(0.9));- assert_eq!(min_p, None);- assert_eq!(repetition_penalty, None);- assert_eq!(suffix_repetition_length, None);- },- _ => panic!("stochastic mode must map to a custom stochastic policy"),- }- }-}diff --git a/crates/uzu/src/cli/flows/settings.rs b/crates/uzu/src/cli/flows/settings.rsindex 2620a79e6..05ba8eee9 100644--- a/crates/uzu/src/cli/flows/settings.rs+++ b/crates/uzu/src/cli/flows/settings.rs@@ -113,27 +113,48 @@ fn toggle(preferences: &mut Preferences,field: Field,support: ThinkingSupport,+ defaults: ModelSamplingDefaults,) {+ let sampling = &mut preferences.sampling;match field {Field::Thinking => adjust(preferences, Field::Thinking, 1, support),- Field::SamplingMode => preferences.sampling.mode = preferences.sampling.mode.next(),- Field::Temperature => preferences.sampling.temperature_enabled = !preferences.sampling.temperature_enabled,- Field::TopK => preferences.sampling.top_k_enabled = !preferences.sampling.top_k_enabled,- Field::TopP => preferences.sampling.top_p_enabled = !preferences.sampling.top_p_enabled,- Field::MinP => preferences.sampling.min_p_enabled = !preferences.sampling.min_p_enabled,+ Field::SamplingMode => sampling.mode = sampling.mode.next(),+ Field::Temperature => {+ toggle_value(&mut sampling.temperature_enabled, &mut sampling.temperature, defaults.temperature)+ },+ Field::TopK => toggle_value(&mut sampling.top_k_enabled, &mut sampling.top_k, defaults.top_k),+ Field::TopP => toggle_value(&mut sampling.top_p_enabled, &mut sampling.top_p, defaults.top_p),+ Field::MinP => toggle_value(&mut sampling.min_p_enabled, &mut sampling.min_p, defaults.min_p),Field::RepetitionPenalty => {- preferences.sampling.repetition_penalty_enabled = !preferences.sampling.repetition_penalty_enabled+ toggle_value(+ &mut sampling.repetition_penalty_enabled,+ &mut sampling.repetition_penalty,+ defaults.repetition_penalty,+ );+ if sampling.repetition_penalty_enabled+ && let Some(value) = defaults.suffix_repetition_length+ {+ sampling.suffix_repetition_length = value;+ }},Field::SuffixRepetitionLength => {- assert!(- preferences.sampling.suffix_repetition_length_enabled(),- "suffix_repetition_length cannot be enabled"- );- preferences.sampling.suffix_repetition_length_disable();+ assert!(sampling.suffix_repetition_length_enabled(), "suffix_repetition_length cannot be enabled");+ sampling.suffix_repetition_length_disable();},}}+fn toggle_value<T>(+ enabled: &mut bool,+ value: &mut T,+ default: Option<T>,+) {+ *enabled = !*enabled;+ if *enabled && let Some(default) = default {+ *value = default;+ }+}+fn step_f64(value: f64,delta: i64,@@ -246,7 +267,7 @@ fn SettingsFlowView(},KeyCode::Char(' ') => {let mut preferences = draft.get();- toggle(&mut preferences, field, support);+ toggle(&mut preferences, field, support, defaults);draft.set(preferences);},KeyCode::Enter => {