From ae346f3e44cb1df9d3d405675ff89725259e2e6e Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Thu, 15 Aug 2024 14:13:11 -0400 Subject: [PATCH 1/5] Implement From for Model, Language, and Redact --- src/common/options.rs | 129 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 6 deletions(-) diff --git a/src/common/options.rs b/src/common/options.rs index 5e0755da..be0b0341 100644 --- a/src/common/options.rs +++ b/src/common/options.rs @@ -2224,6 +2224,52 @@ impl AsRef for Model { } } +impl From for Model { + fn from(value: String) -> Self { + match &*value { + "nova-2" => Self::Nova2, + "nova" => Self::Nova, + "enhanced" => Self::Enhanced, + "base" => Self::Base, + "nova-2-meeting" => Self::Nova2Meeting, + "nova-2-phonecall" => Self::Nova2Phonecall, + "nova-2-finance" => Self::Nova2Finance, + "nova-2-conversationalai" => Self::Nova2Conversationalai, + "nova-2-voicemail" => Self::Nova2Voicemail, + "nova-2-video" => Self::Nova2Video, + "nova-2-medical" => Self::Nova2Medical, + "nova-2-drivethru" => Self::Nova2Drivethru, + "nova-2-automotive" => Self::Nova2Automotive, + "nova-phonecall" => Self::NovaPhonecall, + "nova-medical" => Self::NovaMedical, + "enhanced-meeting" => Self::EnhancedMeeting, + "enhanced-phonecall" => Self::EnhancedPhonecall, + "enhanced-finance" => Self::EnhancedFinance, + "base-meeting" => Self::BaseMeeting, + "base-phonecall" => Self::BasePhonecall, + "base-voicemail" => Self::BaseVoicemail, + "base-finance" => Self::BaseFinance, + "base-conversationalai" => Self::BaseConversationalai, + "base-video" => Self::BaseVideo, + #[allow(deprecated)] + "general" => Self::General, + #[allow(deprecated)] + "phonecall" => Self::Phonecall, + #[allow(deprecated)] + "voicemail" => Self::Voicemail, + #[allow(deprecated)] + "finance" => Self::Finance, + #[allow(deprecated)] + "meeting" => Self::Meeting, + #[allow(deprecated)] + "conversationalai" => Self::Conversationalai, + #[allow(deprecated)] + "video" => Self::Video, + _ => Self::CustomId(value), + } + } +} + impl AsRef for Language { fn as_ref(&self) -> &str { match self { @@ -2286,15 +2332,86 @@ impl AsRef for Language { } } +impl From for Language { + fn from(value: String) -> Language { + match &*value { + "bg" => Self::bg, + "ca" => Self::ca, + "cs" => Self::cs, + "da" => Self::da, + "de" => Self::de, + "de-CH" => Self::de_CH, + "el" => Self::el, + "en" => Self::en, + "en-AU" => Self::en_AU, + "en-GB" => Self::en_GB, + "en-IN" => Self::en_IN, + "en-NZ" => Self::en_NZ, + "en-US" => Self::en_US, + "es" => Self::es, + "es-419" => Self::es_419, + "es-LATAM" => Self::es_LATAM, + "et" => Self::et, + "fi" => Self::fi, + "fr" => Self::fr, + "fr-CA" => Self::fr_CA, + "hi" => Self::hi, + "hi-Latn" => Self::hi_Latn, + "hu" => Self::hu, + "id" => Self::id, + "it" => Self::it, + "ja" => Self::ja, + "ko" => Self::ko, + "ko-KR" => Self::ko_KR, + "lv" => Self::lv, + "lt" => Self::lt, + "ms" => Self::ms, + "nl" => Self::nl, + "nl-BE" => Self::nl_BE, + "no" => Self::no, + "pl" => Self::pl, + "pt" => Self::pt, + "pt-BR" => Self::pt_BR, + "ro" => Self::ro, + "ru" => Self::ru, + "sk" => Self::sk, + "sv" => Self::sv, + "sv-SE" => Self::sv_SE, + "ta" => Self::ta, + "taq" => Self::taq, + "th" => Self::th, + "th-TH" => Self::th_TH, + "tr" => Self::tr, + "uk" => Self::uk, + "vi" => Self::vi, + "zh" => Self::zh, + "zh-CN" => Self::zh_CN, + "zh-Hans" => Self::zh_Hans, + "zh-Hant" => Self::zh_Hant, + "zh-TW" => Self::zh_TW, + _ => Self::Other(value), + } + } +} + impl AsRef for Redact { fn as_ref(&self) -> &str { - use Redact::*; - match self { - Pci => "pci", - Numbers => "numbers", - Ssn => "ssn", - Other(id) => id, + Redact::Pci => "pci", + Redact::Numbers => "numbers", + Redact::Ssn => "ssn", + Redact::Other(id) => id, + } + } +} + +impl From for Redact { + fn from(value: String) -> Redact { + match &*value { + "pci" => Redact::Pci, + "numbers" => Redact::Numbers, + "ssn" => Redact::Ssn, + _ => Redact::Other(value), } } } From aabb38d31d99c0a0290d3a512883be16a88369ad Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Thu, 15 Aug 2024 14:24:24 -0400 Subject: [PATCH 2/5] Add `From` tests --- src/common/options.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/common/options.rs b/src/common/options.rs index be0b0341..fe040652 100644 --- a/src/common/options.rs +++ b/src/common/options.rs @@ -2424,6 +2424,32 @@ fn models_to_string(models: &[Model]) -> String { .join(":") } +#[cfg(test)] +mod from_string_tests { + use super::{Language, Model, Redact}; + + #[test] + fn model_from_string() { + assert_eq!(Model::from("nova-2".to_string()), Model::Nova2); + assert_eq!(Model::from("custom".to_string()), Model::CustomId("custom".to_string())); + assert_eq!(Model::from("".to_string()), Model::CustomId("".to_string())); + } + + #[test] + fn language_from_string() { + assert_eq!(Language::from("zh-Hant".to_string()), Language::zh_Hant); + assert_eq!(Language::from("custom".to_string()), Language::Other("custom".to_string())); + assert_eq!(Language::from("".to_string()), Language::Other("".to_string())); + } + + #[test] + fn redact_from_string() { + assert_eq!(Redact::from("pci".to_string()), Redact::Pci); + assert_eq!(Redact::from("custom".to_string()), Redact::Other("custom".to_string())); + assert_eq!(Redact::from("".to_string()), Redact::Other("".to_string())); + } + +} #[cfg(test)] mod models_to_string_tests { use super::*; From 159fc8b1aaa10e0c123faac9351de86efa5fa895 Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Thu, 15 Aug 2024 14:50:55 -0400 Subject: [PATCH 3/5] fmt --- src/common/options.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/options.rs b/src/common/options.rs index fe040652..d157bf2a 100644 --- a/src/common/options.rs +++ b/src/common/options.rs @@ -2431,24 +2431,35 @@ mod from_string_tests { #[test] fn model_from_string() { assert_eq!(Model::from("nova-2".to_string()), Model::Nova2); - assert_eq!(Model::from("custom".to_string()), Model::CustomId("custom".to_string())); + assert_eq!( + Model::from("custom".to_string()), + Model::CustomId("custom".to_string()) + ); assert_eq!(Model::from("".to_string()), Model::CustomId("".to_string())); } #[test] fn language_from_string() { assert_eq!(Language::from("zh-Hant".to_string()), Language::zh_Hant); - assert_eq!(Language::from("custom".to_string()), Language::Other("custom".to_string())); - assert_eq!(Language::from("".to_string()), Language::Other("".to_string())); + assert_eq!( + Language::from("custom".to_string()), + Language::Other("custom".to_string()) + ); + assert_eq!( + Language::from("".to_string()), + Language::Other("".to_string()) + ); } #[test] fn redact_from_string() { assert_eq!(Redact::from("pci".to_string()), Redact::Pci); - assert_eq!(Redact::from("custom".to_string()), Redact::Other("custom".to_string())); + assert_eq!( + Redact::from("custom".to_string()), + Redact::Other("custom".to_string()) + ); assert_eq!(Redact::from("".to_string()), Redact::Other("".to_string())); } - } #[cfg(test)] mod models_to_string_tests { From 27b5c97a50e57f8b32a8cf121590b8ec283bfe1f Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Fri, 16 Aug 2024 14:14:01 -0400 Subject: [PATCH 4/5] Add explicit `*-general` options. Co-authored-by: Brent George <49082060+bd-g@users.noreply.github.com> --- src/common/options.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/options.rs b/src/common/options.rs index d157bf2a..fe1ac45b 100644 --- a/src/common/options.rs +++ b/src/common/options.rs @@ -2227,10 +2227,10 @@ impl AsRef for Model { impl From for Model { fn from(value: String) -> Self { match &*value { - "nova-2" => Self::Nova2, - "nova" => Self::Nova, - "enhanced" => Self::Enhanced, - "base" => Self::Base, + "nova-2" | "nova-2-general" => Self::Nova2, + "nova" | "nova-general" => Self::Nova, + "enhanced" | "enhanced-general" => Self::Enhanced, + "base" | "base-general" => Self::Base, "nova-2-meeting" => Self::Nova2Meeting, "nova-2-phonecall" => Self::Nova2Phonecall, "nova-2-finance" => Self::Nova2Finance, From 07e8ea1beb451e98c24abcc3abfd34ec6669a210 Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Fri, 16 Aug 2024 14:21:16 -0400 Subject: [PATCH 5/5] fmt --- src/common/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/options.rs b/src/common/options.rs index fe1ac45b..4044ace1 100644 --- a/src/common/options.rs +++ b/src/common/options.rs @@ -2228,7 +2228,7 @@ impl From for Model { fn from(value: String) -> Self { match &*value { "nova-2" | "nova-2-general" => Self::Nova2, - "nova" | "nova-general" => Self::Nova, + "nova" | "nova-general" => Self::Nova, "enhanced" | "enhanced-general" => Self::Enhanced, "base" | "base-general" => Self::Base, "nova-2-meeting" => Self::Nova2Meeting,