Aggiunta del supporto per l'agente esterno e modifica dei metodi di esecuzione
This commit is contained in:
@@ -39,7 +39,7 @@ public class ApplicationBrowserService {
|
||||
classInfo.setCommitSha(kSGitInfo.getCommitId());
|
||||
classInfo.setRepositoryEntityId(kSGitInfo.getId());
|
||||
|
||||
result = javaREModule.revSingleClass(classInfo);
|
||||
result = null;//javaREModule.revSingleClass(classInfo);
|
||||
|
||||
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class ApplicationBrowserService {
|
||||
|
||||
try {
|
||||
// Chiama il metodo getProcessStatus e memorizza il risultato
|
||||
responseEntity = javaREModule.getProcessStatus(processId);
|
||||
responseEntity = null;//javaREModule.getProcessStatus(processId);
|
||||
} catch (Exception e) {
|
||||
// In caso di eccezione
|
||||
logger.error("Exception in getProgressRev: {}", e.getMessage());
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.slf4j.Logger;
|
||||
import com.azure.ai.openai.OpenAIClient;
|
||||
import com.azure.ai.openai.OpenAIClientBuilder;
|
||||
import com.azure.core.credential.AzureKeyCredential;
|
||||
import com.olympus.hermione.stepSolvers.ExternalAgentSolver;
|
||||
|
||||
|
||||
|
||||
@@ -231,7 +232,9 @@ public class ScenarioExecutionService {
|
||||
case "RAG_SOURCE_CODE":
|
||||
solver = new SourceCodeRagSolver();
|
||||
break;
|
||||
|
||||
case "EXTERNAL_AGENT":
|
||||
solver = new ExternalAgentSolver();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.olympus.hermione.stepSolvers;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.olympus.hermione.models.ScenarioExecution;
|
||||
import com.olympus.hermione.utility.AttributeParser;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
|
||||
public class ExternalAgentSolver extends StepSolver {
|
||||
|
||||
private String agent_input;
|
||||
private String agent_base_url;
|
||||
private String agent_output_variable;
|
||||
private String agent_application;
|
||||
private String agent_project;
|
||||
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(BasicQueryRagSolver.class);
|
||||
|
||||
private void loadParameters(){
|
||||
logger.info("Loading parameters");
|
||||
|
||||
if(this.step.getAttributes().get("agent_input")!=null ){
|
||||
this.agent_input = (String) this.step.getAttributes().get("agent_input");
|
||||
logger.info("agent_input: " + this.agent_input);
|
||||
}
|
||||
|
||||
if(this.step.getAttributes().get("agent_application")!=null ){
|
||||
this.agent_input = (String) this.step.getAttributes().get("agent_application");
|
||||
logger.info("agent_application: " + this.agent_application);
|
||||
}
|
||||
if(this.step.getAttributes().get("agent_project")!=null ){
|
||||
this.agent_project = (String) this.step.getAttributes().get("agent_project");
|
||||
logger.info("agent_project: " + this.agent_project);
|
||||
}
|
||||
|
||||
if(this.step.getAttributes().get("agent_base_url")!=null ){
|
||||
this.agent_base_url = (String) this.step.getAttributes().get("agent_base_url");
|
||||
logger.info("agent_base_url: " + this.agent_base_url);
|
||||
}
|
||||
|
||||
if(this.step.getAttributes().get("agent_output_variable")!=null ){
|
||||
this.agent_output_variable = (String) this.step.getAttributes().get("agent_output_variable");
|
||||
logger.info("agent_output_variable: " + this.agent_output_variable);
|
||||
}
|
||||
|
||||
AttributeParser attributeParser = new AttributeParser(this.scenarioExecution);
|
||||
|
||||
this.agent_input = attributeParser.parse((String) this.step.getAttributes().get("agent_input"));
|
||||
this.agent_application = attributeParser.parse((String) this.step.getAttributes().get("agent_application"));
|
||||
this.agent_project = attributeParser.parse((String) this.step.getAttributes().get("agent_project"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScenarioExecution solveStep() throws Exception {
|
||||
|
||||
System.out.println("Solving step: " + this.step.getName());
|
||||
|
||||
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||
|
||||
loadParameters();
|
||||
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.put("executionId", this.scenarioExecution.getId());
|
||||
requestBody.put("user_input", this.agent_input);
|
||||
requestBody.put("application", this.agent_application);
|
||||
requestBody.put("project", this.agent_project);
|
||||
|
||||
HttpEntity<String> request = new HttpEntity<>(requestBody.toString(), headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
this.agent_base_url+"/execute",
|
||||
HttpMethod.POST,
|
||||
request,
|
||||
String.class
|
||||
);
|
||||
|
||||
JSONObject jsonResponse = new JSONObject(response.getBody());
|
||||
|
||||
if (!jsonResponse.get("status").equals("STARTED")) {
|
||||
throw new Exception("Agent execution failed with status: " + jsonResponse.get("status"));
|
||||
}
|
||||
|
||||
|
||||
int maxTries = 100;
|
||||
// Pool the status GET api until it return the SUCCESS or FAILED message
|
||||
while(!jsonResponse.get("status").equals("COMPLETED") && !jsonResponse.get("status").equals("FAILED") && maxTries > 0){
|
||||
response = restTemplate.exchange(
|
||||
this.agent_base_url + "/status/" + this.scenarioExecution.getId(),
|
||||
HttpMethod.GET,
|
||||
request,
|
||||
String.class
|
||||
);
|
||||
jsonResponse = new JSONObject(response.getBody());
|
||||
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.error("Thread was interrupted", e);
|
||||
}
|
||||
|
||||
maxTries--;
|
||||
|
||||
}
|
||||
|
||||
if(jsonResponse.get("status").equals("COMPLETED")){
|
||||
response = restTemplate.exchange(
|
||||
this.agent_base_url + "/execution_result/" + this.scenarioExecution.getId(),
|
||||
HttpMethod.GET,
|
||||
request,
|
||||
String.class
|
||||
);
|
||||
jsonResponse = new JSONObject(response.getBody());
|
||||
|
||||
this.scenarioExecution.getExecSharedMap().put(this.agent_output_variable, jsonResponse.toString());
|
||||
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||
|
||||
}else{
|
||||
throw new Exception("Agent execution failed with status: " + jsonResponse.get("status"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return this.scenarioExecution;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class StepSolver {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(StepSolver.class);
|
||||
|
||||
public ScenarioExecution solveStep(){
|
||||
public ScenarioExecution solveStep() throws Exception {
|
||||
logger.info("Solving step: " + this.step.getName());
|
||||
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||
|
||||
Reference in New Issue
Block a user