2424import com .google .cloud .vertexai .api .Candidate .FinishReason ;
2525import com .google .cloud .vertexai .api .Content ;
2626import com .google .cloud .vertexai .api .GenerateContentResponse ;
27- import com .google .cloud .vertexai .api .GenerationConfig ;
28- import com .google .cloud .vertexai .api .SafetySetting ;
2927import java .io .IOException ;
3028import java .util .ArrayList ;
3129import java .util .Collections ;
@@ -55,7 +53,7 @@ public ChatSession(GenerativeModel model) {
5553 */
5654 @ BetaApi
5755 public ResponseStream <GenerateContentResponse > sendMessageStream (String text ) throws IOException {
58- return sendMessageStream (text , null , null );
56+ return sendMessageStream (text , GenerateContentConfig . newBuilder (). build () );
5957 }
6058
6159 /**
@@ -73,64 +71,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
7371 return sendMessageStream (ContentMaker .fromString (text ), config );
7472 }
7573
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-
13474 /**
13575 * Sends a message to the model and returns a stream of responses.
13676 *
@@ -141,7 +81,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
14181 @ BetaApi
14282 public ResponseStream <GenerateContentResponse > sendMessageStream (Content content )
14383 throws IOException , IllegalArgumentException {
144- return sendMessageStream (content , null , null );
84+ return sendMessageStream (content , GenerateContentConfig . newBuilder (). build () );
14585 }
14686
14787 /**
@@ -165,65 +105,6 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
165105 return respStream ;
166106 }
167107
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-
227108 /**
228109 * Sends a message to the model and returns a response.
229110 *
@@ -232,7 +113,7 @@ public ResponseStream<GenerateContentResponse> sendMessageStream(
232113 */
233114 @ BetaApi
234115 public GenerateContentResponse sendMessage (String text ) throws IOException {
235- return sendMessage (text , null , null );
116+ return sendMessage (text , GenerateContentConfig . newBuilder (). build () );
236117 }
237118
238119 /**
@@ -249,60 +130,6 @@ public GenerateContentResponse sendMessage(String text, GenerateContentConfig co
249130 return sendMessage (ContentMaker .fromString (text ), config );
250131 }
251132
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-
306133 /**
307134 * Sends a message to the model and returns a response.
308135 *
@@ -311,7 +138,7 @@ public GenerateContentResponse sendMessage(
311138 */
312139 @ BetaApi
313140 public GenerateContentResponse sendMessage (Content content ) throws IOException {
314- return sendMessage (content , null , null );
141+ return sendMessage (content , GenerateContentConfig . newBuilder (). build () );
315142 }
316143
317144 /**
@@ -333,59 +160,6 @@ public GenerateContentResponse sendMessage(Content content, GenerateContentConfi
333160 return response ;
334161 }
335162
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-
389163 private void removeLastContent () {
390164 int lastIndex = history .size () - 1 ;
391165 history .remove (lastIndex );
0 commit comments