| 136 | } // namespace |
| 137 | |
| 138 | StableAudioRequest parse_stable_audio_request(const runtime::TaskRequest & request) { |
| 139 | StableAudioRequest out; |
| 140 | if (const auto value = runtime::parse_int_option(request.options, {"batch_size"})) { |
| 141 | if (*value <= 0) { |
| 142 | throw std::runtime_error("Stable Audio batch_size must be positive"); |
| 143 | } |
| 144 | out.batch_size = *value; |
| 145 | } |
| 146 | out.prompts = prompts_from_request(request, out.batch_size); |
| 147 | out.negative_prompts = negative_prompts_from_request(request, out.batch_size); |
| 148 | out.durations_seconds = durations_from_request(request, out.batch_size); |
| 149 | if (const auto value = runtime::parse_int_option(request.options, {"num_inference_steps"})) { |
| 150 | if (*value <= 0) { |
| 151 | throw std::runtime_error("Stable Audio num_inference_steps must be positive"); |
| 152 | } |
| 153 | out.num_inference_steps = *value; |
| 154 | } |
| 155 | if (const auto value = runtime::find_option(request.options, {"sampler"})) { |
| 156 | if (*value != "pingpong" && *value != "euler") { |
| 157 | throw std::runtime_error("Stable Audio sampler must be pingpong or euler"); |
| 158 | } |
| 159 | out.sampler = *value; |
| 160 | } |
| 161 | if (const auto value = runtime::parse_finite_float_option(request.options, {"guidance_scale"})) { |
| 162 | out.guidance_scale = *value; |
| 163 | } |
| 164 | if (const auto value = runtime::parse_finite_float_option(request.options, {"apg_scale"})) { |
| 165 | out.apg_scale = *value; |
| 166 | } |
| 167 | if (const auto value = runtime::parse_u64_option(request.options, {"seed"})) { |
| 168 | out.seed = *value; |
| 169 | out.seed_specified = true; |
| 170 | } else { |
| 171 | out.seed = runtime::random_u64_seed(); |
| 172 | } |
| 173 | if (const auto value = runtime::find_option(request.options, {"truncate_output_to_duration"})) { |
| 174 | out.truncate_output_to_duration = runtime::parse_bool_option(*value, "truncate_output_to_duration"); |
| 175 | } |
| 176 | if (const auto value = runtime::find_option(request.options, {"chunked_decode"})) { |
| 177 | out.chunked_decode = runtime::parse_bool_option(*value, "chunked_decode"); |
| 178 | } |
| 179 | if (const auto value = runtime::parse_finite_float_option(request.options, {"duration_padding_seconds"})) { |
| 180 | if (*value < 0.0F) { |
| 181 | throw std::runtime_error("Stable Audio duration_padding_seconds must be non-negative"); |
| 182 | } |
| 183 | out.duration_padding_seconds = *value; |
| 184 | } |
| 185 | if (const auto value = runtime::parse_finite_float_option(request.options, {"init_noise_level"})) { |
| 186 | if (*value < 0.0F || *value > 1.0F) { |
| 187 | throw std::runtime_error("Stable Audio init_noise_level must be in [0, 1]"); |
| 188 | } |
| 189 | out.init_noise_level = *value; |
| 190 | } |
| 191 | const auto audio_input_kind = runtime::find_option(request.options, {"audio_input_kind"}); |
| 192 | if (audio_input_kind.has_value() && *audio_input_kind != "init_audio" && *audio_input_kind != "inpaint_audio") { |
| 193 | throw std::runtime_error("Stable Audio audio_input_kind must be init_audio or inpaint_audio"); |
| 194 | } |
| 195 | if (request.audio_input.has_value() && (!audio_input_kind.has_value() || *audio_input_kind == "init_audio")) { |
no test coverage detected