fn validate()

in hfendpoints-openai/src/audio/transcription.rs [298:334]


    fn validate(
        file: Option<Bytes>,
        content_type: String,
        language: Option<String>,
        prompt: Option<String>,
        temperature: Option<f32>,
        response_format: Option<String>,
    ) -> HttpResult<Self> {
        let file = match file {
            Some(file) => Ok(file),
            None => Err(HttpError::Validation(
                "Required parameter 'file' was not provided".to_string(),
            )),
        }?;

        let response_format = response_format.unwrap_or(String::from("json"));
        let response_format = match response_format.as_str() {
            "json" => Ok(ResponseFormat::Json),
            "verbose_json" => Ok(ResponseFormat::VerboseJson),
            "text" => Ok(ResponseFormat::Text),
            _ => Err(HttpError::Validation(format!(
                "Unknown response_format: {response_format}. Possible values are: 'json', 'verbose_json', 'text'."
            ))),
        }?;

        let language = language.unwrap_or(String::from("en"));
        let temperature = temperature.unwrap_or(0.0);

        Ok(Self {
            file,
            content_type,
            language,
            prompt,
            temperature,
            response_format,
        })
    }