/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
#![allow(clippy::needless_return, clippy::into_iter_on_ref)]
use super::{configuration, multipart_helper, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
use tokio::fs::File as TokioFile;
use tokio_util::codec::{BytesCodec, FramedRead};
/// struct for typed errors of method [`create_speech`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSpeechError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(String),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_transcription`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateTranscriptionError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(String),
Status413(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_translation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateTranslationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(String),
Status413(models::ErrorResponse),
Status429(models::ErrorResponse),
Status500(models::ErrorResponse),
Status502(models::ErrorResponse),
Status503(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_voice`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateVoiceError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
Status500(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_voice_consent`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateVoiceConsentError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_voice_consent`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteVoiceConsentError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_voice_consent`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVoiceConsentError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_voice_consents`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListVoiceConsentsError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_voice_consent`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateVoiceConsentError {
Status400(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// Generates audio from the input text. Returns the audio file content, or a stream of audio events.
#[bon::builder]
pub async fn create_speech(
configuration: &configuration::Configuration,
create_speech_request: models::CreateSpeechRequest,
) -> Result<reqwest::Response, Error<CreateSpeechError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_speech_request = create_speech_request;
let uri_str = format!("{}/audio/speech", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_speech_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(resp)
} else {
let content = resp.text().await?;
let entity: Option<CreateSpeechError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Transcribes audio into the input language. Returns a transcription object in `json`, `diarized_json`, or `verbose_json` format, plain text in `text`, `srt`, or `vtt` format, or a stream of transcript events. Supported formats depend on the model.
#[bon::builder]
pub async fn create_transcription(
configuration: &configuration::Configuration,
file: std::path::PathBuf,
model: &str,
language: Option<&str>,
languages: Option<Vec<String>>,
keywords: Option<Vec<String>>,
prompt: Option<&str>,
response_format: Option<models::AudioResponseFormat>,
temperature: Option<f64>,
include: Option<Vec<models::TranscriptionInclude>>,
timestamp_granularities: Option<Vec<String>>,
stream: Option<bool>,
chunking_strategy: Option<models::CreateTranscriptionRequestChunkingStrategy>,
known_speaker_names: Option<Vec<String>>,
known_speaker_references: Option<Vec<String>>,
) -> Result<models::CreateTranscription200Response, Error<CreateTranscriptionError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_form_file = file;
let p_form_model = model;
let p_form_language = language;
let p_form_languages = languages;
let p_form_keywords = keywords;
let p_form_prompt = prompt;
let p_form_response_format = response_format;
let p_form_temperature = temperature;
let p_form_include = include;
let p_form_timestamp_granularities = timestamp_granularities;
let p_form_stream = stream;
let p_form_chunking_strategy = chunking_strategy;
let p_form_known_speaker_names = known_speaker_names;
let p_form_known_speaker_references = known_speaker_references;
let uri_str = format!("{}/audio/transcriptions", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
// Add file to multipart form
multipart_form = multipart_helper::add_file_to_form(multipart_form, &p_form_file, "file")?;
multipart_form = multipart_form.text("model", p_form_model.to_string());
if let Some(param_value) = p_form_language {
multipart_form = multipart_form.text("language", param_value.to_string());
}
if let Some(param_value) = p_form_languages {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"languages",
serde_json::to_value(item)?,
None,
)?;
}
}
if let Some(param_value) = p_form_keywords {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"keywords",
serde_json::to_value(item)?,
None,
)?;
}
}
if let Some(param_value) = p_form_prompt {
multipart_form = multipart_form.text("prompt", param_value.to_string());
}
if let Some(param_value) = p_form_response_format {
multipart_form = multipart_form.text("response_format", param_value.to_string());
}
if let Some(param_value) = p_form_temperature {
multipart_form = multipart_form.text("temperature", param_value.to_string());
}
if let Some(param_value) = p_form_include {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"include",
serde_json::to_value(item)?,
None,
)?;
}
}
if let Some(param_value) = p_form_timestamp_granularities {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"timestamp_granularities",
serde_json::to_value(item)?,
None,
)?;
}
}
if let Some(param_value) = p_form_stream {
multipart_form = multipart_form.text("stream", param_value.to_string());
}
if let Some(param_value) = p_form_chunking_strategy {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"chunking_strategy",
serde_json::to_value(param_value)?,
None,
)?;
}
if let Some(param_value) = p_form_known_speaker_names {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"known_speaker_names",
serde_json::to_value(item)?,
None,
)?;
}
}
if let Some(param_value) = p_form_known_speaker_references {
for item in param_value {
multipart_form = multipart_helper::add_schema_value_to_form(
multipart_form,
"known_speaker_references",
serde_json::to_value(item)?,
None,
)?;
}
}
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTranscription200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTranscription200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateTranscriptionError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Translates audio into English.
#[bon::builder]
pub async fn create_translation(
configuration: &configuration::Configuration,
file: std::path::PathBuf,
model: &str,
prompt: Option<&str>,
response_format: Option<&str>,
temperature: Option<f64>,
) -> Result<models::CreateTranslation200Response, Error<CreateTranslationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_form_file = file;
let p_form_model = model;
let p_form_prompt = prompt;
let p_form_response_format = response_format;
let p_form_temperature = temperature;
let uri_str = format!("{}/audio/translations", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
// Add file to multipart form
multipart_form = multipart_helper::add_file_to_form(multipart_form, &p_form_file, "file")?;
multipart_form = multipart_form.text("model", p_form_model.to_string());
if let Some(param_value) = p_form_prompt {
multipart_form = multipart_form.text("prompt", param_value.to_string());
}
if let Some(param_value) = p_form_response_format {
multipart_form = multipart_form.text("response_format", param_value.to_string());
}
if let Some(param_value) = p_form_temperature {
multipart_form = multipart_form.text("temperature", param_value.to_string());
}
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTranslation200Response`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTranslation200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateTranslationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Creates a voice from a text prompt or from a consent recording and an audio sample. For prompt-based creation, send `type: \"prompt\"` with a `name` and `prompt` as JSON or multipart form data. For creation from an audio sample, send `type: \"audio_sample\"` with a `name`, `audio_sample`, and `consent` recording ID as multipart form data. The type defaults to `audio_sample` when omitted. Returns the saved voice's metadata. Voices created from text prompts are supported only in Live, not in Realtime or the speech endpoint. The response does not include preview audio.
#[bon::builder]
pub async fn create_voice(
configuration: &configuration::Configuration,
create_voice_prompt_request: models::CreateVoicePromptRequest,
) -> Result<models::VoiceResource, Error<CreateVoiceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_voice_prompt_request = create_voice_prompt_request;
let uri_str = format!("{}/audio/voices", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_voice_prompt_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateVoiceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Upload a voice consent recording.
#[bon::builder]
pub async fn create_voice_consent(
configuration: &configuration::Configuration,
name: &str,
recording: std::path::PathBuf,
language: &str,
) -> Result<models::VoiceConsentResource, Error<CreateVoiceConsentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_form_name = name;
let p_form_recording = recording;
let p_form_language = language;
let uri_str = format!("{}/audio/voice_consents", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
multipart_form = multipart_form.text("name", p_form_name.to_string());
multipart_form =
multipart_helper::add_file_to_form(multipart_form, &p_form_recording, "recording")?;
multipart_form = multipart_form.text("language", p_form_language.to_string());
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceConsentResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceConsentResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateVoiceConsentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Deletes a voice consent recording.
#[bon::builder]
pub async fn delete_voice_consent(
configuration: &configuration::Configuration,
consent_id: &str,
) -> Result<models::VoiceConsentDeletedResource, Error<DeleteVoiceConsentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_consent_id = consent_id;
let uri_str = format!(
"{}/audio/voice_consents/{consent_id}",
configuration.base_path,
consent_id = crate::apis::urlencode(p_path_consent_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceConsentDeletedResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceConsentDeletedResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteVoiceConsentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Retrieves a voice consent recording.
#[bon::builder]
pub async fn get_voice_consent(
configuration: &configuration::Configuration,
consent_id: &str,
) -> Result<models::VoiceConsentResource, Error<GetVoiceConsentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_consent_id = consent_id;
let uri_str = format!(
"{}/audio/voice_consents/{consent_id}",
configuration.base_path,
consent_id = crate::apis::urlencode(p_path_consent_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceConsentResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceConsentResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetVoiceConsentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Returns a list of voice consent recordings.
#[bon::builder]
pub async fn list_voice_consents(
configuration: &configuration::Configuration,
after: Option<&str>,
limit: Option<i32>,
) -> Result<models::VoiceConsentListResource, Error<ListVoiceConsentsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_after = after;
let p_query_limit = limit;
let uri_str = format!("{}/audio/voice_consents", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_after {
req_builder = req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceConsentListResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceConsentListResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListVoiceConsentsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}
/// Updates a voice consent recording (metadata only).
#[bon::builder]
pub async fn update_voice_consent(
configuration: &configuration::Configuration,
consent_id: &str,
update_voice_consent_request: models::UpdateVoiceConsentRequest,
) -> Result<models::VoiceConsentResource, Error<UpdateVoiceConsentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_consent_id = consent_id;
let p_body_update_voice_consent_request = update_voice_consent_request;
let uri_str = format!(
"{}/audio/voice_consents/{consent_id}",
configuration.base_path,
consent_id = crate::apis::urlencode(p_path_consent_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_voice_consent_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VoiceConsentResource`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VoiceConsentResource`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateVoiceConsentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
})))
}
}