Convinence StreamingChatClient stream default

Add StreamingChatClient stream default that takes String and returns stream of String
This commit is contained in:
Christian Tzolov
2024-03-12 16:58:33 +01:00
parent 4fd15b11c5
commit 7bfe312157

View File

@@ -23,6 +23,13 @@ import org.springframework.ai.model.StreamingModelClient;
@FunctionalInterface
public interface StreamingChatClient extends StreamingModelClient<Prompt, ChatResponse> {
default Flux<String> stream(String message) {
Prompt prompt = new Prompt(message);
return stream(prompt).map(response -> (response.getResult() == null || response.getResult().getOutput() == null
|| response.getResult().getOutput().getContent() == null) ? ""
: response.getResult().getOutput().getContent());
}
@Override
Flux<ChatResponse> stream(Prompt prompt);