Skip to content

Commit dce1c76

Browse files
committed
refactor: improve structure
1 parent 8dc0795 commit dce1c76

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

crates/shared/src/speech.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,16 @@ pub struct ProcessedSpeechOptions {
4747

4848
pub fn process_speech_options(options: SpeechOptions) -> Result<ProcessedSpeechOptions, AppError> {
4949
match options.model.split_once('/') {
50-
Some((provider, model)) => {
51-
if provider.is_empty() || model.is_empty() {
52-
Err(AppError::new(anyhow::anyhow!("Invalid model: {}", options.model), Some(StatusCode::BAD_REQUEST)))
53-
} else {
54-
Ok(ProcessedSpeechOptions {
55-
input: options.input,
56-
model: model.to_string(),
57-
voice: options.voice,
58-
instructions: options.instructions,
59-
response_format: options.response_format,
60-
speed: options.speed,
61-
extra: options.extra,
62-
provider: provider.to_string(),
63-
})
64-
}
65-
}
66-
None => {
67-
Err(AppError::new(anyhow::anyhow!("Invalid model: {}", options.model), Some(StatusCode::BAD_REQUEST)))
68-
}
50+
Some((provider, model)) if !provider.is_empty() && !model.is_empty() => Ok(ProcessedSpeechOptions {
51+
input: options.input,
52+
model: model.to_string(),
53+
voice: options.voice,
54+
instructions: options.instructions,
55+
response_format: options.response_format,
56+
speed: options.speed,
57+
extra: options.extra,
58+
provider: provider.to_string(),
59+
}),
60+
_ => Err(AppError::new(anyhow::anyhow!("Invalid model: {}", options.model), Some(StatusCode::BAD_REQUEST)))
6961
}
7062
}

0 commit comments

Comments
 (0)