diff --git a/sdk/openai/inference/src/clients/chat_completions_client.rs b/sdk/openai/inference/src/clients/chat_completions_client.rs index f94e52cf79..6ffefba71c 100644 --- a/sdk/openai/inference/src/clients/chat_completions_client.rs +++ b/sdk/openai/inference/src/clients/chat_completions_client.rs @@ -8,7 +8,7 @@ use azure_core::{ headers::{ACCEPT, CONTENT_TYPE}, Context, Method, Response, Result, }; -use futures::{Stream, TryStreamExt}; +use futures::{Stream, StreamExt}; pub trait ChatCompletionsClientMethods { #[allow(async_fn_in_trait)] @@ -101,11 +101,11 @@ impl EventStreamer for ChatCompletionsStrea response_body: azure_core::ResponseBody, ) -> impl Stream> { let stream_event_delimiter = "\n\n"; - // TODO: is there something like try_map_ok? - let stream = string_chunks(response_body, stream_event_delimiter).map_ok(|event| { - serde_json::from_str::(&event) - .expect("Deserialization failed") - }); - stream + + string_chunks(response_body, stream_event_delimiter).map(|event| match event { + Ok(event) => serde_json::from_str::(&event) + .map_err(|e| e.into()), + Err(e) => Err(e), + }) } }