io.quarkiverse.langchain4j.watsonx.prompt.impl.MistralPromptFormatter Maven / Gradle / Ivy
package io.quarkiverse.langchain4j.watsonx.prompt.impl;
import java.util.List;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.ChatMessage;
import io.quarkiverse.langchain4j.watsonx.prompt.PromptFormatter;
/**
* Mistral prompt formatter.
*/
public class MistralPromptFormatter implements PromptFormatter {
@Override
public String joiner() {
return "";
}
@Override
public String start() {
return "";
}
@Override
public String system() {
return "[INST] ";
}
@Override
public String user() {
return "[INST] ";
}
@Override
public String assistant() {
return "";
}
@Override
public String endOf(ChatMessage chatMessage) {
return switch (chatMessage.type()) {
case AI -> "";
case SYSTEM -> " [/INST]";
case USER -> " [/INST]";
case TOOL_EXECUTION_RESULT -> "";
};
}
@Override
public String format(List messages, List tools) {
return """
%s\
%s\
%s\
""".formatted(start(), systemMessageFormatter(messages), messagesFormatter(messages));
}
}