Skip to content

Commit 602b435

Browse files
committed
Review code
1 parent a8f7b20 commit 602b435

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

  • services/openai-dialog/src

services/openai-dialog/src/lib.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,9 @@ fn infer_protocol_from_host(host: Option<&str>) -> Result<Protocol> {
156156

157157
let parsed = Url::parse(host).with_context(|| format!("Invalid host URL: {host}"))?;
158158

159-
let is_openai_realtime_endpoint = parsed.scheme() == "wss"
160-
&& parsed.host_str() == Some("api.openai.com")
161-
&& parsed.path() == "/v1/realtime";
162-
163-
if is_openai_realtime_endpoint {
164-
return Ok(Protocol::OpenAI);
165-
}
166-
167-
match parsed.host_str() {
168-
Some(host) if host.ends_with(".openai.azure.com") => Ok(Protocol::Azure),
159+
match (parsed.scheme(), parsed.host_str(), parsed.path()) {
160+
("wss", Some("api.openai.com"), "/v1/realtime") => Ok(Protocol::OpenAI),
161+
(_, Some(host), _) if host.ends_with(".openai.azure.com") => Ok(Protocol::Azure),
169162
_ => bail!(
170163
"Cannot infer protocol from host `{host}`. Set `protocol` explicitly to `openai` or `azure`, use `wss://api.openai.com/v1/realtime`, or use an Azure OpenAI host."
171164
),
@@ -458,29 +451,30 @@ impl Client {
458451
other => bail!("Unexpected non-realtime session: {other:?}"),
459452
};
460453

461-
let input_format = session
462-
.audio
463-
.as_ref()
454+
// OpenAI may omit audio here; treat missing as default behavior.
455+
let audio = session.audio.as_ref();
456+
457+
let input_format = audio
464458
.and_then(|a| a.input.as_ref())
465459
.and_then(|i| i.format.as_ref());
466-
let output_format = session
467-
.audio
468-
.as_ref()
469-
.and_then(|a| a.output.as_ref())
470-
.and_then(|o| o.format.as_ref());
471460

472461
if let Some(format) = input_format
473462
&& !matches!(format, types::AudioFormat::Pcm(_))
474463
{
475464
bail!("Unexpected input audio format: {input_format:?}, expected PCM")
476465
}
477466

467+
let output_format = audio
468+
.and_then(|a| a.output.as_ref())
469+
.and_then(|o| o.format.as_ref());
470+
478471
if let Some(format) = output_format
479472
&& !matches!(format, types::AudioFormat::Pcm(_))
480473
{
481474
bail!("Unexpected output audio format: {output_format:?}, expected PCM")
482475
}
483476

477+
// OpenAI may omit output modalities here; treat missing as default behavior.
484478
let modalities = session.output_modalities.unwrap_or_default();
485479
if !modalities.is_empty()
486480
&& !modalities

0 commit comments

Comments
 (0)