Skip to content

Commit 7bfe312

Browse files
committed
Convinence StreamingChatClient stream default
Add StreamingChatClient stream default that takes String and returns stream of String
1 parent 4fd15b1 commit 7bfe312

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

spring-ai-core/src/main/java/org/springframework/ai/chat/StreamingChatClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
@FunctionalInterface
2424
public interface StreamingChatClient extends StreamingModelClient<Prompt, ChatResponse> {
2525

26+
default Flux<String> stream(String message) {
27+
Prompt prompt = new Prompt(message);
28+
return stream(prompt).map(response -> (response.getResult() == null || response.getResult().getOutput() == null
29+
|| response.getResult().getOutput().getContent() == null) ? ""
30+
: response.getResult().getOutput().getContent());
31+
}
32+
2633
@Override
2734
Flux<ChatResponse> stream(Prompt prompt);
2835

0 commit comments

Comments
 (0)