Skip to content

Commit

Permalink
[docker run] Fix loading of OpenAI Async client - use the Netty provi…
Browse files Browse the repository at this point in the history
…der instead of okhttp (LangStream#442)
  • Loading branch information
eolivelli committed Sep 19, 2023
1 parent 7bd54e7 commit 0eb9c36
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -84,11 +83,21 @@ public CompletableFuture<ChatCompletions> getChatCompletions(
Flux<com.azure.ai.openai.models.ChatCompletions> flux =
client.getChatCompletionsStream(
(String) options.get("model"), chatCompletionsOptions);
Stream<com.azure.ai.openai.models.ChatCompletions> model = flux.toStream();

ChatCompletionsConsumer chatCompletionsConsumer =
new ChatCompletionsConsumer(
streamingChunksConsumer, minChunksPerMessage, finished);
model.forEach(chatCompletionsConsumer);

flux.doOnError(
error -> {
log.error(
"Internal error while processing the streaming response",
error);
finished.completeExceptionally(error);
})
.doOnNext(chatCompletionsConsumer)
.subscribe();

return finished.thenApply(
___ -> {
result.setChoices(
Expand All @@ -101,8 +110,7 @@ public CompletableFuture<ChatCompletions> getChatCompletions(
} else {
com.azure.ai.openai.models.ChatCompletions chatCompletions =
client.getChatCompletions((String) options.get("model"), chatCompletionsOptions)
.toFuture()
.get();
.block();
result.setChoices(
chatCompletions.getChoices().stream()
.map(c -> new ChatChoice(convertMessage(c)))
Expand Down
10 changes: 10 additions & 0 deletions langstream-runtime/langstream-runtime-tester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,23 @@
<groupId>${project.groupId}</groupId>
<artifactId>langstream-pulsar-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>${project.groupId}</groupId>
<artifactId>langstream-codestorage-azure-blob-storage</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>langstream-webservice</artifactId>
<version>${project.version}</version>
<classifier>original</classifier>
<exclusions>
<exclusion>
<groupId>${project.groupId}</groupId>
<artifactId>langstream-codestorage-azure-blob-storage</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down

0 comments on commit 0eb9c36

Please sign in to comment.