// Placeholder message for the upcoming AI reply
MarkdownMessage reply = new MarkdownMessage("Assistant");
messageList.add(reply);
// Ask AI and stream back the reply to UI
Prompt prompt = new Prompt(chatHistory);
chatClient.stream(prompt)
.doOnComplete(() -> chatHistory.add(new AssistantMessage(reply.getMarkdown())))
.subscribe(cr -> reply.appendMarkdownAsync(cr.getResult().getOutput().getContent()));
This is example of the code I'm optimizing: