Class GPTChatMessagesTemplate
- java.lang.Object
-
- com.composum.ai.backend.base.service.chat.impl.GPTChatMessagesTemplate
-
public class GPTChatMessagesTemplate extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
MESSAGE_SEPARATOR
matches the lines like ---------- system ---------- that separate the individual messages in the templatestatic String
PLACEHOLDER_MARKER
If that's in a string, it likely contains placeholders.static Pattern
PLACEHOLDER_PATTERN
static String
TEMPLATEDIR
static String
TEMPLATESUFFIX
-
Constructor Summary
Constructors Constructor Description GPTChatMessagesTemplate(InputStream stream, String name)
GPTChatMessagesTemplate(ClassLoader classLoader, String name)
GPTChatMessagesTemplate(org.osgi.framework.Bundle bundle, String templateName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static InputStream
getGetTemplateStreamFromBundle(org.osgi.framework.Bundle bundle, String templateName)
protected static InputStream
getGetTemplateStreamFromClassloader(ClassLoader classLoader, String name)
protected static List<List<String>>
getMessageLineBlocks(Iterator<String> lineiterator)
split the lines into blocks of lines where the first line is matching MESSAGE_SEPARATORList<GPTChatMessage>
getMessages(Map<String,String> placeholderValues)
Returns a list of messages with the placeholders replaced.protected void
processBlocks(List<List<String>> blocks)
-
-
-
Field Detail
-
TEMPLATEDIR
public static final String TEMPLATEDIR
- See Also:
- Constant Field Values
-
TEMPLATESUFFIX
public static final String TEMPLATESUFFIX
- See Also:
- Constant Field Values
-
MESSAGE_SEPARATOR
public static final Pattern MESSAGE_SEPARATOR
matches the lines like ---------- system ---------- that separate the individual messages in the template
-
PLACEHOLDER_MARKER
public static final String PLACEHOLDER_MARKER
If that's in a string, it likely contains placeholders.- See Also:
- Constant Field Values
-
PLACEHOLDER_PATTERN
public static final Pattern PLACEHOLDER_PATTERN
-
-
Constructor Detail
-
GPTChatMessagesTemplate
public GPTChatMessagesTemplate(InputStream stream, @Nonnull String name) throws GPTException
- Throws:
GPTException
-
GPTChatMessagesTemplate
public GPTChatMessagesTemplate(@Nullable ClassLoader classLoader, @Nonnull String name) throws GPTException
- Throws:
GPTException
-
GPTChatMessagesTemplate
public GPTChatMessagesTemplate(@Nonnull org.osgi.framework.Bundle bundle, @Nonnull String templateName) throws GPTException
- Throws:
GPTException
-
-
Method Detail
-
getGetTemplateStreamFromClassloader
protected static InputStream getGetTemplateStreamFromClassloader(@Nullable ClassLoader classLoader, @Nonnull String name)
-
getGetTemplateStreamFromBundle
protected static InputStream getGetTemplateStreamFromBundle(org.osgi.framework.Bundle bundle, String templateName)
-
getMessageLineBlocks
protected static List<List<String>> getMessageLineBlocks(Iterator<String> lineiterator)
split the lines into blocks of lines where the first line is matching MESSAGE_SEPARATOR
-
getMessages
public List<GPTChatMessage> getMessages(Map<String,String> placeholderValues)
Returns a list of messages with the placeholders replaced. If a placeholder is missing, we throw an error, as this is a misusage of the template.
-
-