This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push:
new 928f6ced BIGTOP-4308: Add some info tools to chatbot (#131)
928f6ced is described below
commit 928f6ced70820261c8771397ec980a3b385e1e4e
Author: haopeng <[email protected]>
AuthorDate: Tue Dec 24 16:20:50 2024 +0800
BIGTOP-4308: Add some info tools to chatbot (#131)
---
.../bigtop/manager/common/utils/JsonUtils.java | 16 ++++
.../resources/mapper/postgresql/HostMapper.xml | 4 +-
.../server/controller/ChatbotController.java | 3 +-
.../server/service/impl/ChatbotServiceImpl.java | 27 +++---
.../manager/server/tools/ClusterInfoTools.java | 51 ----------
.../server/tools/functions/ClusterFunctions.java | 101 ++++++++++++++++++++
.../server/tools/functions/HostFunctions.java | 87 +++++++++++++++++
.../server/tools/functions/StackFunctions.java | 104 +++++++++++++++++++++
.../AIServiceToolsProvider.java} | 29 +++---
.../InfoToolsProvider.java} | 37 +++++---
10 files changed, 356 insertions(+), 103 deletions(-)
diff --git
a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java
b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java
index 963b48a3..5e0d1bc7 100644
---
a/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java
+++
b/bigtop-manager-common/src/main/java/org/apache/bigtop/manager/common/utils/JsonUtils.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
@@ -31,11 +32,15 @@ import java.io.File;
public class JsonUtils {
public static final ObjectMapper OBJECTMAPPER;
+ public static final ObjectMapper INDENT_MAPPER;
static {
OBJECTMAPPER = new ObjectMapper();
OBJECTMAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
OBJECTMAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+
+ INDENT_MAPPER = OBJECTMAPPER.copy();
+ INDENT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
}
public static <T> void writeToFile(String fileName, T obj) {
@@ -129,4 +134,15 @@ public class JsonUtils {
throw new RuntimeException(e);
}
}
+
+ public static <T> String indentWriteAsString(T obj) {
+ if (obj == null) {
+ return null;
+ }
+ try {
+ return INDENT_MAPPER.writeValueAsString(obj);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git
a/bigtop-manager-dao/src/main/resources/mapper/postgresql/HostMapper.xml
b/bigtop-manager-dao/src/main/resources/mapper/postgresql/HostMapper.xml
index 1d02e435..755cc048 100644
--- a/bigtop-manager-dao/src/main/resources/mapper/postgresql/HostMapper.xml
+++ b/bigtop-manager-dao/src/main/resources/mapper/postgresql/HostMapper.xml
@@ -58,7 +58,7 @@
and h.status = #{query.status}
</if>
</where>
- group by h.id, c.name
+ group by h.id, c.name, c.display_name
</select>
<select id="findDetailsById"
resultType="org.apache.bigtop.manager.dao.po.HostPO">
@@ -70,7 +70,7 @@
left join cluster c on h.cluster_id = c.id
left join component comp on h.id = comp.host_id
where h.id = #{id}
- group by h.id, c.name
+ group by h.id, c.name, c.display_name
limit 1
</select>
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ChatbotController.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ChatbotController.java
index 14ef4cba..2206970e 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ChatbotController.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ChatbotController.java
@@ -93,9 +93,8 @@ public class ChatbotController {
if (command != null) {
messageReq.setMessage(
messageReq.getMessage().substring(command.getCmd().length() + 2));
- return chatbotService.talk(threadId, command,
messageReq.getMessage());
}
- return chatbotService.talk(threadId, null, messageReq.getMessage());
+ return chatbotService.talk(threadId, command, messageReq.getMessage());
}
@Operation(summary = "history", description = "Get chat records")
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ChatbotServiceImpl.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ChatbotServiceImpl.java
index a27b64a9..41522581 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ChatbotServiceImpl.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/ChatbotServiceImpl.java
@@ -47,7 +47,7 @@ import
org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
import org.apache.bigtop.manager.server.model.vo.TalkVO;
import org.apache.bigtop.manager.server.service.ChatbotService;
-import org.apache.bigtop.manager.server.tools.AiServiceToolsProvider;
+import org.apache.bigtop.manager.server.tools.provider.AIServiceToolsProvider;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
@@ -77,6 +77,9 @@ public class ChatbotServiceImpl implements ChatbotService {
@Resource
private ChatMessageDao chatMessageDao;
+ @Resource
+ private AIServiceToolsProvider aiServiceToolsProvider;
+
private AIAssistantFactory aiAssistantFactory;
private static final int CHAT_THREAD_NAME_LENGTH = 100;
@@ -121,18 +124,12 @@ public class ChatbotServiceImpl implements ChatbotService
{
private AIAssistant buildAIAssistant(
String platformName, String model, Map<String, String>
credentials, Long threadId, ChatbotCommand command) {
- if (command == null) {
- return getAIAssistantFactory()
- .createAiService(
- getPlatformType(platformName),
getAIAssistantConfig(model, credentials), threadId, null);
- } else {
- return getAIAssistantFactory()
- .createAiService(
- getPlatformType(platformName),
- getAIAssistantConfig(model, credentials),
- threadId,
- new AiServiceToolsProvider(command));
- }
+ return getAIAssistantFactory()
+ .createAiService(
+ getPlatformType(platformName),
+ getAIAssistantConfig(model, credentials),
+ threadId,
+ aiServiceToolsProvider.getToolsProvide(command));
}
@Override
@@ -193,7 +190,7 @@ public class ChatbotServiceImpl implements ChatbotService {
return chatThreads;
}
- private AIAssistant prepareTalk(Long threadId, ChatbotCommand command,
String message) {
+ private AIAssistant prepareTalk(Long threadId, ChatbotCommand command) {
ChatThreadPO chatThreadPO = chatThreadDao.findById(threadId);
Long userId = SessionUserHolder.getUserId();
if (!Objects.equals(userId, chatThreadPO.getUserId()) ||
chatThreadPO.getIsDeleted()) {
@@ -219,7 +216,7 @@ public class ChatbotServiceImpl implements ChatbotService {
@Override
public SseEmitter talk(Long threadId, ChatbotCommand command, String
message) {
- AIAssistant aiAssistant = prepareTalk(threadId, command, message);
+ AIAssistant aiAssistant = prepareTalk(threadId, command);
Flux<String> stringFlux;
if (command == null) {
stringFlux = aiAssistant.streamAsk(message);
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/ClusterInfoTools.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/ClusterInfoTools.java
deleted file mode 100644
index 3f654891..00000000
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/ClusterInfoTools.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.bigtop.manager.server.tools;
-
-import org.apache.bigtop.manager.dao.po.ClusterPO;
-import org.apache.bigtop.manager.server.model.converter.ClusterConverter;
-
-import dev.langchain4j.agent.tool.Tool;
-import dev.langchain4j.agent.tool.ToolSpecification;
-import dev.langchain4j.service.tool.ToolExecutor;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class ClusterInfoTools {
-
- @Tool("Get cluster list")
- public Map<ToolSpecification, ToolExecutor> list() {
- ToolSpecification toolSpecification = ToolSpecification.builder()
- .name("list")
- .description("Get cluster list")
- .build();
- ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
- List<ClusterPO> clusterPOList = new ArrayList<>();
- ClusterPO mockClusterPO = new ClusterPO();
- mockClusterPO.setId(1L);
- mockClusterPO.setName("mock-cluster");
- clusterPOList.add(mockClusterPO);
- return
ClusterConverter.INSTANCE.fromPO2VO(clusterPOList).toString();
- };
-
- return Map.of(toolSpecification, toolExecutor);
- }
-}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/ClusterFunctions.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/ClusterFunctions.java
new file mode 100644
index 00000000..7f61e6d6
--- /dev/null
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/ClusterFunctions.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.tools.functions;
+
+import org.apache.bigtop.manager.common.utils.JsonUtils;
+import org.apache.bigtop.manager.server.model.vo.ClusterVO;
+import org.apache.bigtop.manager.server.service.ClusterService;
+
+import org.springframework.stereotype.Component;
+
+import dev.langchain4j.agent.tool.JsonSchemaProperty;
+import dev.langchain4j.agent.tool.ToolSpecification;
+import dev.langchain4j.service.tool.ToolExecutor;
+import lombok.extern.slf4j.Slf4j;
+
+import jakarta.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+@Slf4j
+public class ClusterFunctions {
+ @Resource
+ private ClusterService clusterService;
+
+ public Map<ToolSpecification, ToolExecutor> listCluster() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("listCluster")
+ .description("Get cluster list")
+ .build();
+ ToolExecutor toolExecutor =
+ (toolExecutionRequest, memoryId) ->
JsonUtils.indentWriteAsString(clusterService.list());
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getClusterById() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("getClusterById")
+ .description("Get cluster information based on ID")
+ .addParameter("clusterId", JsonSchemaProperty.NUMBER,
JsonSchemaProperty.description("cluster id"))
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, Object> arguments =
JsonUtils.readFromString(toolExecutionRequest.arguments());
+ Long clusterId =
Long.valueOf(arguments.get("clusterId").toString());
+ ClusterVO clusterVO = clusterService.get(clusterId);
+ if (clusterVO == null) {
+ return "Cluster not found";
+ }
+ return JsonUtils.indentWriteAsString(clusterVO);
+ };
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getClusterByName() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("getClusterByName")
+ .description("Get cluster information based on cluster name")
+ .addParameter("clusterName", JsonSchemaProperty.STRING,
JsonSchemaProperty.description("cluster name"))
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, Object> arguments =
JsonUtils.readFromString(toolExecutionRequest.arguments());
+ String clusterName = arguments.get("clusterName").toString();
+ List<ClusterVO> clusterVOS = clusterService.list();
+ for (ClusterVO clusterVO : clusterVOS) {
+ if (clusterVO.getName().equals(clusterName)) {
+ return JsonUtils.indentWriteAsString(clusterVO);
+ }
+ }
+ return "Cluster not found";
+ };
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getAllFunctions() {
+ Map<ToolSpecification, ToolExecutor> functions = new HashMap<>();
+ functions.putAll(listCluster());
+ functions.putAll(getClusterById());
+ functions.putAll(getClusterByName());
+ return functions;
+ }
+}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/HostFunctions.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/HostFunctions.java
new file mode 100644
index 00000000..d0b30bd6
--- /dev/null
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/HostFunctions.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.tools.functions;
+
+import org.apache.bigtop.manager.common.utils.JsonUtils;
+import org.apache.bigtop.manager.dao.query.HostQuery;
+import org.apache.bigtop.manager.server.model.vo.HostVO;
+import org.apache.bigtop.manager.server.model.vo.PageVO;
+import org.apache.bigtop.manager.server.service.HostService;
+
+import org.springframework.stereotype.Component;
+
+import dev.langchain4j.agent.tool.JsonSchemaProperty;
+import dev.langchain4j.agent.tool.ToolSpecification;
+import dev.langchain4j.service.tool.ToolExecutor;
+import lombok.extern.slf4j.Slf4j;
+
+import jakarta.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+@Slf4j
+public class HostFunctions {
+ @Resource
+ private HostService hostService;
+
+ public Map<ToolSpecification, ToolExecutor> getHostById() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("getHostById")
+ .description("Get host information based on ID")
+ .addParameter("hostId", JsonSchemaProperty.NUMBER,
JsonSchemaProperty.description("host id"))
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, Object> arguments =
JsonUtils.readFromString(toolExecutionRequest.arguments());
+ Long hostId = Long.valueOf(arguments.get("hostId").toString());
+ HostVO hostVO = hostService.get(hostId);
+ if (hostVO == null) {
+ return "Host not found";
+ }
+ return JsonUtils.indentWriteAsString(hostVO);
+ };
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getHostByName() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("getHostByName")
+ .description("Get host information based on cluster name")
+ .addParameter("hostName", JsonSchemaProperty.STRING,
JsonSchemaProperty.description("host name"))
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, Object> arguments =
JsonUtils.readFromString(toolExecutionRequest.arguments());
+ String hostName = arguments.get("hostName").toString();
+ HostQuery hostQuery = new HostQuery();
+ hostQuery.setHostname(hostName);
+ PageVO<HostVO> hostVO = hostService.list(hostQuery);
+ return JsonUtils.indentWriteAsString(hostVO);
+ };
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getAllFunctions() {
+ Map<ToolSpecification, ToolExecutor> functions = new HashMap<>();
+ functions.putAll(getHostById());
+ functions.putAll(getHostByName());
+ return functions;
+ }
+}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/StackFunctions.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/StackFunctions.java
new file mode 100644
index 00000000..dee8d0a5
--- /dev/null
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/StackFunctions.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.tools.functions;
+
+import org.apache.bigtop.manager.common.utils.JsonUtils;
+import org.apache.bigtop.manager.server.model.vo.PropertyVO;
+import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO;
+import org.apache.bigtop.manager.server.model.vo.ServiceVO;
+import org.apache.bigtop.manager.server.model.vo.StackVO;
+import org.apache.bigtop.manager.server.service.StackService;
+
+import org.springframework.stereotype.Component;
+
+import dev.langchain4j.agent.tool.JsonSchemaProperty;
+import dev.langchain4j.agent.tool.ToolSpecification;
+import dev.langchain4j.service.tool.ToolExecutor;
+import lombok.extern.slf4j.Slf4j;
+
+import jakarta.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+@Slf4j
+public class StackFunctions {
+ @Resource
+ private StackService stackService;
+
+ public Map<ToolSpecification, ToolExecutor> listStackAndService() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("listStackAndService")
+ .description("Retrieve the list of services in each stack")
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, List<String>> stackInfo = new HashMap<>();
+ for (StackVO stackVO : stackService.list()) {
+ List<String> services = new ArrayList<>();
+ for (ServiceVO serviceVO : stackVO.getServices()) {
+ services.add(serviceVO.getName());
+ }
+ stackInfo.put(stackVO.getStackName(), services);
+ }
+ return JsonUtils.indentWriteAsString(stackInfo);
+ };
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getServiceByName() {
+ ToolSpecification toolSpecification = ToolSpecification.builder()
+ .name("getServiceByName")
+ .description("Get service information and configs based on
service name")
+ .addParameter(
+ "serviceName",
+ JsonSchemaProperty.STRING,
+ JsonSchemaProperty.description("Lowercase service
name"))
+ .build();
+ ToolExecutor toolExecutor = (toolExecutionRequest, memoryId) -> {
+ Map<String, Object> arguments =
JsonUtils.readFromString(toolExecutionRequest.arguments());
+ String serviceName = arguments.get("serviceName").toString();
+ for (StackVO stackVO : stackService.list()) {
+ for (ServiceVO serviceVO : stackVO.getServices()) {
+ if (serviceVO.getName().equals(serviceName)) {
+ for (ServiceConfigVO serviceConfigVO :
serviceVO.getConfigs()) {
+ for (PropertyVO propertyVO :
serviceConfigVO.getProperties()) {
+ if (propertyVO.getName().equals("content")) {
+ propertyVO.setValue(null);
+ }
+ }
+ }
+ return JsonUtils.indentWriteAsString(serviceVO);
+ }
+ }
+ }
+ return "Service not found";
+ };
+
+ return Map.of(toolSpecification, toolExecutor);
+ }
+
+ public Map<ToolSpecification, ToolExecutor> getAllFunctions() {
+ Map<ToolSpecification, ToolExecutor> functions = new HashMap<>();
+ functions.putAll(listStackAndService());
+ functions.putAll(getServiceByName());
+ return functions;
+ }
+}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/AIServiceToolsProvider.java
similarity index 55%
copy from
bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
copy to
bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/AIServiceToolsProvider.java
index ffcabfcc..72632ba3 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/AIServiceToolsProvider.java
@@ -16,31 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.bigtop.manager.server.tools;
+package org.apache.bigtop.manager.server.tools.provider;
import org.apache.bigtop.manager.server.enums.ChatbotCommand;
-import dev.langchain4j.service.tool.ToolProvider;
-import dev.langchain4j.service.tool.ToolProviderRequest;
-import dev.langchain4j.service.tool.ToolProviderResult;
+import org.springframework.stereotype.Component;
-public class AiServiceToolsProvider implements ToolProvider {
+import dev.langchain4j.service.tool.ToolProvider;
- ChatbotCommand chatbotCommand;
+import jakarta.annotation.Resource;
- public AiServiceToolsProvider(ChatbotCommand chatbotCommand) {
- this.chatbotCommand = chatbotCommand;
- }
-
- public AiServiceToolsProvider() {
- this.chatbotCommand = null;
- }
+@Component
+public class AIServiceToolsProvider {
+ @Resource
+ private InfoToolsProvider infoToolsProvider;
- @Override
- public ToolProviderResult provideTools(ToolProviderRequest
toolProviderRequest) {
- if (chatbotCommand.equals(ChatbotCommand.INFO)) {
- ClusterInfoTools clusterInfoTools = new ClusterInfoTools();
- return
ToolProviderResult.builder().addAll(clusterInfoTools.list()).build();
+ public ToolProvider getToolsProvide(ChatbotCommand chatbotCommand) {
+ if (ChatbotCommand.INFO.equals(chatbotCommand)) {
+ return infoToolsProvider;
}
return null;
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/InfoToolsProvider.java
similarity index 55%
rename from
bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
rename to
bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/InfoToolsProvider.java
index ffcabfcc..36ec1f92 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/AiServiceToolsProvider.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/tools/provider/InfoToolsProvider.java
@@ -16,32 +16,39 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.bigtop.manager.server.tools;
+package org.apache.bigtop.manager.server.tools.provider;
-import org.apache.bigtop.manager.server.enums.ChatbotCommand;
+import org.apache.bigtop.manager.server.tools.functions.ClusterFunctions;
+import org.apache.bigtop.manager.server.tools.functions.HostFunctions;
+import org.apache.bigtop.manager.server.tools.functions.StackFunctions;
+
+import org.springframework.stereotype.Component;
import dev.langchain4j.service.tool.ToolProvider;
import dev.langchain4j.service.tool.ToolProviderRequest;
import dev.langchain4j.service.tool.ToolProviderResult;
+import lombok.extern.slf4j.Slf4j;
-public class AiServiceToolsProvider implements ToolProvider {
+import jakarta.annotation.Resource;
- ChatbotCommand chatbotCommand;
+@Component
+@Slf4j
+public class InfoToolsProvider implements ToolProvider {
+ @Resource
+ private ClusterFunctions clusterFunctions;
- public AiServiceToolsProvider(ChatbotCommand chatbotCommand) {
- this.chatbotCommand = chatbotCommand;
- }
+ @Resource
+ private HostFunctions hostFunctions;
- public AiServiceToolsProvider() {
- this.chatbotCommand = null;
- }
+ @Resource
+ private StackFunctions stackFunctions;
@Override
public ToolProviderResult provideTools(ToolProviderRequest
toolProviderRequest) {
- if (chatbotCommand.equals(ChatbotCommand.INFO)) {
- ClusterInfoTools clusterInfoTools = new ClusterInfoTools();
- return
ToolProviderResult.builder().addAll(clusterInfoTools.list()).build();
- }
- return null;
+ return ToolProviderResult.builder()
+ .addAll(clusterFunctions.getAllFunctions())
+ .addAll(hostFunctions.getAllFunctions())
+ .addAll(stackFunctions.getAllFunctions())
+ .build();
}
}