Marcello Pucci
Marcello Pucci

Reputation: 11

Webflux and Flux<String> issue with whitespaces

I am trying to consume a REST service that produces a response of this type: ResponseEntity<Flux>.

My requirement is to perform benchmarks on the generation of individual tokens, so it's essential to work with the flux. The REST call works, but there seems to be an issue with whitespace characters.

        Flux<String> eventStream=
          webClientBuilder
                    .clientConnector(new ReactorClientHttpConnector(httpClient))
                    .baseUrl(baseUrl)
                    .build()
                    .post()
                    .uri(uriBuilder -> uriBuilder.path(uri).queryParam("temperature", "0.3").build(llmType))
                    .accept(MediaType.TEXT_EVENT_STREAM).headers(httpHeaders -> httpHeaders.addAll(headers))
                    .bodyValue(body)
                    .retrieve()
                    .bodyToFlux(String.class);
        
        List<String> resultList=
                            eventStream
                            .doOnNext(event->{
                                log.info(event.toString()+" "+event.length());
                            })
                            .doOnComplete(() -> {
                                log.debug("Completed thread {}..................",id);
                            })
                            .collectList()
                            .block();
        
        log.info(String.join("",resultList));

"Certo!Eccoperteunafilastroccaincantevoleevivace,pensataperincantareedivertirechilalegge...."

Expected

"Certo! Ecco per te una filastrocca incantevole e vivace,p ensata per incantare e divertire chi la legge ..."

Upvotes: 1

Views: 53

Answers (0)

Related Questions