diff --git a/src/main/java/com/olympus/hermione/stepSolvers/AdvancedAIPromptSolver.java b/src/main/java/com/olympus/hermione/stepSolvers/AdvancedAIPromptSolver.java index b8faebe..4dfd15d 100644 --- a/src/main/java/com/olympus/hermione/stepSolvers/AdvancedAIPromptSolver.java +++ b/src/main/java/com/olympus/hermione/stepSolvers/AdvancedAIPromptSolver.java @@ -80,25 +80,28 @@ 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, selctedProject, @@ -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, diff --git a/src/main/java/com/olympus/hermione/tools/DocAndSourceCodeTool.java b/src/main/java/com/olympus/hermione/tools/DocAndSourceCodeTool.java index 5709d0d..559835f 100644 --- a/src/main/java/com/olympus/hermione/tools/DocAndSourceCodeTool.java +++ b/src/main/java/com/olympus/hermione/tools/DocAndSourceCodeTool.java @@ -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(); @@ -93,7 +93,7 @@ public class DocAndSourceCodeTool { restTemplate.postForEntity(serviceInstance.getUri() + "/similarity-search-code", similaritySearchCodeInput,CodeRagResponse[].class ).getBody(); String code=""; - + if (ragresponse == null || ragresponse.length == 0) { logger.warning("No source code found for the given query: " + query); return "No source code found for the given query."; diff --git a/src/main/java/com/olympus/hermione/tools/SourceCodeTool.java b/src/main/java/com/olympus/hermione/tools/SourceCodeTool.java index 41b6c0b..ee3b89a 100644 --- a/src/main/java/com/olympus/hermione/tools/SourceCodeTool.java +++ b/src/main/java/com/olympus/hermione/tools/SourceCodeTool.java @@ -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();