@@ -58,6 +58,21 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(String text) th
58
58
return sendMessageStream (text , null , null );
59
59
}
60
60
61
+ /**
62
+ * Sends a message to the model and returns a stream of responses.
63
+ *
64
+ * @param text the message to be sent.
65
+ * @param config a {@link GenerateContentConfig} that contains all the configs for sending message
66
+ * in a chat session.
67
+ * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
68
+ * stream by stream() method.
69
+ */
70
+ @ BetaApi
71
+ public ResponseStream <GenerateContentResponse > sendMessageStream (
72
+ String text , GenerateContentConfig config ) throws IOException {
73
+ return sendMessageStream (ContentMaker .fromString (text ), config );
74
+ }
75
+
61
76
/**
62
77
* Sends a message to the model and returns a stream of responses.
63
78
*
@@ -123,6 +138,27 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(Content content
123
138
return sendMessageStream (content , null , null );
124
139
}
125
140
141
+ /**
142
+ * Sends a message to the model and returns a stream of responses.
143
+ *
144
+ * @param content the content to be sent.
145
+ * @param config a {@link GenerateContentConfig} that contains all the configs for sending message
146
+ * in a chat session.
147
+ * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
148
+ * stream by stream() method.
149
+ */
150
+ @ BetaApi
151
+ public ResponseStream <GenerateContentResponse > sendMessageStream (
152
+ Content content , GenerateContentConfig config ) throws IOException {
153
+ checkLastResponseAndEditHistory ();
154
+ history .add (content );
155
+ ResponseStream <GenerateContentResponse > respStream =
156
+ model .generateContentStream (history , config );
157
+ currentResponseStream = respStream ;
158
+ currentResponse = null ;
159
+ return respStream ;
160
+ }
161
+
126
162
/**
127
163
* Sends a message to the model and returns a stream of responses.
128
164
*
@@ -187,6 +223,20 @@ public GenerateContentResponse sendMessage(String text) throws IOException {
187
223
return sendMessage (text , null , null );
188
224
}
189
225
226
+ /**
227
+ * Sends a message to the model and returns a response.
228
+ *
229
+ * @param text the message to be sent.
230
+ * @param config a {@link GenerateContentConfig} that contains all the configs for sending message
231
+ * in a chat session.
232
+ * @return a response.
233
+ */
234
+ @ BetaApi
235
+ public GenerateContentResponse sendMessage (String text , GenerateContentConfig config )
236
+ throws IOException {
237
+ return sendMessage (ContentMaker .fromString (text ), config );
238
+ }
239
+
190
240
/**
191
241
* Sends a message to the model and returns a response.
192
242
*
@@ -246,6 +296,25 @@ public GenerateContentResponse sendMessage(Content content) throws IOException {
246
296
return sendMessage (content , null , null );
247
297
}
248
298
299
+ /**
300
+ * Sends a message to the model and returns a response.
301
+ *
302
+ * @param content the content to be sent.
303
+ * @param config a {@link GenerateContentConfig} that contains all the configs for sending message
304
+ * in a chat session.
305
+ * @return a response.
306
+ */
307
+ @ BetaApi
308
+ public GenerateContentResponse sendMessage (Content content , GenerateContentConfig config )
309
+ throws IOException {
310
+ checkLastResponseAndEditHistory ();
311
+ history .add (content );
312
+ GenerateContentResponse response = model .generateContent (history , config );
313
+ currentResponse = response ;
314
+ currentResponseStream = null ;
315
+ return response ;
316
+ }
317
+
249
318
/**
250
319
* Sends a message to the model and returns a response.
251
320
*
@@ -303,7 +372,7 @@ private void removeLastContent() {
303
372
*
304
373
* @throws IllegalStateException if the response stream is not finished.
305
374
*/
306
- private void checkLastResponseAndEditHistory () throws IllegalStateException {
375
+ private void checkLastResponseAndEditHistory () {
307
376
if (currentResponseStream == null && currentResponse == null ) {
308
377
return ;
309
378
} else if (currentResponseStream != null && !currentResponseStream .isConsumed ()) {
0 commit comments