package org.tutorial.yy.langchain.service;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.model.qianfan.QianfanChatModel;
import dev.langchain4j.model.qianfan.QianfanStreamingChatModel;

import static dev.langchain4j.model.openai.OpenAiChatModelName.GPT_3_5_TURBO;
import static java.time.Duration.ofSeconds;

/**
 * @author yyHuangfu
 * @create 2024/1/29
 * @description
 */
public class LangModel {

    public static ChatLanguageModel getModel(String modelName) {
        switch (modelName) {
            case "qian_fan":
                return getQianFanModel();
            case "open_ai":
                return getOpenAIModel();
            default:
                throw new RuntimeException("unKnown model name, plz check your config");
        }
    }

    private static ChatLanguageModel getOpenAIModel() {
        return OpenAiChatModel.builder()
                .apiKey(ApiKeys.OPENAI_API_KEY)
                .modelName(GPT_3_5_TURBO)
                .temperature(0.6)
                .timeout(ofSeconds(60))
                .logRequests(true)
                .logResponses(true)
                .build();
    }

    public static QianfanStreamingChatModel getStreamModel() {
        return QianfanStreamingChatModel.builder()
                .apiKey("bUyk2k96KQ2gG1ZQ8TB8t3cd")
                .secretKey(ApiKeys.QIAN_FAN_API_KEY)
                .modelName("Yi-34B-Chat")
                .build();
    }

    private static QianfanChatModel getQianFanModel() {
        return QianfanChatModel.builder()
                .apiKey("bUyk2k96KQ2gG1ZQ8TB8t3cd")
                .secretKey(ApiKeys.QIAN_FAN_API_KEY)
                .modelName("Yi-34B-Chat")
                .build();
    }
}

dev.langchain4j.model.qianfan.QianfanChatModel.builder dev.langchain4j.model.openai.OpenAiChatModel.builder dev.langchain4j.model.qianfan.QianfanStreamingChatModel.builder
[((979, 1264), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1239), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1203), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1168), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1128), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1094), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((979, 1052), 'dev.langchain4j.model.openai.OpenAiChatModel.builder'), ((1351, 1558), 'dev.langchain4j.model.qianfan.QianfanStreamingChatModel.builder'), ((1351, 1533), 'dev.langchain4j.model.qianfan.QianfanStreamingChatModel.builder'), ((1351, 1491), 'dev.langchain4j.model.qianfan.QianfanStreamingChatModel.builder'), ((1351, 1438), 'dev.langchain4j.model.qianfan.QianfanStreamingChatModel.builder'), ((1638, 1836), 'dev.langchain4j.model.qianfan.QianfanChatModel.builder'), ((1638, 1811), 'dev.langchain4j.model.qianfan.QianfanChatModel.builder'), ((1638, 1769), 'dev.langchain4j.model.qianfan.QianfanChatModel.builder'), ((1638, 1716), 'dev.langchain4j.model.qianfan.QianfanChatModel.builder')]