# 多模型适配

AIP与多个厂家大模型适配方式,以下为调用示例。

# 回答方式

使用Deepseekp大模型,响应式回答:

import com.agentsflex.core.llm.Llm
import com.agentsflex.core.message.AiMessage
import com.agentsflex.llm.deepseek.DeepseekLlm
import com.agentsflex.llm.deepseek.DeepseekLlmConfig

def config = new DeepseekLlmConfig(
    endpoint: "https://dashscope.aliyuncs.com/compatible-mode/v1",  // 自定义地址(默认为官网地址)
    apiKey: secretKey?.qwen_key,
    model: "deepseek-v3"
)

Llm llm = new DeepseekLlm(config)

println "思考中......"

def message = expertService.clearMessage(taskInfo.getText())

def output = agentFlexLLM.chatComponent(llm , message)

return output

使用Deepseekp大模型,流式回答:

import com.agentsflex.core.llm.Llm
import com.agentsflex.core.message.AiMessage
import com.agentsflex.llm.deepseek.DeepseekLlm
import com.agentsflex.llm.deepseek.DeepseekLlmConfig

def config = new DeepseekLlmConfig(
    apiKey: secretKey?.qwen_key,
    model: "deepseek-r1"
)

Llm llm = new DeepseekLlm(config)

def output = "思考中....."
def prompt = expertService.clearMessage(taskInfo.getText())

agentFlexLLM.processStream(llm , role , prompt , taskInfo)

return output

# 多模型适配

以下接入有豆包、deepseek、通义千问、科大讯飞等多个厂家大模型。

接入方式:

使用 OpenAi 大语言模型:

 @Test
public void testChat() {
    OpenAiLlmConfig config = new OpenAiLlmConfig();
    config.setApiKey("sk-rts5NF6n*******");

    Llm llm = new OpenAiLlm(config);
    String response = llm.chat("请问你叫什么名字");

    System.out.println(response);
}

使用 “通义千问” 大语言模型:

@Test
public void testChat() {
    QwenLlmConfig config = new QwenLlmConfig();
    config.setApiKey("sk-28a6be3236****");
    config.setModel("qwen-turbo");

    Llm llm = new QwenLlm(config);
    String response = llm.chat("请问你叫什么名字");

    System.out.println(response);
}

使用 “讯飞星火” 大语言模型:

@Test
public void testChat() {
    SparkLlmConfig config = new SparkLlmConfig();
    config.setAppId("****");
    config.setApiKey("****");
    config.setApiSecret("****");

    Llm llm = new SparkLlm(config);
    String response = llm.chat("请问你叫什么名字");

    System.out.println(response);
}

# 鸣谢

Last Updated: 2/11/2025, 7:49:38 AM