Skip to content

Commit 9588711

Browse files
committed
Use chained constructors instead.
1 parent 13e7f18 commit 9588711

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

spring-ai-core/src/main/java/org/springframework/ai/chat/prompt/PromptTemplate.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,28 @@ public class PromptTemplate implements PromptTemplateActions, PromptTemplateMess
4949
private Map<String, Object> dynamicModel = new HashMap<>();
5050

5151
public PromptTemplate(Resource resource) {
52+
this(resource, Collections.emptyMap());
53+
}
54+
55+
public PromptTemplate(Resource resource, Map<String, Object> model) {
5256
try (InputStream inputStream = resource.getInputStream()) {
5357
this.template = StreamUtils.copyToString(inputStream, Charset.defaultCharset());
5458
}
5559
catch (IOException ex) {
5660
throw new RuntimeException("Failed to read resource", ex);
5761
}
58-
initST(this.template, Collections.emptyMap());
62+
initST(this.template, model);
5963
}
6064

6165
public PromptTemplate(String template) {
62-
this.template = template;
63-
initST(this.template, Collections.emptyMap());
66+
this(template, Collections.emptyMap());
6467
}
6568

6669
public PromptTemplate(String template, Map<String, Object> model) {
6770
this.template = template;
6871
initST(this.template, model);
6972
}
7073

71-
public PromptTemplate(Resource resource, Map<String, Object> model) {
72-
try (InputStream inputStream = resource.getInputStream()) {
73-
this.template = StreamUtils.copyToString(inputStream, Charset.defaultCharset());
74-
}
75-
catch (IOException ex) {
76-
throw new RuntimeException("Failed to read resource", ex);
77-
}
78-
initST(this.template, model);
79-
}
80-
8174
private void initST(String template, Map<String, Object> model) {
8275
// If the template string is not valid, an exception will be thrown
8376
try {

0 commit comments

Comments
 (0)