Merge branch 'master' into develop
This commit is contained in:
@@ -49,6 +49,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;
|
||||
|
||||
|
||||
|
||||
@@ -239,7 +240,9 @@ public class ScenarioExecutionService {
|
||||
case "RAG_SOURCE_CODE":
|
||||
solver = new SourceCodeRagSolver();
|
||||
break;
|
||||
|
||||
case "EXTERNAL_AGENT":
|
||||
solver = new ExternalAgentSolver();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
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 = 500;
|
||||
// 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(2000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.error("Thread was interrupted", e);
|
||||
}
|
||||
logger.info ("Check status => Remaining tryes :" + maxTries);
|
||||
maxTries--;
|
||||
|
||||
}
|
||||
|
||||
logger.info ("Stop pooling agents pod. Latest status = "+jsonResponse.get("status"));
|
||||
|
||||
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{
|
||||
logger.error ("ERROR on pooling Agents");
|
||||
|
||||
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());
|
||||
|
||||
@@ -15,8 +15,8 @@ spring.ai.vectorstore.mongodb.indexName=vector_index
|
||||
spring.ai.vectorstore.mongodb.collection-name=vector_store
|
||||
spring.ai.vectorstore.mongodb.initialize-schema=false
|
||||
|
||||
spring.ai.vectorstore.azure.api-key=jxKqZvbMKuo1MwXs8ilEAeRDeswtoTXO1lWX600jP2AzSeDXo1nq
|
||||
spring.ai.vectorstore.azure.url=https://search-olympus.search.windows.net
|
||||
spring.ai.vectorstore.azure.api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
spring.ai.vectorstore.azure.url=https://search-olympus.search.windows.net_old
|
||||
spring.ai.vectorstore.azure.initialize-schema =false
|
||||
|
||||
|
||||
@@ -58,4 +58,10 @@ eureka.instance.preferIpAddress: true
|
||||
hermione.fe.url = http://localhost:5173
|
||||
|
||||
java-parser-module.url: http://java-parser-module-service.olympus.svc.cluster.local:8080
|
||||
|
||||
java-re-module.url: http://java-re-module-service.olympus.svc.cluster.local:8080
|
||||
|
||||
spring.ai.vectorstore.chroma.client.host=http://108.142.74.161
|
||||
spring.ai.vectorstore.chroma.client.port=8000
|
||||
spring.ai.vectorstore.chroma.client.key-token=nVYLh3eq92aJP4x08dNdWngilPG2ooj9
|
||||
spring.ai.vectorstore.chroma.initialize-schema=true
|
||||
spring.ai.vectorstore.chroma.collection-name=olympus
|
||||
Reference in New Issue
Block a user