Skip to content

Commit

Permalink
Merge pull request #39 from RobJenks/generic-models
Browse files Browse the repository at this point in the history
Add common BPMN execution model interface
  • Loading branch information
RobJenks authored Jun 14, 2024
2 parents 3f4c93e + 3353a62 commit 3f0f57c
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.rj.modelgen.bpmn.models.generation;

import reactor.core.publisher.Mono;

import java.util.Map;

public interface BpmnGenerationExecutionModel {

Mono<BpmnGenerationResult> executeModel(String sessionId, String request, Map<String, Object> data);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.rj.modelgen.bpmn.models.generation.base;

import org.rj.modelgen.bpmn.intrep.model.BpmnIntermediateModel;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationExecutionModel;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationExecutionModelOptions;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationResult;
import org.rj.modelgen.bpmn.models.generation.base.context.BpmnGenerationPromptGenerator;
@@ -14,10 +15,11 @@
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

public class BpmnGenerationExecutionModel extends ModelInterfaceStateMachine {
public static BpmnGenerationExecutionModel create(ModelInterface modelInterface, ModelSchema modelSchema,
BpmnGenerationExecutionModelOptions options) {
public class BpmnGenerationBaseExecutionModel extends ModelInterfaceStateMachine implements BpmnGenerationExecutionModel {
public static BpmnGenerationBaseExecutionModel create(ModelInterface modelInterface, ModelSchema modelSchema,
BpmnGenerationExecutionModelOptions options) {
final var modelClass = BpmnIntermediateModel.class;

final var generationPrompt = options.shouldUseHistory()
@@ -52,15 +54,16 @@ public static BpmnGenerationExecutionModel create(ModelInterface modelInterface,
new ModelInterfaceTransitionRule(stateValidateBpmnModelCorrectness, BpmnGenerationSignals.CompleteGeneration, stateComplete)
));

return new BpmnGenerationExecutionModel(modelInterface, states, rules);
return new BpmnGenerationBaseExecutionModel(modelInterface, states, rules);
}

private BpmnGenerationExecutionModel(ModelInterface modelInterface, List<ModelInterfaceState> states,
ModelInterfaceTransitionRules rules) {
private BpmnGenerationBaseExecutionModel(ModelInterface modelInterface, List<ModelInterfaceState> states,
ModelInterfaceTransitionRules rules) {
super(modelInterface, states, rules);
}

public Mono<BpmnGenerationResult> executeModel(String sessionId, String request) {
@Override
public Mono<BpmnGenerationResult> executeModel(String sessionId, String request, Map<String, Object> data) {
final var initialState = ModelInterfaceState.defaultStateId(StartBpmnGeneration.class);

final var input = new BpmnGenerationModelInputPayload(sessionId, request);
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.rj.modelgen.bpmn.intrep.model.BpmnIntermediateModel;
import org.rj.modelgen.bpmn.intrep.schema.BpmnIntermediateModelSchema;
import org.rj.modelgen.bpmn.intrep.validation.BpmnIntermediateModelSanitizer;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationExecutionModel;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationResult;
import org.rj.modelgen.bpmn.models.generation.base.data.BpmnGenerationModelInputPayload;
import org.rj.modelgen.bpmn.models.generation.base.states.BpmnGenerationComplete;
@@ -27,7 +28,8 @@
import java.util.function.Function;

public class BpmnMultiLevelGenerationModel extends MultiLevelGenerationModel<BpmnIntermediateModel, BpmnIntermediateModel,
BpmnModelInstance, BpmnComponentLibrary, BpmnGenerationResult> {
BpmnModelInstance, BpmnComponentLibrary, BpmnGenerationResult>
implements BpmnGenerationExecutionModel {

public static BpmnMultiLevelGenerationModel create(ModelInterface modelInterface) {
final var promptGenerator = new BpmnGenerationMultiLevelPromptGenerator();
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import org.camunda.bpm.model.bpmn.Bpmn;
import org.rj.modelgen.bpmn.intrep.schema.BpmnIntermediateModelSchema;
import org.rj.modelgen.bpmn.models.generation.base.BpmnGenerationExecutionModel;
import org.rj.modelgen.bpmn.models.generation.base.BpmnGenerationBaseExecutionModel;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationExecutionModelOptions;
import org.rj.modelgen.bpmn.models.generation.BpmnGenerationResult;
import org.rj.modelgen.bpmn.models.generation.multilevel.BpmnMultiLevelGenerationModel;
@@ -41,14 +41,14 @@ public CodegenServiceApplication() {
this.bpmnGenerationModel = buildMultiPhaseModel(); // buildModel();
}

private BpmnGenerationExecutionModel buildModel() {
private BpmnGenerationBaseExecutionModel buildModel() {
final var modelInterface = new OpenAIModelInterface.Builder()
.withApiKeyGenerator(() -> Util.loadStringResource(tokenPath))
.build();

final var modelSchema = new BpmnIntermediateModelSchema();

return BpmnGenerationExecutionModel.create(modelInterface, modelSchema, BpmnGenerationExecutionModelOptions.defaultOptions());
return BpmnGenerationBaseExecutionModel.create(modelInterface, modelSchema, BpmnGenerationExecutionModelOptions.defaultOptions());
}

private BpmnMultiLevelGenerationModel buildMultiPhaseModel() {

0 comments on commit 3f0f57c

Please sign in to comment.