Skip to content

Commit

Permalink
Implement From<String> for Model, Language, and Redact (#86)
Browse files Browse the repository at this point in the history
---
Co-authored-by: Brent George <[email protected]>
  • Loading branch information
jcdyer authored Aug 16, 2024
1 parent f8d070c commit eec66ac
Showing 1 changed file with 160 additions and 6 deletions.
166 changes: 160 additions & 6 deletions src/common/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,52 @@ impl AsRef<str> for Model {
}
}

impl From<String> for Model {
fn from(value: String) -> Self {
match &*value {
"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,
"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<str> for Language {
fn as_ref(&self) -> &str {
match self {
Expand Down Expand Up @@ -2286,15 +2332,86 @@ impl AsRef<str> for Language {
}
}

impl From<String> 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<str> 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<String> for Redact {
fn from(value: String) -> Redact {
match &*value {
"pci" => Redact::Pci,
"numbers" => Redact::Numbers,
"ssn" => Redact::Ssn,
_ => Redact::Other(value),
}
}
}
Expand All @@ -2307,6 +2424,43 @@ 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::*;
Expand Down

0 comments on commit eec66ac

Please sign in to comment.