【同步】BOOT 和 CLOUD 的功能(BPM)
This commit is contained in:
@@ -112,6 +112,18 @@
|
||||
<groupId>dev.tinyflow</groupId>
|
||||
<artifactId>tinyflow-java-core</artifactId>
|
||||
<version>${tinyflow.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<!-- 解决 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1318/ 问题 -->
|
||||
<groupId>com.agentsflex</groupId>
|
||||
<artifactId>agents-flex-store-elasticsearch</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<!-- TODO @芋艿:暂时移除 groovy,和 iot 冲突 -->
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package cn.iocoder.yudao.framework.ai.mcp;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.core.model.doubao.DouBaoChatModel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.openai.OpenAiChatModel;
|
||||
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||
import org.springframework.ai.openai.api.OpenAiApi;
|
||||
import org.springframework.ai.tool.annotation.Tool;
|
||||
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
|
||||
|
||||
public class DouBaoMcpTests {
|
||||
|
||||
private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
|
||||
.openAiApi(OpenAiApi.builder()
|
||||
.baseUrl(DouBaoChatModel.BASE_URL)
|
||||
.apiKey("5c1b5747-26d2-4ebd-a4e0-dd0e8d8b4272") // apiKey
|
||||
.build())
|
||||
.defaultOptions(OpenAiChatOptions.builder()
|
||||
.model("doubao-1-5-lite-32k-250115") // 模型(doubao)
|
||||
.temperature(0.7)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
private final DouBaoChatModel chatModel = new DouBaoChatModel(openAiChatModel);
|
||||
|
||||
private final MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
|
||||
.toolObjects(new UserService())
|
||||
.build();
|
||||
|
||||
private final ChatClient chatClient = ChatClient.builder(chatModel)
|
||||
.defaultTools(provider)
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void testMcpGetUserInfo() {
|
||||
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("目前有哪些工具可以使用")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("小新的年龄是多少")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("获取小新的基本信息")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("小新是什么职业的")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("小新的教育背景")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
// 打印结果
|
||||
System.out.println(chatClient.prompt()
|
||||
.user("小新的兴趣爱好是什么")
|
||||
.call()
|
||||
.content());
|
||||
System.out.println("====================================");
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class UserService {
|
||||
|
||||
@Tool(name = "getUserAge", description = "获取用户年龄")
|
||||
public String getUserAge(String userName) {
|
||||
return "《" + userName + "》的年龄为:18";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserSex", description = "获取用户性别")
|
||||
public String getUserSex(String userName) {
|
||||
return "《" + userName + "》的性别为:男";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserBasicInfo", description = "获取用户基本信息,包括姓名、年龄、性别等")
|
||||
public String getUserBasicInfo(String userName) {
|
||||
return "《" + userName + "》的基本信息:\n姓名:" + userName + "\n年龄:18\n性别:男\n身高:175cm\n体重:65kg";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserContact", description = "获取用户联系方式,包括电话、邮箱等")
|
||||
public String getUserContact(String userName) {
|
||||
return "《" + userName + "》的联系方式:\n电话:138****1234\n邮箱:" + userName.toLowerCase() + "@example.com\nQQ:123456789";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserAddress", description = "获取用户地址信息")
|
||||
public String getUserAddress(String userName) {
|
||||
return "《" + userName + "》的地址信息:北京市朝阳区科技园区88号";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserJob", description = "获取用户职业信息")
|
||||
public String getUserJob(String userName) {
|
||||
return "《" + userName + "》的职业信息:软件工程师,就职于ABC科技有限公司,工作年限5年";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserHobbies", description = "获取用户兴趣爱好")
|
||||
public String getUserHobbies(String userName) {
|
||||
return "《" + userName + "》的兴趣爱好:编程、阅读、旅游、摄影、打篮球";
|
||||
}
|
||||
|
||||
@Tool(name = "getUserEducation", description = "获取用户教育背景")
|
||||
public String getUserEducation(String userName) {
|
||||
return "《" + userName + "》的教育背景:\n本科:计算机科学与技术专业,北京大学\n硕士:软件工程专业,清华大学";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.framework.ai.ppt.wdd;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api.WddPptApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.wenduoduo.api.WenDuoDuoPptApi;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,24 +10,23 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@link WddPptApi} 集成测试
|
||||
* {@link WenDuoDuoPptApi} 集成测试
|
||||
*
|
||||
* @author xiaoxin
|
||||
*/
|
||||
public class WddPptApiTests {
|
||||
|
||||
private final WddPptApi wddPptApi = new WddPptApi("https://docmee.cn");
|
||||
public class WenDuoDuoPptApiTests {
|
||||
|
||||
private final String token = ""; // API Token
|
||||
private final WenDuoDuoPptApi wenDuoDuoPptApi = new WenDuoDuoPptApi(token);
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testCreateApiToken() {
|
||||
// 准备参数
|
||||
String apiKey = "";
|
||||
WddPptApi.CreateTokenRequest request = new WddPptApi.CreateTokenRequest(apiKey);
|
||||
WenDuoDuoPptApi.CreateTokenRequest request = new WenDuoDuoPptApi.CreateTokenRequest(apiKey);
|
||||
// 调用方法
|
||||
String token = wddPptApi.createApiToken(request);
|
||||
String token = wenDuoDuoPptApi.createApiToken(request);
|
||||
// 打印结果
|
||||
System.out.println(token);
|
||||
}
|
||||
@@ -38,7 +37,7 @@ public class WddPptApiTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testCreateTask() {
|
||||
WddPptApi.ApiResponse apiResponse = wddPptApi.createTask(token, 1, "dify 介绍", null);
|
||||
WenDuoDuoPptApi.ApiResponse apiResponse = wenDuoDuoPptApi.createTask(1, "dify 介绍", null);
|
||||
System.out.println(apiResponse);
|
||||
}
|
||||
|
||||
@@ -46,10 +45,10 @@ public class WddPptApiTests {
|
||||
@Test // 创建大纲
|
||||
@Disabled
|
||||
public void testGenerateOutlineRequest() {
|
||||
WddPptApi.CreateOutlineRequest request = new WddPptApi.CreateOutlineRequest(
|
||||
WenDuoDuoPptApi.CreateOutlineRequest request = new WenDuoDuoPptApi.CreateOutlineRequest(
|
||||
"1901539019628613632", "medium", null, null, null, null);
|
||||
// 调用
|
||||
Flux<Map<String, Object>> flux = wddPptApi.createOutline(token, request);
|
||||
Flux<Map<String, Object>> flux = wenDuoDuoPptApi.createOutline(request);
|
||||
StringBuffer contentBuffer = new StringBuffer();
|
||||
flux.doOnNext(chunk -> {
|
||||
contentBuffer.append(chunk.get("text"));
|
||||
@@ -69,10 +68,10 @@ public class WddPptApiTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testUpdateOutlineRequest() {
|
||||
WddPptApi.UpdateOutlineRequest request = new WddPptApi.UpdateOutlineRequest(
|
||||
WenDuoDuoPptApi.UpdateOutlineRequest request = new WenDuoDuoPptApi.UpdateOutlineRequest(
|
||||
"1901539019628613632", TEST_OUT_LINE_CONTENT, "精简一点,三个章节即可");
|
||||
// 调用
|
||||
Flux<Map<String, Object>> flux = wddPptApi.updateOutline(token, request);
|
||||
Flux<Map<String, Object>> flux = wenDuoDuoPptApi.updateOutline(request);
|
||||
StringBuffer contentBuffer = new StringBuffer();
|
||||
flux.doOnNext(chunk -> {
|
||||
contentBuffer.append(chunk.get("text"));
|
||||
@@ -94,11 +93,11 @@ public class WddPptApiTests {
|
||||
@Disabled
|
||||
public void testGetPptTemplatePage() {
|
||||
// 准备参数
|
||||
WddPptApi.TemplateQueryRequest.Filter filter = new WddPptApi.TemplateQueryRequest.Filter(
|
||||
WenDuoDuoPptApi.TemplateQueryRequest.Filter filter = new WenDuoDuoPptApi.TemplateQueryRequest.Filter(
|
||||
1, null, null, null);
|
||||
WddPptApi.TemplateQueryRequest request = new WddPptApi.TemplateQueryRequest(1, 10, filter);
|
||||
WenDuoDuoPptApi.TemplateQueryRequest request = new WenDuoDuoPptApi.TemplateQueryRequest(1, 10, filter);
|
||||
// 调用
|
||||
WddPptApi.PagePptTemplateInfo pptTemplatePage = wddPptApi.getTemplatePage(token, request);
|
||||
WenDuoDuoPptApi.PagePptTemplateInfo pptTemplatePage = wenDuoDuoPptApi.getTemplatePage(request);
|
||||
// 打印结果
|
||||
System.out.println(pptTemplatePage);
|
||||
}
|
||||
@@ -110,9 +109,9 @@ public class WddPptApiTests {
|
||||
@Disabled
|
||||
public void testGeneratePptx() {
|
||||
// 准备参数
|
||||
WddPptApi.CreatePptRequest request = new WddPptApi.CreatePptRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT);
|
||||
WenDuoDuoPptApi.PptCreateRequest request = new WenDuoDuoPptApi.PptCreateRequest("1901539019628613632", "1805081814809960448", TEST_OUT_LINE_CONTENT);
|
||||
// 调用
|
||||
WddPptApi.PptInfo pptInfo = wddPptApi.create(token, request);
|
||||
WenDuoDuoPptApi.PptInfo pptInfo = wenDuoDuoPptApi.create(request);
|
||||
// 打印结果
|
||||
System.out.println(pptInfo);
|
||||
}
|
||||
@@ -309,6 +308,7 @@ public class WddPptApiTests {
|
||||
#### 7.2.2 合作共赢
|
||||
期待与更多的企业和机构合作,共同推动AI技术的应用。
|
||||
#### 7.2.3 共创未来
|
||||
让我们一起用AI技术改变世界,共创美好未来。""";
|
||||
让我们一起用AI技术改变世界,共创美好未来。
|
||||
""";
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.framework.ai.ppt.xunfei;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunfeiPptApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.api.XunFeiPptApi;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -11,17 +11,17 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* {@link XunfeiPptApi} 集成测试
|
||||
* {@link XunFeiPptApi} 集成测试
|
||||
*
|
||||
* @author xiaoxin
|
||||
*/
|
||||
public class XunfeiPptApiTests {
|
||||
public class XunFeiPptApiTests {
|
||||
|
||||
// 讯飞 API 配置信息,实际使用时请替换为您的应用信息
|
||||
private static final String APP_ID = "";
|
||||
private static final String API_SECRET = "";
|
||||
private static final String APP_ID = "6c8ac023";
|
||||
private static final String API_SECRET = "Y2RjM2Q1MWJjZTdkYmFiODc0OGE5NmRk";
|
||||
|
||||
private final XunfeiPptApi xunfeiPptApi = new XunfeiPptApi(XunfeiPptApi.BASE_URL, APP_ID, API_SECRET);
|
||||
private final XunFeiPptApi xunfeiPptApi = new XunFeiPptApi(APP_ID, API_SECRET);
|
||||
|
||||
/**
|
||||
* 获取 PPT 模板列表
|
||||
@@ -30,7 +30,7 @@ public class XunfeiPptApiTests {
|
||||
@Disabled
|
||||
public void testGetTemplatePage() {
|
||||
// 调用方法
|
||||
XunfeiPptApi.TemplatePageResponse response = xunfeiPptApi.getTemplatePage("商务", 10);
|
||||
XunFeiPptApi.TemplatePageResponse response = xunfeiPptApi.getTemplatePage("商务", 10);
|
||||
// 打印结果
|
||||
System.out.println("模板列表响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -41,7 +41,7 @@ public class XunfeiPptApiTests {
|
||||
|
||||
// 打印第一个模板的信息(如果存在)
|
||||
if (!response.data().records().isEmpty()) {
|
||||
XunfeiPptApi.TemplateInfo firstTemplate = response.data().records().get(0);
|
||||
XunFeiPptApi.TemplateInfo firstTemplate = response.data().records().get(0);
|
||||
System.out.println("模板ID:" + firstTemplate.templateIndexId());
|
||||
System.out.println("模板风格:" + firstTemplate.style());
|
||||
System.out.println("模板颜色:" + firstTemplate.color());
|
||||
@@ -56,7 +56,7 @@ public class XunfeiPptApiTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testCreateOutline() {
|
||||
XunfeiPptApi.CreateResponse response = getCreateResponse();
|
||||
XunFeiPptApi.CreateResponse response = getCreateResponse();
|
||||
// 打印结果
|
||||
System.out.println("创建大纲响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -75,9 +75,10 @@ public class XunfeiPptApiTests {
|
||||
|
||||
/**
|
||||
* 创建大纲(通过文本)
|
||||
*
|
||||
* @return 创建大纲响应
|
||||
*/
|
||||
private XunfeiPptApi.CreateResponse getCreateResponse() {
|
||||
private XunFeiPptApi.CreateResponse getCreateResponse() {
|
||||
String param = "智能体平台 Dify 介绍";
|
||||
return xunfeiPptApi.createOutline(param);
|
||||
}
|
||||
@@ -89,9 +90,9 @@ public class XunfeiPptApiTests {
|
||||
@Disabled
|
||||
public void testCreatePptByOutlineWithFullParams() {
|
||||
// 创建大纲对象
|
||||
XunfeiPptApi.CreateResponse createResponse = getCreateResponse();
|
||||
XunFeiPptApi.CreateResponse createResponse = getCreateResponse();
|
||||
// 调用方法
|
||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节");
|
||||
XunFeiPptApi.CreateResponse response = xunfeiPptApi.createPptByOutline(createResponse.data().outline(), "精简一些,不要超过6个章节");
|
||||
// 打印结果
|
||||
System.out.println("通过大纲创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -114,13 +115,13 @@ public class XunfeiPptApiTests {
|
||||
String sid = "e96dac09f2ec4ee289f029a5fb874ecd"; // 替换为实际的sid
|
||||
|
||||
// 调用方法
|
||||
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||
XunFeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||
// 打印结果
|
||||
System.out.println("检查进度响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
// 安全地访问响应数据
|
||||
if (response != null && response.data() != null) {
|
||||
XunfeiPptApi.ProgressResponseData data = response.data();
|
||||
XunFeiPptApi.ProgressResponseData data = response.data();
|
||||
|
||||
// 打印PPT生成状态
|
||||
System.out.println("PPT 构建状态: " + data.pptStatus());
|
||||
@@ -160,7 +161,7 @@ public class XunfeiPptApiTests {
|
||||
@Disabled
|
||||
public void testPollCheckProgress() throws InterruptedException {
|
||||
// 准备参数 - 使用之前创建 PP T时返回的 sid
|
||||
String sid = "fa36e926f2ed434987fcb4c1f0776ffb"; // 替换为实际的sid
|
||||
String sid = "1690ef6ee0344e72b5c5434f403b8eaa"; // 替换为实际的sid
|
||||
|
||||
// 最大轮询次数
|
||||
int maxPolls = 20;
|
||||
@@ -171,11 +172,11 @@ public class XunfeiPptApiTests {
|
||||
System.out.println("第" + (i + 1) + "次查询进度...");
|
||||
|
||||
// 调用方法
|
||||
XunfeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||
XunFeiPptApi.ProgressResponse response = xunfeiPptApi.checkProgress(sid);
|
||||
|
||||
// 安全地访问响应数据
|
||||
if (response != null && response.data() != null) {
|
||||
XunfeiPptApi.ProgressResponseData data = response.data();
|
||||
XunFeiPptApi.ProgressResponseData data = response.data();
|
||||
|
||||
// 打印进度信息
|
||||
System.out.println("PPT 构建状态: " + data.pptStatus());
|
||||
@@ -218,7 +219,7 @@ public class XunfeiPptApiTests {
|
||||
String query = "合肥天气趋势分析,包括近5年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
||||
|
||||
// 调用方法
|
||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(query);
|
||||
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(query);
|
||||
// 打印结果
|
||||
System.out.println("直接创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -244,7 +245,7 @@ public class XunfeiPptApiTests {
|
||||
MultipartFile multipartFile = convertFileToMultipartFile(file);
|
||||
|
||||
// 调用方法
|
||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(multipartFile, file.getName());
|
||||
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(multipartFile, file.getName());
|
||||
// 打印结果
|
||||
System.out.println("通过文件创建PPT响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -269,7 +270,7 @@ public class XunfeiPptApiTests {
|
||||
String query = "合肥天气趋势分析,包括近 5 年的气温变化、降水量变化、极端天气事件,以及对城市生活的影响";
|
||||
|
||||
// 创建请求对象
|
||||
XunfeiPptApi.CreatePptRequest request = XunfeiPptApi.CreatePptRequest.builder()
|
||||
XunFeiPptApi.CreatePptRequest request = XunFeiPptApi.CreatePptRequest.builder()
|
||||
.query(query)
|
||||
.language("cn")
|
||||
.isCardNote(true)
|
||||
@@ -280,7 +281,7 @@ public class XunfeiPptApiTests {
|
||||
.build();
|
||||
|
||||
// 调用方法
|
||||
XunfeiPptApi.CreateResponse response = xunfeiPptApi.create(request);
|
||||
XunFeiPptApi.CreateResponse response = xunfeiPptApi.create(request);
|
||||
// 打印结果
|
||||
System.out.println("使用完整参数创建 PPT 响应:" + JsonUtils.toJsonString(response));
|
||||
|
||||
@@ -296,9 +297,9 @@ public class XunfeiPptApiTests {
|
||||
|
||||
// 立即查询一次进度
|
||||
System.out.println("立即查询进度...");
|
||||
XunfeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid);
|
||||
XunFeiPptApi.ProgressResponse progressResponse = xunfeiPptApi.checkProgress(sid);
|
||||
if (progressResponse != null && progressResponse.data() != null) {
|
||||
XunfeiPptApi.ProgressResponseData progressData = progressResponse.data();
|
||||
XunFeiPptApi.ProgressResponseData progressData = progressResponse.data();
|
||||
System.out.println("PPT 构建状态: " + progressData.pptStatus());
|
||||
if (progressData.totalPages() != null && progressData.donePages() != null) {
|
||||
System.out.println("完成进度: " + progressData.donePages() + "/" + progressData.totalPages()
|
||||
Reference in New Issue
Block a user