Riorganizza il codice per migliorare la gestione degli strumenti di documentazione e codice sorgente

This commit is contained in:
Andrea Terzani
2025-06-30 13:13:26 +02:00
parent ac3d7edd41
commit ce7dd0e681
3 changed files with 36 additions and 39 deletions

View File

@@ -80,24 +80,27 @@ public class AdvancedAIPromptSolver extends StepSolver {
for(String tool: this.qai_available_tools.split(",")){
logger.info("Tool: {}", tool);
String selctedProject = "";
String selectedApplication = "";
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project")!=null){
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project");
} else {
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_project");
}
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application")!=null){
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application");
} else {
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_application");
}
logger.info("Selected project: {}", selctedProject);
logger.info("Selected application: {}", selectedApplication);
switch(tool.trim()){
case "DocumentationTool" -> {
logger.info("Instantiating DocumentationTool");
String selctedProject = "";
String selectedApplication = "";
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project")!=null){
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project");
} else {
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_project");
}
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application")!=null){
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application");
} else {
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_application");
}
this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project");
tools = new com.olympus.hermione.tools.DocumentationTool(
selectedApplication,
@@ -107,23 +110,13 @@ public class AdvancedAIPromptSolver extends StepSolver {
case "SourceCodeTool" -> {
logger.info("Instantiating SourceCodeTool");
tools = new com.olympus.hermione.tools.SourceCodeTool(this.discoveryClient);
tools = new com.olympus.hermione.tools.SourceCodeTool(this.discoveryClient,
selectedApplication,
selctedProject);
}
case "DocAndSourceCodeTool" -> {
logger.info("Instantiating DocAndSourceCodeTool");
String selctedProject = "";
String selectedApplication = "";
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project")!=null){
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_project");
} else {
selctedProject = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_project");
}
if(this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application")!=null){
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("selected_application");
} else {
selectedApplication = this.scenarioExecution.getScenarioExecutionInput().getInputs().get("input_application");
}
tools = new com.olympus.hermione.tools.DocAndSourceCodeTool(
selectedApplication,

View File

@@ -84,8 +84,8 @@ public class DocAndSourceCodeTool {
similaritySearchCodeInput.setQuery(query);
similaritySearchCodeInput.setTopK("3");
similaritySearchCodeInput.setSimilarityThreshold("0.7");
similaritySearchCodeInput.setFilterExpression("");
similaritySearchCodeInput.setFilterExpression("'ksApplicationName' == '" + this.application+"'");
logger.info("[TOOL]LLM SourceCodeTool getCodeBySimilarity filterExpression: " + similaritySearchCodeInput.getFilterExpression());
ServiceInstance serviceInstance = discoveryClient.getInstances("source-code-module").get(0);
RestTemplate restTemplate = new RestTemplate();

View File

@@ -14,19 +14,22 @@ import com.olympus.dto.SimilaritySearchCodeInput;
public class SourceCodeTool {
private DiscoveryClient discoveryClient;
Logger logger = Logger.getLogger(SourceCodeTool.class.getName());
public SourceCodeTool(DiscoveryClient discoveryClient) {
private DiscoveryClient discoveryClient;
private String application;
public SourceCodeTool(DiscoveryClient discoveryClient,String application, String project) {
this.discoveryClient = discoveryClient;
this.application = application;
}
@Tool(description = "Get the source code of a class by fully qualified name")
public String getClassCodeByFullyQualifidClassName(String fullyQualifiedClassName) {
logger.info("[TOOL]LLM SourceCodeTool Getting source code for class: " + fullyQualifiedClassName);
logger.info("[TOOL]LLM SourceCodeTool getClassCodeByFullyQualifidClassName source code for class: " + fullyQualifiedClassName);
ServiceInstance serviceInstance = discoveryClient.getInstances("source-code-module").get(0);
RestTemplate restTemplate = new RestTemplate();
@@ -41,13 +44,14 @@ public class SourceCodeTool {
@Tool(description = "Retrieve the source code that match concept with natural language query ")
public String getCodeBySimilarity(String query) {
logger.info("[TOOL]LLM SourceCodeTool Getting source code for class: " + query);
logger.info("[TOOL]LLM SourceCodeTool getCodeBySimilarity source code for class: " + query);
SimilaritySearchCodeInput similaritySearchCodeInput = new SimilaritySearchCodeInput();
similaritySearchCodeInput.setQuery(query);
similaritySearchCodeInput.setTopK("3");
similaritySearchCodeInput.setSimilarityThreshold("0.7");
similaritySearchCodeInput.setFilterExpression("");
similaritySearchCodeInput.setFilterExpression("ksApplicationName == '" + this.application+"'");
logger.info("[TOOL]LLM SourceCodeTool getCodeBySimilarity filterExpression: " + similaritySearchCodeInput.getFilterExpression());
ServiceInstance serviceInstance = discoveryClient.getInstances("source-code-module").get(0);
RestTemplate restTemplate = new RestTemplate();