From 236393ef5d391e98ab97ff868d0e6f719bcf98dd Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Fri, 18 Aug 2023 01:23:15 -0400 Subject: [PATCH] PromptTemplates can create messages --- .../ai/prompt/SystemPromptTemplate.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/prompt/SystemPromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/prompt/SystemPromptTemplate.java index bfc4f4e859..dd06afaf2c 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/prompt/SystemPromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/prompt/SystemPromptTemplate.java @@ -16,9 +16,15 @@ package org.springframework.ai.prompt; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; import java.util.Map; import org.springframework.ai.prompt.messages.SystemMessage; +import org.springframework.core.io.Resource; +import org.springframework.util.StreamUtils; +import org.stringtemplate.v4.ST; public class SystemPromptTemplate extends PromptTemplate { @@ -26,6 +32,14 @@ public SystemPromptTemplate(String template) { super(template); } + public SystemPromptTemplate(Resource resource) { + super(resource); + } + + public SystemMessage createMessage(Map model) { + return new SystemMessage(render(model)); + } + @Override public Prompt create() { return new Prompt(new SystemMessage(render()));