@@ -26,6 +26,7 @@ pub struct Options {
26
26
search : Vec < String > ,
27
27
replace : Vec < Replace > ,
28
28
keywords : Vec < Keyword > ,
29
+ keyterms : Vec < String > ,
29
30
keyword_boost_legacy : Option < bool > ,
30
31
utterances : Option < Utterances > ,
31
32
tags : Vec < String > ,
@@ -195,6 +196,17 @@ impl fmt::Display for Endpointing {
195
196
#[ derive( Debug , PartialEq , Eq , Clone , Hash ) ]
196
197
#[ non_exhaustive]
197
198
pub enum Model {
199
+ /// Recommended for challenging audio.
200
+ /// Recommended for most use cases.
201
+ ///
202
+ /// Nova-3 expands on Nova-2's advancements with speech-specific
203
+ /// optimizations to the underlying Transformer architecture, advanced
204
+ /// data curation techniques, and a multi-stage training methodology.
205
+ /// These changes yield reduced word error rate (WER) and enhancements
206
+ /// to entity recognition (i.e. proper nouns, alphanumerics, etc.),
207
+ /// punctuation, and capitalization and Keyterms.
208
+ Nova3 ,
209
+
198
210
/// Recommended for readability and Deepgram's lowest word error rates.
199
211
/// Recommended for most use cases.
200
212
///
@@ -703,6 +715,7 @@ impl OptionsBuilder {
703
715
search : Vec :: new ( ) ,
704
716
replace : Vec :: new ( ) ,
705
717
keywords : Vec :: new ( ) ,
718
+ keyterms : Vec :: new ( ) ,
706
719
keyword_boost_legacy : None ,
707
720
utterances : None ,
708
721
tags : Vec :: new ( ) ,
@@ -1911,6 +1924,45 @@ impl OptionsBuilder {
1911
1924
self
1912
1925
}
1913
1926
1927
+ /// Set the Keyterms feature.
1928
+ ///
1929
+ /// Calling this when already set will append to the existing keyterms, not overwrite them.
1930
+ ///
1931
+ /// See the [Deepgram Keyterms feature docs][docs] for more info.
1932
+ ///
1933
+ /// [docs]: https://developers.deepgram.com/docs/keyterm
1934
+ ///
1935
+ /// # Examples
1936
+ ///
1937
+ /// ```
1938
+ /// # use deepgram::common::options::Options;
1939
+ /// #
1940
+ /// let options = Options::builder()
1941
+ /// .keyterms(["hello", "world"])
1942
+ /// .build();
1943
+ /// ```
1944
+ ///
1945
+ /// ```
1946
+ /// # use deepgram::common::options::Options;
1947
+ /// #
1948
+ /// let options1 = Options::builder()
1949
+ /// .keyterms(["hello"])
1950
+ /// .keyterms(["world"])
1951
+ /// .build();
1952
+ ///
1953
+ /// let options2 = Options::builder()
1954
+ /// .keyterms(["hello", "world"])
1955
+ /// .build();
1956
+ ///
1957
+ /// assert_eq!(options1, options2);
1958
+ /// ```
1959
+ pub fn keyterms < ' a > ( mut self , keyterms : impl IntoIterator < Item = & ' a str > ) -> Self {
1960
+ self . 0
1961
+ . keyterms
1962
+ . extend ( keyterms. into_iter ( ) . map ( String :: from) ) ;
1963
+ self
1964
+ }
1965
+
1914
1966
/// Finish building the [`Options`] object.
1915
1967
pub fn build ( self ) -> Options {
1916
1968
self . 0
@@ -1958,6 +2010,7 @@ impl Serialize for SerializableOptions<'_> {
1958
2010
search,
1959
2011
replace,
1960
2012
keywords,
2013
+ keyterms,
1961
2014
keyword_boost_legacy,
1962
2015
utterances,
1963
2016
tags,
@@ -2182,13 +2235,18 @@ impl Serialize for SerializableOptions<'_> {
2182
2235
seq. serialize_element ( & ( "callback_method" , callback_method. as_str ( ) ) ) ?;
2183
2236
}
2184
2237
2238
+ for element in keyterms {
2239
+ seq. serialize_element ( & ( "keyterm" , element) ) ?;
2240
+ }
2241
+
2185
2242
seq. end ( )
2186
2243
}
2187
2244
}
2188
2245
2189
2246
impl AsRef < str > for Model {
2190
2247
fn as_ref ( & self ) -> & str {
2191
2248
match self {
2249
+ Self :: Nova3 => "nova-3" ,
2192
2250
Self :: Nova2 => "nova-2" ,
2193
2251
Self :: Nova => "nova" ,
2194
2252
Self :: Enhanced => "enhanced" ,
@@ -2985,4 +3043,84 @@ mod serialize_options_tests {
2985
3043
"paragraphs=true" ,
2986
3044
) ;
2987
3045
}
3046
+
3047
+ #[ test]
3048
+ fn keyterms_serialization ( ) {
3049
+ check_serialization ( & Options :: builder ( ) . keyterms ( [ ] ) . build ( ) , "" ) ;
3050
+
3051
+ check_serialization (
3052
+ & Options :: builder ( ) . keyterms ( [ "hello" ] ) . build ( ) ,
3053
+ "keyterm=hello" ,
3054
+ ) ;
3055
+
3056
+ check_serialization (
3057
+ & Options :: builder ( ) . keyterms ( [ "hello" , "world" ] ) . build ( ) ,
3058
+ "keyterm=hello&keyterm=world" ,
3059
+ ) ;
3060
+
3061
+ // Test URL encoding of spaces
3062
+ check_serialization (
3063
+ & Options :: builder ( ) . keyterms ( [ "hello world" ] ) . build ( ) ,
3064
+ "keyterm=hello+world" ,
3065
+ ) ;
3066
+
3067
+ // Test with other features
3068
+ check_serialization (
3069
+ & Options :: builder ( )
3070
+ . model ( Model :: Nova3 )
3071
+ . language ( Language :: en)
3072
+ . keyterms ( [ "hello" , "world" ] )
3073
+ . punctuate ( true )
3074
+ . build ( ) ,
3075
+ "model=nova-3&language=en&punctuate=true&keyterm=hello&keyterm=world" ,
3076
+ ) ;
3077
+
3078
+ // Test with multiple words per keyterm
3079
+ check_serialization (
3080
+ & Options :: builder ( )
3081
+ . keyterms ( [ "hello world" , "rust programming" ] )
3082
+ . build ( ) ,
3083
+ "keyterm=hello+world&keyterm=rust+programming" ,
3084
+ ) ;
3085
+ }
3086
+
3087
+ #[ test]
3088
+ fn keyterms ( ) {
3089
+ check_serialization ( & Options :: builder ( ) . keyterms ( [ ] ) . build ( ) , "" ) ;
3090
+
3091
+ check_serialization (
3092
+ & Options :: builder ( ) . keyterms ( [ "hello" ] ) . build ( ) ,
3093
+ "keyterm=hello" ,
3094
+ ) ;
3095
+
3096
+ check_serialization (
3097
+ & Options :: builder ( ) . keyterms ( [ "hello" , "world" ] ) . build ( ) ,
3098
+ "keyterm=hello&keyterm=world" ,
3099
+ ) ;
3100
+
3101
+ // Test URL encoding of spaces
3102
+ check_serialization (
3103
+ & Options :: builder ( ) . keyterms ( [ "hello world" ] ) . build ( ) ,
3104
+ "keyterm=hello+world" ,
3105
+ ) ;
3106
+
3107
+ // Test with other features
3108
+ check_serialization (
3109
+ & Options :: builder ( )
3110
+ . model ( Model :: Nova3 )
3111
+ . language ( Language :: en)
3112
+ . keyterms ( [ "hello" , "world" ] )
3113
+ . punctuate ( true )
3114
+ . build ( ) ,
3115
+ "model=nova-3&language=en&punctuate=true&keyterm=hello&keyterm=world" ,
3116
+ ) ;
3117
+
3118
+ // Test with multiple words per keyterm
3119
+ check_serialization (
3120
+ & Options :: builder ( )
3121
+ . keyterms ( [ "hello world" , "rust programming" ] )
3122
+ . build ( ) ,
3123
+ "keyterm=hello+world&keyterm=rust+programming" ,
3124
+ ) ;
3125
+ }
2988
3126
}
0 commit comments