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

com.dingtalk.baymax.framework.sdk.mercury.model.BaseLanguageModel Maven / Gradle / Ivy

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

import com.dingtalk.baymax.framework.sdk.mercury.annotation.StreamFunction;
import com.dingtalk.baymax.framework.sdk.mercury.domain.BaseMessage;
import com.dingtalk.baymax.framework.sdk.mercury.domain.BaseModel;
import com.dingtalk.baymax.framework.sdk.mercury.model.nl2x.Nl2x;
import com.dingtalk.baymax.framework.sdk.mercury.prompt.PromptValue;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * 语言模型基类
 *
 * @author xiaoxuan.lp
 */
public abstract class BaseLanguageModel extends BaseModel implements Nl2x {
    /**
     * 获取提示值列表并返回LLMResult
     *
     * @param prompts
     * @param stops
     * @return
     */
    public abstract LLMResult generatePrompt(List prompts, List stops);

    /**
     * 流式获取提示值列表
     *
     * @param prompts
     * @param stops
     * @return
     */
    @StreamFunction
    public abstract void generatePrompt(List prompts, List stops, StreamObserver streamObserver);

    /**
     * 获取提示值列表并返回LLMResult
     *
     * @param prompts
     * @param stops
     * @return
     */
    public abstract CompletableFuture generatePromptAsync(List prompts, List stops);

    /**
     * 从文本预测文本
     *
     * @param text 文本
     * @return
     */
    public abstract String predict(String text);

    /**
     * 从文本预测文本
     *
     * @param text 文本
     * @param stops 停止字符串
     * @return
     */
    public abstract String predict(String text, List stops);

    /**
     * 从文本预测文本
     * 异步化方法
     *
     * @param text 文本
     * @return
     */
    public abstract CompletableFuture predictAsync(String text);

    /**
     * 从文本预测文本
     * 异步化方法
     * @param text 文本
     * @return
     */
    public abstract CompletableFuture predictAsync(String text, List stops);

    /**
     * 从BaseMessage预测BaseMessage
     *
     * @param messages
     * @return
     */
    public abstract BaseMessage predictMessage(List messages);

    /**
     * 从BaseMessage预测BaseMessage
     *
     * @param messages
     * @param stops
     * @return
     */
    public abstract BaseMessage predictMessage(List messages, List stops);


    @Override
    public String nl2rawStr(String userInput, Map context) {
        return predict(userInput);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy