new engine workflows

This commit is contained in:
andrea.terzani
2024-09-05 10:14:22 +02:00
parent 3580789de5
commit 967b61a0fe
12 changed files with 79 additions and 34 deletions

View File

@@ -91,10 +91,11 @@
<version>4.3.4</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.8</version>
</dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.8</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>

View File

@@ -3,8 +3,12 @@ package com.olympus.hermione.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ComparisonOperators.Ne;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.olympus.hermione.dto.ScenarioExecutionInput;
import com.olympus.hermione.dto.ScenarioOutput;
import com.olympus.hermione.services.Neo4JUitilityService;
import com.olympus.hermione.services.ScenarioExecutionService;
@@ -14,20 +18,23 @@ public class TestController {
@Autowired
ScenarioExecutionService scenarioExecutionService;
@Autowired
Neo4JUitilityService neo4JUitilityService;
@GetMapping("/test/scenario_execution")
public String testScenarioExecution(){
String result = scenarioExecutionService.executeScenario("66aa162debe80dfcd17f0ef4","How i can change the path where uploaded documents are stored ?");
return result;
@PostMapping("test/execute")
public ScenarioOutput executeScenario(@RequestBody ScenarioExecutionInput scenarioExecutionInput) {
return scenarioExecutionService.executeScenario(scenarioExecutionInput);
}
@GetMapping("/test/generate_schema_description")
public String testGenerateSchemaDescription(){
return neo4JUitilityService.generateSchemaDescription().toString();
}
}

View File

@@ -15,6 +15,7 @@ public class Scenario {
private String id;
private String name;
private String description;
private String startWithStepId;
private List<ScenarioStep> steps;
private List<ScenarioInputs> inputs;

View File

@@ -21,5 +21,8 @@ public class ScenarioExecution {
private String scenarioId;
private String currentStepId;
private String nextStepId;
}

View File

@@ -12,6 +12,9 @@ public class ScenarioStep {
private String description;
private String name;
private int order;
private String stepId;
private String nextStepId;
private HashMap<String,Object> attributes;

View File

@@ -71,8 +71,11 @@ public class ScenarioExecutionService {
List<ScenarioStep> steps = scenario.getSteps();
steps.sort(Comparator.comparingInt(ScenarioStep::getOrder));
for (ScenarioStep step : steps) {
executeScenarioStep(step, scenarioExecution, step.getOrder());
executeScenarioStep(step, scenarioExecution);
}
return scenarioExecution.getExecSharedMap().get("scenario_output").toString();
@@ -107,9 +110,18 @@ public class ScenarioExecutionService {
List<ScenarioStep> steps = scenario.getSteps();
steps.sort(Comparator.comparingInt(ScenarioStep::getOrder));
for (ScenarioStep step : steps) {
executeScenarioStep(step, scenarioExecution, step.getOrder());
String startStepId=scenario.getStartWithStepId();
ScenarioStep startStep = steps.stream().filter(step -> step.getStepId().equals(startStepId)).findFirst().orElse(null);
executeScenarioStep(startStep, scenarioExecution);
while (scenarioExecution.getNextStepId()!=null) {
ScenarioStep step = steps.stream().filter(s -> s.getStepId().equals(scenarioExecution.getNextStepId())).findFirst().orElse(null);
executeScenarioStep(step, scenarioExecution);
}
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
@@ -130,7 +142,7 @@ public class ScenarioExecutionService {
private void executeScenarioStep(ScenarioStep step, ScenarioExecution scenarioExecution, int stepIndex){
private void executeScenarioStep(ScenarioStep step, ScenarioExecution scenarioExecution){
logger.info("Start working on step: " + step.getName() + " with type: " + step.getType());
StepSolver solver=new StepSolver();
switch (step.getType()) {
@@ -147,14 +159,18 @@ public class ScenarioExecutionService {
break;
}
logger.info("Initializing step: " + step.getName());
logger.info("Initializing step: " + step.getStepId());
solver.init(step, scenarioExecution, vectorStore,chatModel,graphDriver,neo4JUitilityService);
logger.info("Solving step: " + step.getName());
logger.info("Solving step: " + step.getStepId());
scenarioExecution.setCurrentStepId(step.getStepId());
//must add try catch in order to catch exceptions and step execution errors
ScenarioExecution scenarioExecutionNew = solver.solveStep();
logger.info("Step solved: " + step.getStepId());
logger.info("Next step: " + scenarioExecutionNew.getNextStepId());
scenarioExecutionRepository.save(scenarioExecutionNew);

View File

@@ -49,6 +49,8 @@ public class BasicAIPromptSolver extends StepSolver {
System.out.println("Solving step: " + this.step.getName());
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
loadParameters();
@@ -64,7 +66,9 @@ public class BasicAIPromptSolver extends StepSolver {
String output = response.get(0).getOutput().getContent();
this.scenarioExecution.getExecSharedMap().put(this.qai_output_variable, output);
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
return this.scenarioExecution;
}

View File

@@ -93,7 +93,9 @@ public class BasicQueryRagSolver extends StepSolver {
//concatenate the content of the results into a single string
String resultString = String.join("\n", result);
this.scenarioExecution.getExecSharedMap().put(this.outputField, resultString);
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
return this.scenarioExecution;
}

View File

@@ -58,6 +58,9 @@ public class QueryNeo4JSolver extends StepSolver {
this.scenarioExecution.getExecSharedMap().put(this.outputField, "Error executing query: " + e.getMessage());
}
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
return this.scenarioExecution;
}

View File

@@ -20,8 +20,14 @@ public class StepSolver {
public ScenarioExecution solveStep(){
System.out.println("Solving step: " + this.step.getName());
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
return this.scenarioExecution;
};
public void init(ScenarioStep step, ScenarioExecution scenarioExecution, VectorStore vectorStore,ChatModel chatModel,Driver graphDriver,Neo4JUitilityService neo4JUitilityService){
this.scenarioExecution = scenarioExecution;
this.step = step;

View File

@@ -1,16 +0,0 @@
{
"folders": [
{
"path": "../../../../../../../../apollo"
},
{
"name": "hermione",
"path": "../../../../../../.."
},
{
"name": "hermione-fe",
"path": "../../../../../../../../hermione-fe"
}
],
"settings": {}
}

View File

@@ -0,0 +1,15 @@
{
"id": "test-workflow",
"version": 1,
"steps": [
{
"id": "step1",
"stepType": "com.olympus.hermione.stepSolversV2.Task1",
"nextStepId": "step2"
},
{
"id": "step2",
"stepType": "com.olympus.hermione.stepSolversV2.Task2"
}
]
}