I want to display the text to edittext while fetching data, but this is only showing the data in the end.
Here is the code
void networkcall(String query) {
messageList.add(new MessageModel(query, 1));
messageList.add(new MessageModel("Typing...", 3));
adapter.notifyItemInserted(messageList.size() - 1);
OpenAiService service = new OpenAiService(API_KEY);
List<ChatMessage> message = new ArrayList<ChatMessage>();
message.add(new ChatMessage(ChatMessageRole.USER.value(), query));
ChatCompletionRequest chatCompletionRequest;
chatCompletionRequest = ChatCompletionRequest
.builder()
.model("gpt-3.5-turbo")
.messages(message)
.n(1)
.maxTokens(500)
.logitBias(Collections.emptyMap())
.build();
Flowable<ChatCompletionChunk> flowableResult = service.streamChatCompletion(chatCompletionRequest);
StringBuilder buffer = new StringBuilder();
flowableResult.subscribe(chunk -> {
chunk.getChoices().forEach(choice -> {
String result = choice.getMessage().getContent();
if (result != null) {
buffer.append(result);
Log.d("Gdfgrd", result);
runOnUiThread(new Runnable() {
@Override
public void run() {
editQuery.setText(buffer);
}
});
Log.d("Gdfgrd", result);
}
});
});
message.add(new ChatMessage(ChatMessageRole.SYSTEM.value(), buffer.toString()));
}
I was expecting the buffer to be displayed in the EditText
like ChatGPT.