重命名 tool-calls to tools.enabled
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
package com.jeesite.modules.cms.ai.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
@ConfigurationProperties("spring.ai")
|
||||
public class CmsAiProperties {
|
||||
|
||||
/**
|
||||
* 是否启用 Tool calling 工具调用
|
||||
*/
|
||||
private Boolean toolCalls = false;
|
||||
|
||||
/**
|
||||
* 默认系统提示词
|
||||
*/
|
||||
private String defaultSystem = "";
|
||||
|
||||
/**
|
||||
* 默认问题模板格式
|
||||
*/
|
||||
private String defaultPromptTemplate = "";
|
||||
|
||||
/**
|
||||
* 向量数据库设置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private final Vectorstore vectorstore = new Vectorstore();
|
||||
|
||||
public Boolean getToolCalls() {
|
||||
return toolCalls;
|
||||
}
|
||||
|
||||
public void setToolCalls(Boolean toolCalls) {
|
||||
this.toolCalls = toolCalls;
|
||||
}
|
||||
|
||||
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 Vectorstore getVectorstore() {
|
||||
return vectorstore;
|
||||
}
|
||||
|
||||
public static class Vectorstore {
|
||||
|
||||
/**
|
||||
* 向量库类型选择:chroma、pgvector、elasticsearch、milvus
|
||||
*/
|
||||
private String type;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/**
|
||||
* 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.cms.ai.service.CmsAiChatService;
|
||||
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.tool-calls=true"})
|
||||
public class AiChatServiceTest extends BaseSpringContextTests {
|
||||
|
||||
private final CmsAiChatService cmsAiChatService;
|
||||
|
||||
public AiChatServiceTest(CmsAiChatService cmsAiChatService) {
|
||||
this.cmsAiChatService = cmsAiChatService;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01Text() {
|
||||
logger.info("===== 聊天对话,文本输出");
|
||||
String message = "你好";
|
||||
String text = cmsAiChatService.chatText(message);
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02Json() {
|
||||
logger.info("===== 聊天对话,结构化输出 JSON");
|
||||
String message = "张三";
|
||||
Map<String, Object> map = cmsAiChatService.chatJson(message);
|
||||
System.out.println(JsonMapper.toJson(map));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test03Tool() {
|
||||
logger.info("===== 聊天对话,结构化输出 Tool Calling");
|
||||
String message = "打开客厅的灯";
|
||||
Map<String, Object> map = cmsAiChatService.chatJson(message);
|
||||
System.out.println(JsonMapper.toJson(map));
|
||||
message = "关闭客厅的灯";
|
||||
map = cmsAiChatService.chatJson(message);
|
||||
System.out.println(JsonMapper.toJson(map));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test04Entity() {
|
||||
logger.info("===== 聊天对话,结构化输出 Entity");
|
||||
String message = "北京";
|
||||
List<Area> list = cmsAiChatService.chatArea(message);
|
||||
System.out.println(JsonMapper.toJson(list));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user