admin
2025-06-06 9cd825aea53fa5ba0cda1485464af027e27f0ce4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package tech.aiflowy.ai.entity;
 
import com.agentsflex.llm.deepseek.DeepseekConfig;
import com.agentsflex.llm.deepseek.DeepseekLlm;
import tech.aiflowy.ai.entity.base.AiLlmBase;
import tech.aiflowy.common.util.PropertiesUtil;
import tech.aiflowy.common.util.StringUtil;
import com.agentsflex.core.llm.Llm;
import com.agentsflex.llm.gitee.GiteeAiLlm;
import com.agentsflex.llm.gitee.GiteeAiLlmConfig;
import com.agentsflex.llm.ollama.OllamaLlm;
import com.agentsflex.llm.ollama.OllamaLlmConfig;
import com.agentsflex.llm.openai.OpenAILlm;
import com.agentsflex.llm.openai.OpenAILlmConfig;
import com.agentsflex.llm.qwen.QwenLlm;
import com.agentsflex.llm.qwen.QwenLlmConfig;
import com.agentsflex.llm.spark.SparkLlm;
import com.agentsflex.llm.spark.SparkLlmConfig;
import com.mybatisflex.annotation.Table;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
 
/**
 * 实体类。
 *
 * @author michael
 * @since 2024-08-23
 */
 
@Table("tb_ai_llm")
public class AiLlm extends AiLlmBase {
 
    public List<String> getSupportFeatures() {
        List<String> features = new ArrayList<>();
        if (getSupportChat() != null && getSupportChat()) {
            features.add("对话");
        }
 
        if (getSupportFunctionCalling() != null && getSupportFunctionCalling()) {
            features.add("方法调用");
        }
 
        if (getSupportEmbed() != null && getSupportEmbed()) {
            features.add("Embedding");
        }
 
        if (getSupportReranker() != null && getSupportReranker()) {
            features.add("重排");
        }
 
        if (getSupportTextToImage() != null && getSupportTextToImage()) {
            features.add("文生图");
        }
 
        if (getSupportImageToImage() != null && getSupportImageToImage()) {
            features.add("图生图");
        }
 
        if (getSupportTextToAudio() != null && getSupportTextToAudio()) {
            features.add("文生音频");
        }
 
        if (getSupportAudioToAudio() != null && getSupportAudioToAudio()) {
            features.add("音频转音频");
        }
 
        if (getSupportTextToVideo() != null && getSupportTextToVideo()) {
            features.add("文生视频");
        }
 
        if (getSupportImageToVideo() != null && getSupportImageToVideo()) {
            features.add("图生视频");
        }
        return features;
    }
 
    public Llm toLlm() {
        String brand = getBrand();
        if (StringUtil.noText(brand)) {
            return null;
        }
        switch (brand.toLowerCase()) {
            case "openai":
                return openaiLLm();
            case "spark":
                return sparkLlm();
            case "ollama":
                return ollamaLlm();
            case "qwen":
            case "aliyun":
                return qwenLlm();
            case "gitee":
                return giteeLlm();
            case "deepseek":
                return deepseekLlm();
            default:
                return null;
        }
    }
 
    private Llm giteeLlm() {
        GiteeAiLlmConfig giteeAiLlmConfig = new GiteeAiLlmConfig();
        giteeAiLlmConfig.setEndpoint(getLlmEndpoint());
        giteeAiLlmConfig.setApiKey(getLlmApiKey());
        giteeAiLlmConfig.setModel(getLlmModel());
        return new GiteeAiLlm(giteeAiLlmConfig);
    }
 
    private Llm qwenLlm() {
        QwenLlmConfig qwenLlmConfig = new QwenLlmConfig();
        qwenLlmConfig.setEndpoint(getLlmEndpoint());
        qwenLlmConfig.setApiKey(getLlmApiKey());
        qwenLlmConfig.setModel(getLlmModel());
        return new QwenLlm(qwenLlmConfig);
    }
 
    private Llm ollamaLlm() {
        OllamaLlmConfig ollamaLlmConfig = new OllamaLlmConfig();
        ollamaLlmConfig.setEndpoint(getLlmEndpoint());
        ollamaLlmConfig.setApiKey(getLlmApiKey());
        ollamaLlmConfig.setModel(getLlmModel());
        return new OllamaLlm(ollamaLlmConfig);
    }
 
    private Llm openaiLLm() {
        OpenAILlmConfig openAiLlmConfig = new OpenAILlmConfig();
        openAiLlmConfig.setEndpoint(getLlmEndpoint());
        openAiLlmConfig.setApiKey(getLlmApiKey());
        openAiLlmConfig.setModel(getLlmModel());
        openAiLlmConfig.setDefaultEmbeddingModel(getLlmModel());
        String llmExtraConfig = getLlmExtraConfig();
        if (llmExtraConfig != null && !llmExtraConfig.isEmpty()){
            Properties prop = PropertiesUtil.textToProperties(llmExtraConfig);
            String chatPath = prop.getProperty("chatPath");
            String embedPath = prop.getProperty("embedPath");
            if (chatPath != null && !chatPath.isEmpty()) {
                openAiLlmConfig.setChatPath(chatPath);
            }
            if (embedPath != null && !embedPath.isEmpty()) {
                openAiLlmConfig.setEmbedPath(embedPath);
            }
        }
        return new OpenAILlm(openAiLlmConfig);
    }
 
    private Llm sparkLlm() {
        SparkLlmConfig sparkLlmConfig = PropertiesUtil.propertiesTextToEntity(getLlmExtraConfig(), SparkLlmConfig.class);
        sparkLlmConfig.setApiKey(getLlmApiKey());
        return new SparkLlm(sparkLlmConfig);
    }
 
    private Llm deepseekLlm() {
        DeepseekConfig config = new DeepseekConfig();
        config.setModel(getLlmModel());
        config.setEndpoint(getLlmEndpoint());
        config.setApiKey(getLlmApiKey());
        return new DeepseekLlm(config);
    }
}