重命名 tool-calls to tools.enabled

This commit is contained in:
thinkgem
2025-10-19 13:20:06 +08:00
parent 5dfb735186
commit afcce5db7b
2 changed files with 41 additions and 28 deletions

View File

@@ -1,15 +1,22 @@
package com.jeesite.modules.cms.ai.properties;
package com.jeesite.modules.ai.cms.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
@ConfigurationProperties("spring.ai")
public class CmsAiProperties {
public class AiCmsProperties {
/**
* 是否启用 Tool calling 工具调用
* 向量数据库设置
*/
private Boolean toolCalls = false;
@NestedConfigurationProperty
private final Vectorstore vectorstore = new Vectorstore();
/**
* 是否启用 Tool calling 工具调用例子详见 TestAiTools.javaUserAiTools.java
*/
@NestedConfigurationProperty
private final Tools tools = new Tools();
/**
* 默认系统提示词
@@ -21,18 +28,12 @@ public class CmsAiProperties {
*/
private String defaultPromptTemplate = "";
/**
* 向量数据库设置
*/
@NestedConfigurationProperty
private final Vectorstore vectorstore = new Vectorstore();
public Boolean getToolCalls() {
return toolCalls;
public Vectorstore getVectorstore() {
return vectorstore;
}
public void setToolCalls(Boolean toolCalls) {
this.toolCalls = toolCalls;
public Tools getTools() {
return tools;
}
public String getDefaultSystem() {
@@ -51,10 +52,6 @@ public class CmsAiProperties {
this.defaultPromptTemplate = defaultPromptTemplate;
}
public Vectorstore getVectorstore() {
return vectorstore;
}
public static class Vectorstore {
/**
@@ -70,4 +67,20 @@ public class CmsAiProperties {
this.type = type;
}
}
public static class Tools {
/**
* 是否启用 Tool calling 工具调用例子详见 TestAiTools.javaUserAiTools.java
*/
private Boolean enabled = false;
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
}
}

View File

@@ -6,7 +6,7 @@ package com.jeesite.test;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.cms.ai.service.CmsAiChatService;
import com.jeesite.modules.ai.cms.service.AiCmsChatService;
import com.jeesite.modules.sys.entity.Area;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -26,20 +26,20 @@ import java.util.Map;
@ActiveProfiles("test")
@SpringBootApplication
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SpringBootTest(properties = {"spring.ai.tool-calls=true"})
@SpringBootTest(properties = {"spring.ai.tools.enabled=true"})
public class AiChatServiceTest extends BaseSpringContextTests {
private final CmsAiChatService cmsAiChatService;
private final AiCmsChatService aiCmsChatService;
public AiChatServiceTest(CmsAiChatService cmsAiChatService) {
this.cmsAiChatService = cmsAiChatService;
public AiChatServiceTest(AiCmsChatService aiCmsChatService) {
this.aiCmsChatService = aiCmsChatService;
}
@Test
public void test01Text() {
logger.info("===== 聊天对话,文本输出");
String message = "你好";
String text = cmsAiChatService.chatText(message);
String text = aiCmsChatService.chatText(message);
System.out.println(text);
}
@@ -47,7 +47,7 @@ public class AiChatServiceTest extends BaseSpringContextTests {
public void test02Json() {
logger.info("===== 聊天对话,结构化输出 JSON");
String message = "张三";
Map<String, Object> map = cmsAiChatService.chatJson(message);
Map<String, Object> map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
}
@@ -55,10 +55,10 @@ public class AiChatServiceTest extends BaseSpringContextTests {
public void test03Tool() {
logger.info("===== 聊天对话,结构化输出 Tool Calling");
String message = "打开客厅的灯";
Map<String, Object> map = cmsAiChatService.chatJson(message);
Map<String, Object> map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
message = "关闭客厅的灯";
map = cmsAiChatService.chatJson(message);
map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
}
@@ -66,7 +66,7 @@ public class AiChatServiceTest extends BaseSpringContextTests {
public void test04Entity() {
logger.info("===== 聊天对话,结构化输出 Entity");
String message = "北京";
List<Area> list = cmsAiChatService.chatArea(message);
List<Area> list = aiCmsChatService.chatArea(message);
System.out.println(JsonMapper.toJson(list));
}