AI模块使用
jsbos-ai 项目AI模块
项目简介
jsbos-ai 项目AI模块,主要用于处理jsbos项目中AI相关的功能。
使用样例
1. 引入依赖
<dependency>
<groupId>com.bringspring</groupId>
<artifactId>jsbos-ai</artifactId>
<scope>compile</scope>
</dependency>
2. 实现接口McpBaseServer
/**
* 工单智能助手服务端实现
*
* @author 朱俊杰
* @since 2025-09-01
**/
@Service
@McpServerEndpoint(name = "workorder", sseEndpoint = "/mcp/workorder")
public class WorkOrderMcpServiceImpl implements McpBaseServer {
/**
* 智能报单创建工单接口
*/
@ToolMapping(name = "createWorkOrder", description = "创建工单:如果必填参数没有填写,则返回对应必填参数缺失的提示信息;参数完整经过确认后创建工单")
public String createWorkOrder(
@Param(name = "title", description = "工单标题:根据工单类型及当前登录用户生成工单标题;例如:'{姓名}提交{工单类型名称}的工单'", required = true) String title,
@Param(name = "workOrderTypeId", description = "工单类型ID:根据描述判断所属工单类型", required = true) String workOrderTypeId,
@Param(name = "note", description = "故障描述:只描述故障现象、故障原因", required = true) String note,
@Param(name = "location", description = "故障位置:根据描述信息,提取故障位置描述信息", required = true) String location,
@Param(name = "startTime", description = "预计开 始时间:默认当前时间;时间格式:yyyy-MM-dd HH:mm:ss", required = true) String startTime,
@Param(name = "priority", description = "紧急程度:根据描述判断工单紧急程度编码,默认一般;如:normal:一般、urgent:加急、emergent:紧急;") String priority,
@Param(name = "contacts", description = "联系人姓名:默认当前登录用户姓名;没有当前登录人信息时默认空;") String contacts,
@Param(name = "contactsPhone", description = "联系人手机:默认当前登录用户的手机号;没有当前登录人信息时默认空;") String contactsPhone,
@Param(name = "attachmentFileList", description = "工单附件:上传的附件列表,多个附件以逗号分隔") String attachmentFileList,
@Param(name = "token", description = "当前登陆人token", required = true) String token
) {
// 业务逻辑处理
//...
// 返回结果
return "工单创建成功";
}
}
3. 配置文件
config:
mcp:
enabled: true
4. 调用接口测试
public static void main(String[] args) {
McpClientProvider toolProvider = McpClientProvider.builder()
.apiUrl("http://localhost:30000/mcp/workorder")
.build();
//传参
Map<String, Object> map = Collections.singletonMap("location", "杭州");
//调用接口 getCurrentTime
String rst = toolProvider.callToolAsText("getCurrentTime", map).getContent();
System.out.println(rst);
}
// 调用接口
实现接口McpBaseServer,启动自动注入系统