Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa0d3d9

Browse files
committed
fix(components): openai stream closure design note
1 parentdd49696 commitaa0d3d9

File tree

1 file changed

+6
-1
lines changed
  • components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai

1 file changed

+6
-1
lines changed

‎components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@
4949
importorg.apache.camel.support.DefaultAsyncProducer;
5050
importorg.apache.camel.support.ResourceHelper;
5151
importorg.apache.camel.util.ObjectHelper;
52+
importorg.slf4j.Logger;
53+
importorg.slf4j.LoggerFactory;
5254

5355
/**
5456
* OpenAI producer for chat completion.
5557
*/
5658
publicclassOpenAIProducerextendsDefaultAsyncProducer {
5759

60+
privatestaticfinalLoggerLOG =LoggerFactory.getLogger(OpenAIProducer.class);
5861
privatestaticfinalObjectMapperOBJECT_MAPPER =newObjectMapper();
5962

6063
publicOpenAIProducer(OpenAIEndpointendpoint) {
@@ -347,8 +350,9 @@ private void processNonStreaming(Exchange exchange, ChatCompletionCreateParams p
347350
}
348351

349352
privatevoidprocessStreaming(Exchangeexchange,ChatCompletionCreateParamsparams) {
353+
// NOTE: the stream is going to be closed after the exchange completes.
350354
StreamResponse<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.)
354358
Iterator<ChatCompletionChunk>it =streamResponse.stream().iterator();
@@ -370,6 +374,7 @@ private void safeClose() {
370374
try {
371375
streamResponse.close();
372376
}catch (Exceptionignore) {
377+
LOG.warn("An error happened while processing streaming: ignoring",ignore);
373378
}
374379
}
375380
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp