初始化

This commit is contained in:
2026-02-22 18:55:40 +08:00
commit 8392cdd861
496 changed files with 45020 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2023-2026, Easy-Agents (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.easyagents.llm.deepseek;
import com.easyagents.core.model.chat.OpenAICompatibleChatModel;
import com.easyagents.core.model.chat.ChatInterceptor;
import com.easyagents.core.model.chat.GlobalChatInterceptors;
import java.util.List;
/**
* @author huangjf
* @version : v1.0
*/
public class DeepseekChatModel extends OpenAICompatibleChatModel<DeepseekConfig> {
/**
* 构造一个聊天模型实例,不使用实例级拦截器。
*
* @param config 聊天模型配置
*/
public DeepseekChatModel(DeepseekConfig config) {
super(config);
}
/**
* 构造一个聊天模型实例,并指定实例级拦截器。
* <p>
* 实例级拦截器会与全局拦截器(通过 {@link GlobalChatInterceptors} 注册)合并,
* 执行顺序为:可观测性拦截器 → 全局拦截器 → 实例拦截器。
*
* @param config 聊天模型配置
* @param userInterceptors 实例级拦截器列表
*/
public DeepseekChatModel(DeepseekConfig config, List<ChatInterceptor> userInterceptors) {
super(config, userInterceptors);
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023-2026, Easy-Agents (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.easyagents.llm.deepseek;
import com.easyagents.core.model.chat.ChatConfig;
/**
* @author huangjf
* @version : v1.0
*/
public class DeepseekConfig extends ChatConfig {
private static final String DEFAULT_MODEL = "deepseek-chat";
private static final String DEFAULT_ENDPOINT = "https://api.deepseek.com";
private static final String DEFAULT_REQUEST_PATH = "/chat/completions";
public DeepseekConfig() {
setEndpoint(DEFAULT_ENDPOINT);
setRequestPath(DEFAULT_REQUEST_PATH);
setModel(DEFAULT_MODEL);
}
}

View File

@@ -0,0 +1,92 @@
package com.easyagents.llm.deepseek;
import com.easyagents.core.message.UserMessage;
import com.easyagents.core.model.client.StreamContext;
import com.easyagents.core.model.chat.ChatModel;
import com.easyagents.core.model.chat.StreamResponseListener;
import com.easyagents.core.model.chat.tool.annotation.ToolDef;
import com.easyagents.core.model.chat.tool.annotation.ToolParam;
import com.easyagents.core.model.chat.response.AiMessageResponse;
import com.easyagents.core.message.SystemMessage;
import com.easyagents.core.prompt.MemoryPrompt;
import com.easyagents.core.prompt.SimplePrompt;
import com.easyagents.core.util.StringUtil;
import java.util.Scanner;
public class DeepseekTest {
@ToolDef(name = "get_the_weather_info", description = "get the weather info")
public static String getWeatherInfo(@ToolParam(name = "city", description = "城市名称") String name) {
//在这里,我们应该通过第三方接口调用 api 信息
return name + "的天气是阴转多云。 ";
}
@ToolDef(name = "get_holiday_balance", description = "获取假期余额")
public static String getHolidayBalance() {
//在这里,我们应该通过第三方接口调用 api 信息
String username = "michael";
return username + "你的年假还剩余3天有效期至26年1月。调休假剩余1天长期有效。 ";
}
public static ChatModel getLLM() {
DeepseekConfig deepseekConfig = new DeepseekConfig();
deepseekConfig.setEndpoint("https://api.siliconflow.cn/v1");
deepseekConfig.setApiKey("*********************");
deepseekConfig.setModel("Pro/deepseek-ai/DeepSeek-V3");
deepseekConfig.setLogEnabled(true);
return new DeepseekChatModel(deepseekConfig);
}
public static void chatHr() {
ChatModel chatModel = getLLM();
MemoryPrompt prompt = new MemoryPrompt();
// 加入system
prompt.addMessage(new SystemMessage("你是一个人事助手小智,专注于为用户提供高效、精准的信息查询和问题解答服务。"));
System.out.println("我是小智,你的人事小助手!请尽情吩咐小智!");
Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine();
while (userInput != null) {
// 第二步:创建 HumanMessage并添加方法调用
UserMessage userMessage = new UserMessage(userInput);
userMessage.addToolsFromClass(DeepseekTest.class);
// 第三步:将 HumanMessage 添加到 HistoriesPrompt 中
prompt.addMessage(userMessage);
// 第四步:调用 chatStream 方法,进行对话
chatModel.chatStream(prompt, new StreamResponseListener() {
@Override
public void onMessage(StreamContext context, AiMessageResponse response) {
if (StringUtil.hasText(response.getMessage().getContent())) {
System.out.print(response.getMessage().getContent());
}
if (response.getMessage().isFinalDelta()) {
System.out.println(response);
System.out.println("------");
}
}
@Override
public void onStop(StreamContext context) {
System.out.println("stop!!!------");
}
});
userInput = scanner.nextLine();
}
}
public static void functionCall() {
ChatModel chatModel = getLLM();
SimplePrompt prompt = new SimplePrompt("今天北京的天气怎么样");
prompt.addToolsFromClass(DeepseekTest.class);
AiMessageResponse response = chatModel.chat(prompt);
System.out.println(response.executeToolCallsAndGetResults());
}
public static void main(String[] args) {
// functionCall();
chatHr();
}
}