-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIGTOP-4308: Add some info tools to chatbot (#131)
- Loading branch information
Showing
10 changed files
with
388 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
...manager-server/src/main/java/org/apache/bigtop/manager/server/tools/ClusterInfoTools.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
...rver/src/main/java/org/apache/bigtop/manager/server/tools/functions/ClusterFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...-server/src/main/java/org/apache/bigtop/manager/server/tools/functions/HostFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.