Remove deprecated PromptTemplate constructors · spring-projects/spring-ai@722c77e (original) (raw)
23 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -218,7 +218,7 @@ public void qaAdvisorTakesUserParameterizedUserMessagesIntoAccountForSimilarityS | ||
218 | 218 | var qaAdvisor = new QuestionAnswerAdvisor(this.vectorStore, SearchRequest.builder().build()); |
219 | 219 | |
220 | 220 | var userTextTemplate = "Please answer my question {question}"; |
221 | -var userPromptTemplate = new PromptTemplate(userTextTemplate, Map.of("question", "XYZ")); | |
221 | +var userPromptTemplate = PromptTemplate.builder().template(userTextTemplate).variables(Map.of("question", "XYZ")).build(); | |
222 | 222 | var userMessage = userPromptTemplate.createMessage(); |
223 | 223 | // @formatter:off |
224 | 224 | chatClient.prompt(new Prompt(userMessage)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -154,8 +154,10 @@ void listOutputConverter() { | ||
154 | 154 | List five {subject} |
155 | 155 | {format} |
156 | 156 | """; |
157 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
158 | -Map.of("subject", "ice cream flavors", "format", format)); | |
157 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
158 | + .template(template) | |
159 | + .variables(Map.of("subject", "ice cream flavors", "format", format)) | |
160 | + .build(); | |
159 | 161 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
160 | 162 | Generation generation = this.chatModel.call(prompt).getResult(); |
161 | 163 | |
@@ -172,8 +174,11 @@ void mapOutputConverter() { | ||
172 | 174 | Provide me a List of {subject} |
173 | 175 | {format} |
174 | 176 | """; |
175 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
176 | -Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); | |
177 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
178 | + .template(template) | |
179 | + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", | |
180 | +format)) | |
181 | + .build(); | |
177 | 182 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
178 | 183 | Generation generation = this.chatModel.call(prompt).getResult(); |
179 | 184 | |
@@ -192,7 +197,10 @@ void beanOutputConverterRecords() { | ||
192 | 197 | Generate the filmography of 5 movies for Tom Hanks. |
193 | 198 | {format} |
194 | 199 | """; |
195 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
200 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
201 | + .template(template) | |
202 | + .variables(Map.of("format", format)) | |
203 | + .build(); | |
196 | 204 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
197 | 205 | Generation generation = this.chatModel.call(prompt).getResult(); |
198 | 206 | |
@@ -212,7 +220,10 @@ void beanStreamOutputConverterRecords() { | ||
212 | 220 | Generate the filmography of 5 movies for Tom Hanks. |
213 | 221 | {format} |
214 | 222 | """; |
215 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
223 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
224 | + .template(template) | |
225 | + .variables(Map.of("format", format)) | |
226 | + .build(); | |
216 | 227 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
217 | 228 | |
218 | 229 | String generationTextFromStream = this.streamingChatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -137,8 +137,10 @@ void listOutputConverter() { | ||
137 | 137 | List five {subject} |
138 | 138 | {format} |
139 | 139 | """; |
140 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
141 | -Map.of("subject", "ice cream flavors", "format", format)); | |
140 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
141 | + .template(template) | |
142 | + .variables(Map.of("subject", "ice cream flavors", "format", format)) | |
143 | + .build(); | |
142 | 144 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
143 | 145 | Generation generation = this.chatModel.call(prompt).getResult(); |
144 | 146 | |
@@ -156,8 +158,11 @@ void mapOutputConverter() { | ||
156 | 158 | Provide me a List of {subject} |
157 | 159 | {format} |
158 | 160 | """; |
159 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
160 | -Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); | |
161 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
162 | + .template(template) | |
163 | + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", | |
164 | +format)) | |
165 | + .build(); | |
161 | 166 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
162 | 167 | Generation generation = this.chatModel.call(prompt).getResult(); |
163 | 168 | |
@@ -176,7 +181,10 @@ void beanOutputConverter() { | ||
176 | 181 | Generate the filmography for a random actor. |
177 | 182 | {format} |
178 | 183 | """; |
179 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
184 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
185 | + .template(template) | |
186 | + .variables(Map.of("format", format)) | |
187 | + .build(); | |
180 | 188 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
181 | 189 | Generation generation = this.chatModel.call(prompt).getResult(); |
182 | 190 | |
@@ -194,7 +202,10 @@ void beanOutputConverterRecords() { | ||
194 | 202 | Generate the filmography of 5 movies for Tom Hanks. |
195 | 203 | {format} |
196 | 204 | """; |
197 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
205 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
206 | + .template(template) | |
207 | + .variables(Map.of("format", format)) | |
208 | + .build(); | |
198 | 209 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
199 | 210 | Generation generation = this.chatModel.call(prompt).getResult(); |
200 | 211 | |
@@ -214,7 +225,10 @@ void beanStreamOutputConverterRecords() { | ||
214 | 225 | Generate the filmography of 5 movies for Tom Hanks. |
215 | 226 | {format} |
216 | 227 | """; |
217 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
228 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
229 | + .template(template) | |
230 | + .variables(Map.of("format", format)) | |
231 | + .build(); | |
218 | 232 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
219 | 233 | |
220 | 234 | String generationTextFromStream = this.chatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -152,8 +152,10 @@ void listOutputConverter() { | ||
152 | 152 | List five {subject} |
153 | 153 | {format} |
154 | 154 | """; |
155 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
156 | -Map.of("subject", "ice cream flavors", "format", format)); | |
155 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
156 | + .template(template) | |
157 | + .variables(Map.of("subject", "ice cream flavors", "format", format)) | |
158 | + .build(); | |
157 | 159 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
158 | 160 | Generation generation = this.chatModel.call(prompt).getResult(); |
159 | 161 | |
@@ -170,8 +172,11 @@ void mapOutputConverter() { | ||
170 | 172 | Provide me a List of {subject} |
171 | 173 | {format} |
172 | 174 | """; |
173 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
174 | -Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); | |
175 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
176 | + .template(template) | |
177 | + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", | |
178 | +format)) | |
179 | + .build(); | |
175 | 180 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
176 | 181 | Generation generation = this.chatModel.call(prompt).getResult(); |
177 | 182 | |
@@ -190,7 +195,10 @@ void beanOutputConverterRecords() { | ||
190 | 195 | Generate the filmography of 5 movies for Tom Hanks. |
191 | 196 | {format} |
192 | 197 | """; |
193 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
198 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
199 | + .template(template) | |
200 | + .variables(Map.of("format", format)) | |
201 | + .build(); | |
194 | 202 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
195 | 203 | Generation generation = this.chatModel.call(prompt).getResult(); |
196 | 204 | |
@@ -210,7 +218,10 @@ void beanStreamOutputConverterRecords() { | ||
210 | 218 | Generate the filmography of 5 movies for Tom Hanks. |
211 | 219 | {format} |
212 | 220 | """; |
213 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
221 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
222 | + .template(template) | |
223 | + .variables(Map.of("format", format)) | |
224 | + .build(); | |
214 | 225 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
215 | 226 | |
216 | 227 | String generationTextFromStream = this.streamingChatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -127,8 +127,10 @@ void listOutputConverter() { | ||
127 | 127 | List five {subject} |
128 | 128 | {format} |
129 | 129 | """; |
130 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
131 | -Map.of("subject", "ice cream flavors", "format", format)); | |
130 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
131 | + .template(template) | |
132 | + .variables(Map.of("subject", "ice cream flavors", "format", format)) | |
133 | + .build(); | |
132 | 134 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
133 | 135 | Generation generation = this.chatModel.call(prompt).getResult(); |
134 | 136 | |
@@ -145,8 +147,11 @@ void mapOutputConverter() { | ||
145 | 147 | Provide me a List of {subject} |
146 | 148 | {format} |
147 | 149 | """; |
148 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
149 | -Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", format)); | |
150 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
151 | + .template(template) | |
152 | + .variables(Map.of("subject", "an array of numbers from 1 to 9 under they key name 'numbers'", "format", | |
153 | +format)) | |
154 | + .build(); | |
150 | 155 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
151 | 156 | Generation generation = this.chatModel.call(prompt).getResult(); |
152 | 157 | |
@@ -165,7 +170,10 @@ void beanOutputConverterRecords() { | ||
165 | 170 | Generate the filmography of 5 movies for Tom Hanks. |
166 | 171 | {format} |
167 | 172 | """; |
168 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
173 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
174 | + .template(template) | |
175 | + .variables(Map.of("format", format)) | |
176 | + .build(); | |
169 | 177 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
170 | 178 | Generation generation = this.chatModel.call(prompt).getResult(); |
171 | 179 | |
@@ -185,7 +193,10 @@ void beanStreamOutputConverterRecords() { | ||
185 | 193 | Generate the filmography of 5 movies for Tom Hanks. |
186 | 194 | {format} |
187 | 195 | """; |
188 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
196 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
197 | + .template(template) | |
198 | + .variables(Map.of("format", format)) | |
199 | + .build(); | |
189 | 200 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
190 | 201 | |
191 | 202 | String generationTextFromStream = this.streamingChatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -163,8 +163,10 @@ void listOutputConverter() { | ||
163 | 163 | List five {subject} |
164 | 164 | {format} |
165 | 165 | """; |
166 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
167 | -Map.of("subject", "ice cream flavors.", "format", format)); | |
166 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
167 | + .template(template) | |
168 | + .variables(Map.of("subject", "ice cream flavors.", "format", format)) | |
169 | + .build(); | |
168 | 170 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
169 | 171 | Generation generation = this.chatModel.call(prompt).getResult(); |
170 | 172 | |
@@ -182,7 +184,10 @@ void mapOutputConvert() { | ||
182 | 184 | Example: R -> Red. |
183 | 185 | {format} |
184 | 186 | """; |
185 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
187 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
188 | + .template(template) | |
189 | + .variables(Map.of("format", format)) | |
190 | + .build(); | |
186 | 191 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
187 | 192 | |
188 | 193 | Generation generation = this.chatModel.call(prompt).getResult(); |
@@ -203,7 +208,10 @@ void beanOutputConverterRecords() { | ||
203 | 208 | Consider the filmography of Tom Hanks and tell me 5 of his movies. |
204 | 209 | {format} |
205 | 210 | """; |
206 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
211 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
212 | + .template(template) | |
213 | + .variables(Map.of("format", format)) | |
214 | + .build(); | |
207 | 215 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
208 | 216 | Generation generation = this.chatModel.call(prompt).getResult(); |
209 | 217 | |
@@ -221,7 +229,10 @@ void beanStreamOutputConverterRecords() { | ||
221 | 229 | Consider the filmography of Tom Hanks and tell me 5 of his movies. |
222 | 230 | {format} |
223 | 231 | """; |
224 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
232 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
233 | + .template(template) | |
234 | + .variables(Map.of("format", format)) | |
235 | + .build(); | |
225 | 236 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
226 | 237 | |
227 | 238 | String generationTextFromStream = this.chatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -246,8 +246,10 @@ void listOutputConverter() { | ||
246 | 246 | List five {subject} |
247 | 247 | {format} |
248 | 248 | """; |
249 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
250 | -Map.of("subject", "ice cream flavors", "format", format)); | |
249 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
250 | + .template(template) | |
251 | + .variables(Map.of("subject", "ice cream flavors", "format", format)) | |
252 | + .build(); | |
251 | 253 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
252 | 254 | Generation generation = this.chatModel.call(prompt).getResult(); |
253 | 255 | |
@@ -265,8 +267,10 @@ void mapOutputConverter() { | ||
265 | 267 | Provide me a List of {subject} |
266 | 268 | {format} |
267 | 269 | """; |
268 | -PromptTemplate promptTemplate = new PromptTemplate(template, | |
269 | -Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)); | |
270 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
271 | + .template(template) | |
272 | + .variables(Map.of("subject", "numbers from 1 to 9 under they key name 'numbers'", "format", format)) | |
273 | + .build(); | |
270 | 274 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
271 | 275 | Generation generation = this.chatModel.call(prompt).getResult(); |
272 | 276 | |
@@ -285,7 +289,10 @@ void beanOutputConverter() { | ||
285 | 289 | Generate the filmography for a random actor. |
286 | 290 | {format} |
287 | 291 | """; |
288 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
292 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
293 | + .template(template) | |
294 | + .variables(Map.of("format", format)) | |
295 | + .build(); | |
289 | 296 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
290 | 297 | Generation generation = this.chatModel.call(prompt).getResult(); |
291 | 298 | |
@@ -302,7 +309,10 @@ void beanOutputConverterRecords() { | ||
302 | 309 | Generate the filmography of 5 movies for Tom Hanks. |
303 | 310 | {format} |
304 | 311 | """; |
305 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
312 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
313 | + .template(template) | |
314 | + .variables(Map.of("format", format)) | |
315 | + .build(); | |
306 | 316 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
307 | 317 | Generation generation = this.chatModel.call(prompt).getResult(); |
308 | 318 | |
@@ -322,7 +332,10 @@ void beanStreamOutputConverterRecords() { | ||
322 | 332 | Generate the filmography of 5 movies for Tom Hanks. |
323 | 333 | {format} |
324 | 334 | """; |
325 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
335 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
336 | + .template(template) | |
337 | + .variables(Map.of("format", format)) | |
338 | + .build(); | |
326 | 339 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
327 | 340 | |
328 | 341 | String generationTextFromStream = this.streamingChatModel.stream(prompt) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -58,7 +58,10 @@ void typeRefOutputConverterRecords() { | ||
58 | 58 | Generate the filmography of 5 movies for Tom Hanks and Bill Murray. |
59 | 59 | {format} |
60 | 60 | """; |
61 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
61 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
62 | + .template(template) | |
63 | + .variables(Map.of("format", format)) | |
64 | + .build(); | |
62 | 65 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
63 | 66 | Generation generation = this.chatModel.call(prompt).getResult(); |
64 | 67 | |
@@ -84,7 +87,10 @@ void typeRefStreamOutputConverterRecords() { | ||
84 | 87 | Generate the filmography of 5 movies for Tom Hanks and Bill Murray. |
85 | 88 | {format} |
86 | 89 | """; |
87 | -PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format)); | |
90 | +PromptTemplate promptTemplate = PromptTemplate.builder() | |
91 | + .template(template) | |
92 | + .variables(Map.of("format", format)) | |
93 | + .build(); | |
88 | 94 | Prompt prompt = new Prompt(promptTemplate.createMessage()); |
89 | 95 | |
90 | 96 | String generationTextFromStream = this.streamingChatModel.stream(prompt) |