24
24
import com .google .cloud .vertexai .api .Candidate .FinishReason ;
25
25
import com .google .cloud .vertexai .api .Content ;
26
26
import com .google .cloud .vertexai .api .GenerateContentResponse ;
27
- import com .google .cloud .vertexai .api .GenerationConfig ;
28
- import com .google .cloud .vertexai .api .SafetySetting ;
29
27
import java .io .IOException ;
30
28
import java .util .ArrayList ;
31
29
import java .util .Collections ;
@@ -55,7 +53,7 @@ public ChatSession(GenerativeModel model) {
55
53
*/
56
54
@ BetaApi
57
55
public ResponseStream <GenerateContentResponse > sendMessageStream (String text ) throws IOException {
58
- return sendMessageStream (text , null , null );
56
+ return sendMessageStream (text , GenerateContentConfig . newBuilder (). build () );
59
57
}
60
58
61
59
/**
@@ -73,64 +71,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
73
71
return sendMessageStream (ContentMaker .fromString (text ), config );
74
72
}
75
73
76
- /**
77
- * Sends a message to the model and returns a stream of responses.
78
- *
79
- * @param text the message to be sent.
80
- * @param generationConfig the generation config.
81
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
82
- * stream by stream() method.
83
- * @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
84
- */
85
- @ BetaApi
86
- @ Deprecated
87
- public ResponseStream <GenerateContentResponse > sendMessageStream (
88
- String text , GenerationConfig generationConfig ) throws IOException {
89
- return sendMessageStream (text , generationConfig , null );
90
- }
91
-
92
- /**
93
- * Sends a message to the model and returns a stream of responses.
94
- *
95
- * @param text the message to be sent.
96
- * @param safetySettings the safety settings.
97
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
98
- * stream by stream() method.
99
- * @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
100
- */
101
- @ BetaApi ("safetySettings is a preview feature." )
102
- @ Deprecated
103
- public ResponseStream <GenerateContentResponse > sendMessageStream (
104
- String text , List <SafetySetting > safetySettings ) throws IOException {
105
- return sendMessageStream (text , null , safetySettings );
106
- }
107
-
108
- /**
109
- * Sends a message to the model and returns a stream of responses.
110
- *
111
- * @param text the message to be sent.
112
- * @param generationConfig the generation config.
113
- * @param safetySettings the safety settings.
114
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
115
- * stream by stream() method.
116
- * @deprecated use {@link #sendMessageStream(String, GenerateContentConfig)} instead
117
- */
118
- @ BetaApi ("safetySettings is a preview feature." )
119
- @ Deprecated
120
- public ResponseStream <GenerateContentResponse > sendMessageStream (
121
- String text , GenerationConfig generationConfig , List <SafetySetting > safetySettings )
122
- throws IOException {
123
- checkLastResponseAndEditHistory ();
124
-
125
- history .add (ContentMaker .fromString (text ));
126
-
127
- ResponseStream <GenerateContentResponse > respStream =
128
- model .generateContentStream (history , generationConfig , safetySettings );
129
- currentResponseStream = respStream ;
130
- currentResponse = null ;
131
- return respStream ;
132
- }
133
-
134
74
/**
135
75
* Sends a message to the model and returns a stream of responses.
136
76
*
@@ -141,7 +81,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
141
81
@ BetaApi
142
82
public ResponseStream <GenerateContentResponse > sendMessageStream (Content content )
143
83
throws IOException , IllegalArgumentException {
144
- return sendMessageStream (content , null , null );
84
+ return sendMessageStream (content , GenerateContentConfig . newBuilder (). build () );
145
85
}
146
86
147
87
/**
@@ -165,65 +105,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
165
105
return respStream ;
166
106
}
167
107
168
- /**
169
- * Sends a message to the model and returns a stream of responses.
170
- *
171
- * @param content the content to be sent.
172
- * @param generationConfig the generation config.
173
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
174
- * stream by stream() method.
175
- * @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
176
- */
177
- @ BetaApi
178
- @ Deprecated
179
- public ResponseStream <GenerateContentResponse > sendMessageStream (
180
- Content content , GenerationConfig generationConfig )
181
- throws IOException , IllegalArgumentException {
182
- return sendMessageStream (content , generationConfig , null );
183
- }
184
-
185
- /**
186
- * Sends a message to the model and returns a stream of responses.
187
- *
188
- * @param content the content to be sent.
189
- * @param safetySettings the safety settings.
190
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
191
- * stream by stream() method.
192
- * @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
193
- */
194
- @ BetaApi ("safetySettings is a preview feature." )
195
- @ Deprecated
196
- public ResponseStream <GenerateContentResponse > sendMessageStream (
197
- Content content , List <SafetySetting > safetySettings )
198
- throws IOException , IllegalArgumentException {
199
- return sendMessageStream (content , null , safetySettings );
200
- }
201
-
202
- /**
203
- * Sends a message to the model and returns a stream of responses.
204
- *
205
- * @param content the content to be sent.
206
- * @param generationConfig the generation config.
207
- * @param safetySettings the safety settings.
208
- * @return an iterable in which each element is a GenerateContentResponse. Can be converted to
209
- * stream by stream() method.
210
- * @deprecated use {@link #sendMessageStream(Content, GenerateContentConfig)} instead
211
- */
212
- @ BetaApi ("safetySettings is a preview feature." )
213
- @ Deprecated
214
- public ResponseStream <GenerateContentResponse > sendMessageStream (
215
- Content content , GenerationConfig generationConfig , List <SafetySetting > safetySettings )
216
- throws IOException {
217
- checkLastResponseAndEditHistory ();
218
-
219
- history .add (content );
220
- ResponseStream <GenerateContentResponse > respStream =
221
- model .generateContentStream (history , generationConfig , safetySettings );
222
- currentResponseStream = respStream ;
223
- currentResponse = null ;
224
- return respStream ;
225
- }
226
-
227
108
/**
228
109
* Sends a message to the model and returns a response.
229
110
*
@@ -232,7 +113,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
232
113
*/
233
114
@ BetaApi
234
115
public GenerateContentResponse sendMessage (String text ) throws IOException {
235
- return sendMessage (text , null , null );
116
+ return sendMessage (text , GenerateContentConfig . newBuilder (). build () );
236
117
}
237
118
238
119
/**
@@ -249,60 +130,6 @@ public GenerateContentResponse sendMessage(String text, GenerateContentConfig co
249
130
return sendMessage (ContentMaker .fromString (text ), config );
250
131
}
251
132
252
- /**
253
- * Sends a message to the model and returns a response.
254
- *
255
- * @param text the message to be sent.
256
- * @param generationConfig the generation config.
257
- * @return a response.
258
- * @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
259
- */
260
- @ BetaApi
261
- @ Deprecated
262
- public GenerateContentResponse sendMessage (String text , GenerationConfig generationConfig )
263
- throws IOException {
264
- return sendMessage (text , generationConfig , null );
265
- }
266
-
267
- /**
268
- * Sends a message to the model and returns a response.
269
- *
270
- * @param text the message to be sent.
271
- * @param safetySettings the safety settings.
272
- * @return a response.
273
- * @deprecated use {@link #sendMessage(String, GenerateContentConfig)} instead
274
- */
275
- @ BetaApi ("safetySettings is a preview feature." )
276
- @ Deprecated
277
- public GenerateContentResponse sendMessage (String text , List <SafetySetting > safetySettings )
278
- throws IOException {
279
- return sendMessage (text , null , safetySettings );
280
- }
281
-
282
- /**
283
- * Sends a message to the model and returns a response.
284
- *
285
- * @param text the message to be sent.
286
- * @param generationConfig the generation config.
287
- * @param safetySettings the safety settings.
288
- * @return a response.
289
- * @deprecated use {@link #sendMessage(String, GenerateContentConfig)} instead
290
- */
291
- @ BetaApi ("Both sendMessage and safetySettings are preview features." )
292
- @ Deprecated
293
- public GenerateContentResponse sendMessage (
294
- String text , GenerationConfig generationConfig , List <SafetySetting > safetySettings )
295
- throws IOException {
296
-
297
- checkLastResponseAndEditHistory ();
298
- history .add (ContentMaker .fromString (text ));
299
- GenerateContentResponse response =
300
- model .generateContent (history , generationConfig , safetySettings );
301
- currentResponse = response ;
302
- currentResponseStream = null ;
303
- return response ;
304
- }
305
-
306
133
/**
307
134
* Sends a message to the model and returns a response.
308
135
*
@@ -311,7 +138,7 @@ public GenerateContentResponse sendMessage(
311
138
*/
312
139
@ BetaApi
313
140
public GenerateContentResponse sendMessage (Content content ) throws IOException {
314
- return sendMessage (content , null , null );
141
+ return sendMessage (content , GenerateContentConfig . newBuilder (). build () );
315
142
}
316
143
317
144
/**
@@ -333,59 +160,6 @@ public GenerateContentResponse sendMessage(Content content, GenerateContentConfi
333
160
return response ;
334
161
}
335
162
336
- /**
337
- * Sends a message to the model and returns a response.
338
- *
339
- * @param content the content to be sent.
340
- * @param generationConfig the generation config.
341
- * @return a response.
342
- * @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
343
- */
344
- @ BetaApi
345
- @ Deprecated
346
- public GenerateContentResponse sendMessage (Content content , GenerationConfig generationConfig )
347
- throws IOException {
348
- return sendMessage (content , generationConfig , null );
349
- }
350
-
351
- /**
352
- * Sends a message to the model and returns a response.
353
- *
354
- * @param content the content to be sent.
355
- * @param safetySettings the safety settings.
356
- * @return a response.
357
- * @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
358
- */
359
- @ BetaApi ("Both sendMessage and safetySettings are preview features." )
360
- @ Deprecated
361
- public GenerateContentResponse sendMessage (Content content , List <SafetySetting > safetySettings )
362
- throws IOException {
363
- return sendMessage (content , null , safetySettings );
364
- }
365
-
366
- /**
367
- * Sends a message to the model and returns a response.
368
- *
369
- * @param content the content to be sent.
370
- * @param generationConfig the generation config.
371
- * @param safetySettings the safety settings.
372
- * @return a response.
373
- * @deprecated use {@link #sendMessage(Content, GenerateContentConfig)} instead
374
- */
375
- @ BetaApi ("Both sendMessage and safetySettings are preview features." )
376
- @ Deprecated
377
- public GenerateContentResponse sendMessage (
378
- Content content , GenerationConfig generationConfig , List <SafetySetting > safetySettings )
379
- throws IOException {
380
- checkLastResponseAndEditHistory ();
381
- history .add (content );
382
- GenerateContentResponse response =
383
- model .generateContent (history , generationConfig , safetySettings );
384
- currentResponse = response ;
385
- currentResponseStream = null ;
386
- return response ;
387
- }
388
-
389
163
private void removeLastContent () {
390
164
int lastIndex = history .size () - 1 ;
391
165
history .remove (lastIndex );
0 commit comments