All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.langchain4j.watsonx.prompt.impl.MistralPromptFormatter Maven / Gradle / Ivy

There is a newer version: 0.21.0
Show newest version
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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy