重命名 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

@@ -0,0 +1,86 @@
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 AiCmsProperties {
/**
* 向量数据库设置
*/
@NestedConfigurationProperty
private final Vectorstore vectorstore = new Vectorstore();
/**
* 是否启用 Tool calling 工具调用【例子详见 TestAiTools.java、UserAiTools.java 】
*/
@NestedConfigurationProperty
private final Tools tools = new Tools();
/**
* 默认系统提示词
*/
private String defaultSystem = "";
/**
* 默认问题模板格式
*/
private String defaultPromptTemplate = "";
public Vectorstore getVectorstore() {
return vectorstore;
}
public Tools getTools() {
return tools;
}
public String getDefaultSystem() {
return defaultSystem;
}
public void setDefaultSystem(String defaultSystem) {
this.defaultSystem = defaultSystem;
}
public String getDefaultPromptTemplate() {
return defaultPromptTemplate;
}
public void setDefaultPromptTemplate(String defaultPromptTemplate) {
this.defaultPromptTemplate = defaultPromptTemplate;
}
public static class Vectorstore {
/**
* 向量库类型选择chroma、pgvector、elasticsearch、milvus
*/
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
public static class Tools {
/**
* 是否启用 Tool calling 工具调用【例子详见 TestAiTools.java、UserAiTools.java 】
*/
private Boolean enabled = false;
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
}
}

View File

@@ -0,0 +1,74 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.ai.cms.service.AiCmsChatService;
import com.jeesite.modules.sys.entity.Area;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.util.List;
import java.util.Map;
/**
* AI 对话单元测试
* @author ThinkGem
* @version 2025-06-06
*/
@ActiveProfiles("test")
@SpringBootApplication
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@SpringBootTest(properties = {"spring.ai.tools.enabled=true"})
public class AiChatServiceTest extends BaseSpringContextTests {
private final AiCmsChatService aiCmsChatService;
public AiChatServiceTest(AiCmsChatService aiCmsChatService) {
this.aiCmsChatService = aiCmsChatService;
}
@Test
public void test01Text() {
logger.info("===== 聊天对话,文本输出");
String message = "你好";
String text = aiCmsChatService.chatText(message);
System.out.println(text);
}
@Test
public void test02Json() {
logger.info("===== 聊天对话,结构化输出 JSON");
String message = "张三";
Map<String, Object> map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
}
@Test
public void test03Tool() {
logger.info("===== 聊天对话,结构化输出 Tool Calling");
String message = "打开客厅的灯";
Map<String, Object> map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
message = "关闭客厅的灯";
map = aiCmsChatService.chatJson(message);
System.out.println(JsonMapper.toJson(map));
}
@Test
public void test04Entity() {
logger.info("===== 聊天对话,结构化输出 Entity");
String message = "北京";
List<Area> list = aiCmsChatService.chatArea(message);
System.out.println(JsonMapper.toJson(list));
}
}