|
16 | 16 | import com.google.protobuf.Value; |
17 | 17 | import com.microsoft.semantickernel.Kernel; |
18 | 18 | import com.microsoft.semantickernel.aiservices.google.GeminiService; |
| 19 | +import com.microsoft.semantickernel.aiservices.google.GeminiServiceBuilder; |
19 | 20 | import com.microsoft.semantickernel.aiservices.google.implementation.MonoConverter; |
20 | 21 | import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; |
21 | 22 | import com.microsoft.semantickernel.exceptions.AIException; |
|
36 | 37 | import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; |
37 | 38 | import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; |
38 | 39 | import com.microsoft.semantickernel.services.chatcompletion.ChatMessageContent; |
39 | | -import com.microsoft.semantickernel.aiservices.google.GeminiServiceBuilder; |
| 40 | +import com.microsoft.semantickernel.services.chatcompletion.StreamingChatContent; |
40 | 41 | import java.io.IOException; |
41 | 42 | import java.time.OffsetDateTime; |
42 | 43 | import java.util.ArrayList; |
43 | 44 | import java.util.List; |
44 | 45 | import java.util.UUID; |
45 | 46 | import java.util.stream.Collectors; |
46 | 47 | import javax.annotation.Nullable; |
47 | | -import com.microsoft.semantickernel.services.chatcompletion.StreamingChatContent; |
48 | 48 | import org.slf4j.Logger; |
49 | 49 | import org.slf4j.LoggerFactory; |
50 | 50 | import reactor.core.publisher.Flux; |
@@ -78,17 +78,49 @@ public Mono<List<ChatMessageContent<?>>> getChatMessageContentsAsync(String prom |
78 | 78 |
|
79 | 79 | @Override |
80 | 80 | public Flux<StreamingChatContent<?>> getStreamingChatMessageContentsAsync( |
81 | | - ChatHistory chatHistory, @Nullable Kernel kernel, |
| 81 | + ChatHistory chatHistory, |
| 82 | + @Nullable Kernel kernel, |
82 | 83 | @Nullable InvocationContext invocationContext) { |
83 | | - throw new UnsupportedOperationException( |
84 | | - "Streaming chat message contents are not supported"); |
| 84 | + |
| 85 | + LOGGER.warn("Streaming has been called on GeminiChatCompletion service. " |
| 86 | + + "This is currently not supported in Gemini. " |
| 87 | + + "The results will be returned in a non streaming fashion."); |
| 88 | + |
| 89 | + return getChatMessageContentsAsync(chatHistory, kernel, invocationContext) |
| 90 | + .flatMapIterable(chatMessageContents -> chatMessageContents) |
| 91 | + .map(content -> { |
| 92 | + return new GeminiStreamingChatMessageContent( |
| 93 | + content.getAuthorRole(), |
| 94 | + content.getContent(), |
| 95 | + getModelId(), |
| 96 | + content.getInnerContent(), |
| 97 | + content.getEncoding(), |
| 98 | + content.getMetadata(), |
| 99 | + null, |
| 100 | + UUID.randomUUID().toString()); |
| 101 | + }); |
85 | 102 | } |
86 | 103 |
|
87 | 104 | @Override |
88 | 105 | public Flux<StreamingChatContent<?>> getStreamingChatMessageContentsAsync(String prompt, |
89 | 106 | @Nullable Kernel kernel, @Nullable InvocationContext invocationContext) { |
90 | | - throw new UnsupportedOperationException( |
91 | | - "Streaming chat message contents are not supported"); |
| 107 | + LOGGER.warn("Streaming has been called on GeminiChatCompletion service. " |
| 108 | + + "This is currently not supported in Gemini. " |
| 109 | + + "The results will be returned in a non streaming fashion."); |
| 110 | + |
| 111 | + return getChatMessageContentsAsync(prompt, kernel, invocationContext) |
| 112 | + .flatMapIterable(chatMessageContents -> chatMessageContents) |
| 113 | + .map(content -> { |
| 114 | + return new GeminiStreamingChatMessageContent( |
| 115 | + content.getAuthorRole(), |
| 116 | + content.getContent(), |
| 117 | + getModelId(), |
| 118 | + content.getInnerContent(), |
| 119 | + content.getEncoding(), |
| 120 | + content.getMetadata(), |
| 121 | + null, |
| 122 | + UUID.randomUUID().toString()); |
| 123 | + }); |
92 | 124 | } |
93 | 125 |
|
94 | 126 | @Override |
|
0 commit comments