Skip to content

Commit

Permalink
Allow arbitrary query params (reapply) (#73)
Browse files Browse the repository at this point in the history
Allow adding arbitrary query params to prerecorded transcription requests.

Since Deepgram doesn't officially support the rust SDK, it may
occasionally fall behind in feature support.  This change will make it
possible for rust developers to make use of arbitrary new features through
the SDK before a new version gets released.
  • Loading branch information
jcdyer authored Jul 8, 2024
1 parent decda72 commit d60f05b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deprecate tiers and add explicit support for all currently available models.
- Expand language enum to include all currently-supported languages.
- Add (default on) feature flags for live and prerecorded transcription.
- Support arbitrary query params in transcription options.

## [0.4.0] - 2023-11-01

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deepgram"
version = "0.4.0"
version = "0.5.0"
authors = ["Deepgram <[email protected]>"]
edition = "2021"
description = "Official Rust SDK for Deepgram's automated speech recognition APIs."
Expand Down
35 changes: 35 additions & 0 deletions src/transcription/prerecorded/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Options {
utterances: Option<Utterances>,
tags: Vec<String>,
detect_language: Option<bool>,
query_params: Vec<(String, String)>,
}

/// Used as a parameter for [`OptionsBuilder::model`] and [`OptionsBuilder::multichannel_with_models`].
Expand Down Expand Up @@ -464,6 +465,7 @@ impl OptionsBuilder {
utterances: None,
tags: Vec::new(),
detect_language: None,
query_params: Vec::new(),
})
}

Expand Down Expand Up @@ -1229,6 +1231,34 @@ impl OptionsBuilder {

self
}

/// Append extra query parameters to the end of the transcription request.
/// Users should prefer using the other builder methods over this one. This
/// exists as an escape hatch for using features before they have been added
/// to the SDK.
///
/// Calling this twice will add both sets of parameters.
///
/// # Examples
///
/// ```
/// # use deepgram::transcription::prerecorded::options::Options;
///
/// use std::collections::HashMap;
/// let mut params = HashMap::new(); // Could also be a Vec<(String, String)>
/// params.insert("extra".to_string(), "parameter".to_string());
/// let more_params = vec![("final".to_string(), "option".to_string())];
/// let options = Options::builder()
/// .query_params(params)
/// .query_params(more_params)
/// .build();
///
/// ```
pub fn query_params(mut self, params: impl IntoIterator<Item = (String, String)>) -> Self {
self.0.query_params.extend(params);
self
}

/// Finish building the [`Options`] object.
pub fn build(self) -> Options {
self.0
Expand Down Expand Up @@ -1268,6 +1298,7 @@ impl Serialize for SerializableOptions<'_> {
utterances,
tags,
detect_language,
query_params,
} = self.0;

match multichannel {
Expand Down Expand Up @@ -1381,6 +1412,10 @@ impl Serialize for SerializableOptions<'_> {
seq.serialize_element(&("detect_language", detect_language))?;
}

for (param, value) in query_params {
seq.serialize_element(&(param, value))?;
}

seq.end()
}
}
Expand Down

0 comments on commit d60f05b

Please sign in to comment.