new engine workflows
This commit is contained in:
9
pom.xml
9
pom.xml
@@ -91,10 +91,11 @@
|
|||||||
<version>4.3.4</version>
|
<version>4.3.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.8.8</version>
|
<version>2.8.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ package com.olympus.hermione.controllers;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.mongodb.core.aggregation.ComparisonOperators.Ne;
|
import org.springframework.data.mongodb.core.aggregation.ComparisonOperators.Ne;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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 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.Neo4JUitilityService;
|
||||||
import com.olympus.hermione.services.ScenarioExecutionService;
|
import com.olympus.hermione.services.ScenarioExecutionService;
|
||||||
|
|
||||||
@@ -14,20 +18,23 @@ public class TestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ScenarioExecutionService scenarioExecutionService;
|
ScenarioExecutionService scenarioExecutionService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
Neo4JUitilityService neo4JUitilityService;
|
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 ?");
|
@PostMapping("test/execute")
|
||||||
return result;
|
public ScenarioOutput executeScenario(@RequestBody ScenarioExecutionInput scenarioExecutionInput) {
|
||||||
|
return scenarioExecutionService.executeScenario(scenarioExecutionInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/test/generate_schema_description")
|
@GetMapping("/test/generate_schema_description")
|
||||||
public String testGenerateSchemaDescription(){
|
public String testGenerateSchemaDescription(){
|
||||||
return neo4JUitilityService.generateSchemaDescription().toString();
|
return neo4JUitilityService.generateSchemaDescription().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class Scenario {
|
|||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
|
private String startWithStepId;
|
||||||
private List<ScenarioStep> steps;
|
private List<ScenarioStep> steps;
|
||||||
private List<ScenarioInputs> inputs;
|
private List<ScenarioInputs> inputs;
|
||||||
|
|
||||||
|
|||||||
@@ -21,5 +21,8 @@ public class ScenarioExecution {
|
|||||||
|
|
||||||
private String scenarioId;
|
private String scenarioId;
|
||||||
|
|
||||||
|
private String currentStepId;
|
||||||
|
private String nextStepId;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ public class ScenarioStep {
|
|||||||
private String description;
|
private String description;
|
||||||
private String name;
|
private String name;
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
private String stepId;
|
||||||
|
private String nextStepId;
|
||||||
|
|
||||||
private HashMap<String,Object> attributes;
|
private HashMap<String,Object> attributes;
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,11 @@ public class ScenarioExecutionService {
|
|||||||
List<ScenarioStep> steps = scenario.getSteps();
|
List<ScenarioStep> steps = scenario.getSteps();
|
||||||
|
|
||||||
steps.sort(Comparator.comparingInt(ScenarioStep::getOrder));
|
steps.sort(Comparator.comparingInt(ScenarioStep::getOrder));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (ScenarioStep step : steps) {
|
for (ScenarioStep step : steps) {
|
||||||
executeScenarioStep(step, scenarioExecution, step.getOrder());
|
executeScenarioStep(step, scenarioExecution);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scenarioExecution.getExecSharedMap().get("scenario_output").toString();
|
return scenarioExecution.getExecSharedMap().get("scenario_output").toString();
|
||||||
@@ -107,9 +110,18 @@ public class ScenarioExecutionService {
|
|||||||
|
|
||||||
List<ScenarioStep> steps = scenario.getSteps();
|
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());
|
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());
|
logger.info("Start working on step: " + step.getName() + " with type: " + step.getType());
|
||||||
StepSolver solver=new StepSolver();
|
StepSolver solver=new StepSolver();
|
||||||
switch (step.getType()) {
|
switch (step.getType()) {
|
||||||
@@ -147,14 +159,18 @@ public class ScenarioExecutionService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Initializing step: " + step.getName());
|
logger.info("Initializing step: " + step.getStepId());
|
||||||
solver.init(step, scenarioExecution, vectorStore,chatModel,graphDriver,neo4JUitilityService);
|
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
|
//must add try catch in order to catch exceptions and step execution errors
|
||||||
ScenarioExecution scenarioExecutionNew = solver.solveStep();
|
ScenarioExecution scenarioExecutionNew = solver.solveStep();
|
||||||
|
|
||||||
|
logger.info("Step solved: " + step.getStepId());
|
||||||
|
logger.info("Next step: " + scenarioExecutionNew.getNextStepId());
|
||||||
|
|
||||||
scenarioExecutionRepository.save(scenarioExecutionNew);
|
scenarioExecutionRepository.save(scenarioExecutionNew);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class BasicAIPromptSolver extends StepSolver {
|
|||||||
|
|
||||||
System.out.println("Solving step: " + this.step.getName());
|
System.out.println("Solving step: " + this.step.getName());
|
||||||
|
|
||||||
|
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||||
|
|
||||||
loadParameters();
|
loadParameters();
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +66,9 @@ public class BasicAIPromptSolver extends StepSolver {
|
|||||||
String output = response.get(0).getOutput().getContent();
|
String output = response.get(0).getOutput().getContent();
|
||||||
|
|
||||||
this.scenarioExecution.getExecSharedMap().put(this.qai_output_variable, output);
|
this.scenarioExecution.getExecSharedMap().put(this.qai_output_variable, output);
|
||||||
|
|
||||||
|
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||||
|
|
||||||
return this.scenarioExecution;
|
return this.scenarioExecution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ public class BasicQueryRagSolver extends StepSolver {
|
|||||||
//concatenate the content of the results into a single string
|
//concatenate the content of the results into a single string
|
||||||
String resultString = String.join("\n", result);
|
String resultString = String.join("\n", result);
|
||||||
this.scenarioExecution.getExecSharedMap().put(this.outputField, resultString);
|
this.scenarioExecution.getExecSharedMap().put(this.outputField, resultString);
|
||||||
|
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||||
|
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||||
|
|
||||||
return this.scenarioExecution;
|
return this.scenarioExecution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ public class QueryNeo4JSolver extends StepSolver {
|
|||||||
this.scenarioExecution.getExecSharedMap().put(this.outputField, "Error executing query: " + e.getMessage());
|
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;
|
return this.scenarioExecution;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,14 @@ public class StepSolver {
|
|||||||
|
|
||||||
public ScenarioExecution solveStep(){
|
public ScenarioExecution solveStep(){
|
||||||
System.out.println("Solving step: " + this.step.getName());
|
System.out.println("Solving step: " + this.step.getName());
|
||||||
|
|
||||||
|
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||||
|
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||||
|
|
||||||
return this.scenarioExecution;
|
return this.scenarioExecution;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public void init(ScenarioStep step, ScenarioExecution scenarioExecution, VectorStore vectorStore,ChatModel chatModel,Driver graphDriver,Neo4JUitilityService neo4JUitilityService){
|
public void init(ScenarioStep step, ScenarioExecution scenarioExecution, VectorStore vectorStore,ChatModel chatModel,Driver graphDriver,Neo4JUitilityService neo4JUitilityService){
|
||||||
this.scenarioExecution = scenarioExecution;
|
this.scenarioExecution = scenarioExecution;
|
||||||
this.step = step;
|
this.step = step;
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"folders": [
|
|
||||||
{
|
|
||||||
"path": "../../../../../../../../apollo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "hermione",
|
|
||||||
"path": "../../../../../../.."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "hermione-fe",
|
|
||||||
"path": "../../../../../../../../hermione-fe"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"settings": {}
|
|
||||||
}
|
|
||||||
15
src/main/resources/workflow.json
Normal file
15
src/main/resources/workflow.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user