4949import org .apache .camel .support .DefaultAsyncProducer ;
5050import org .apache .camel .support .ResourceHelper ;
5151import org .apache .camel .util .ObjectHelper ;
52+ import org .slf4j .Logger ;
53+ import org .slf4j .LoggerFactory ;
5254
5355/**
5456 * OpenAI producer for chat completion.
5557 */
5658public class OpenAIProducer extends DefaultAsyncProducer {
5759
60+ private static final Logger LOG =LoggerFactory .getLogger (OpenAIProducer .class );
5861private static final ObjectMapper OBJECT_MAPPER =new ObjectMapper ();
5962
6063public OpenAIProducer (OpenAIEndpoint endpoint ) {
@@ -347,8 +350,9 @@ private void processNonStreaming(Exchange exchange, ChatCompletionCreateParams p
347350 }
348351
349352private void processStreaming (Exchange exchange ,ChatCompletionCreateParams params ) {
353+ // NOTE: the stream is going to be closed after the exchange completes.
350354StreamResponse <ChatCompletionChunk >streamResponse =getEndpoint ().getClient ().chat ().completions ()
351- .createStreaming (params );
355+ .createStreaming (params );// NOSONAR
352356
353357// hand Camel an Iterator for streaming EIPs (split, recipientList, etc.)
354358Iterator <ChatCompletionChunk >it =streamResponse .stream ().iterator ();
@@ -370,6 +374,7 @@ private void safeClose() {
370374try {
371375streamResponse .close ();
372376 }catch (Exception ignore ) {
377+ LOG .warn ("An error happened while processing streaming: ignoring" ,ignore );
373378 }
374379 }
375380 });