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

com.dingtalk.baymax.framework.sdk.mercury.util.BaseMessageUtils Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.dingtalk.baymax.framework.sdk.mercury.util;

import com.dingtalk.baymax.framework.sdk.mercury.domain.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiaoyan.wjw
 * @Date 2023-05-22 15:56:31
 */
public class BaseMessageUtils {

    public static String getBufferString(List messages, String humanPrefix, String aiPrefix) {
        List stringMessages = new ArrayList<>();
        for (BaseMessage m : messages) {
            String role;
            if (m instanceof HumanMessage) {
                role = humanPrefix;
            } else if (m instanceof AIMessage) {
                role = aiPrefix;
            } else if (m instanceof SystemMessage) {
                role = "System";
            } else if (m instanceof ChatMessage) {
                role = ((ChatMessage) m).getRole();
            } else {
                throw new IllegalArgumentException("Got unsupported message type: " + m);
            }
            stringMessages.add(role + ": " + m.getContent());
        }
        return String.join("\n", stringMessages);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy