@Override
	public Flux<ChatResponse> stream(Prompt prompt) {

		WatsonxAiRequest request = request(prompt);

		Flux<WatsonxAiResponse> response = this.watsonxAiApi.generateStreaming(request);

		return response.map(chunk -> {
			Generation generation = new Generation(chunk.results().get(0).generatedText());
			if (chunk.system() != null) {
				generation = generation.withGenerationMetadata(
						ChatGenerationMetadata.from(chunk.results().get(0).stopReason(), chunk.system()));
			}
			return new ChatResponse(List.of(generation));
		});
	}
@Test
	public void testStreamMethod() {
		WatsonxAiApi mockChatApi = mock(WatsonxAiApi.class);
		WatsonxAiChatModel chatModel = new WatsonxAiChatModel(mockChatApi);

		Prompt prompt = new Prompt(List.of(new SystemMessage("Your prompt here")),
				WatsonxAiChatOptions.builder().withModel("google/flan-ul2").build());

		WatsonxAiChatOptions parameters = WatsonxAiChatOptions.builder().withModel("google/flan-ul2").build();

		WatsonxAiResults fakeResultsFirst = new WatsonxAiResults("LLM resp", 0, 0, "max_tokens");
		WatsonxAiResults fakeResultsSecond = new WatsonxAiResults("onse", 4, 3, "not_finished");

		WatsonxAiResponse fakeResponseFirst = new WatsonxAiResponse("google/flan-ul2", new Date(),
				List.of(fakeResultsFirst),
				Map.of("warnings", List.of(Map.of("message", "the message", "id", "disclaimer_warning"))));
		WatsonxAiResponse fakeResponseSecond = new WatsonxAiResponse("google/flan-ul2", new Date(),
				List.of(fakeResultsSecond), null);

		Flux<WatsonxAiResponse> fakeResponse = Flux.just(fakeResponseFirst, fakeResponseSecond);
		when(mockChatApi.generateStreaming(any(WatsonxAiRequest.class))).thenReturn(fakeResponse);

		Generation firstGen = new Generation("LLM resp")
			.withGenerationMetadata(ChatGenerationMetadata.from("max_tokens",
					Map.of("warnings", List.of(Map.of("message", "the message", "id", "disclaimer_warning")))));
		Generation secondGen = new Generation("onse");

		Flux<ChatResponse> response = chatModel.stream(prompt);

		StepVerifier.create(response).assertNext(current -> {

			ChatResponse expected = new ChatResponse(List.of(firstGen));

			Assert.assertEquals(expected.getResults().size(), current.getResults().size());
			Assert.assertEquals(expected.getResult().getOutput(), current.getResult().getOutput());
		}).assertNext(current -> {
			ChatResponse expected = new ChatResponse(List.of(secondGen));

			Assert.assertEquals(expected.getResults().size(), current.getResults().size());
			Assert.assertEquals(expected.getResult().getOutput(), current.getResult().getOutput());
		}).expectComplete().verify();

	}