Skip to content

Commit

Permalink
Allow multi-stage BPMN model to build on previous executions
Browse files Browse the repository at this point in the history
  • Loading branch information
RobJenks committed Jun 18, 2024
1 parent efc0269 commit 69c9789
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public String serialize(BpmnComponentLibrary library) {
.orElseGet(List::of)
.stream()
.map(BpmnComponent::serializeDetailLevel)
.collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n---\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public String serialize(BpmnComponentLibrary library) {
.orElseGet(List::of)
.stream()
.map(BpmnComponent::serializeHighLevel)
.collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n---\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ Other requirements:
* A node can only have ONE outbound connection, UNLESS it is an 'exclusiveGateway' node. As a result, you should use exclusiveGateway nodes to handling branching. They should be placed after a result is calculated which you want to branch on
* Your process should begin with a Start Event and end with one or more End Events

<#if CURRENT_STATE??>
You have previously generated the following model, which follows the schema above:
```
${CURRENT_STATE}
```
You should make the following updates to this model, and return the new full model as JSON (complying to the schema above):
```
${PROMPT}
```
<#else>
The model which you should generate in JSON form (complying to the given schema) is as follows:
```
${PROMPT}
```

</#if>
Return ONLY the JSON process data, with no other explanation or commentary.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ TComponentLibrary extends ComponentLibrary<?>> ModelData buildModelData(
final var stateExecuteHighLevel = new PrepareAndSubmitMLRequestForLevel<>(highLevelSchema, contextProvider,
highLevelPhaseConfig.getModelSanitizer(), modelPromptGenerator, MultiLevelModelPromptType.GenerateHighLevel,
componentLibrary, highLevelPhaseConfig.getComponentLibrarySelector(), highLevelPhaseConfig.getComponentLibrarySerializer())
//.withOverriddenModelSuccessResponse(Util.loadStringResource("generation-examples/multiLevel/example1/2-response-high-level.json"))
.withOverriddenModelSuccessResponse(Util.loadStringResource("generation-examples/multiLevel/example1/2-response-high-level.json"))
.withOverriddenId("executeHighLevel");

final var stateValidateHighLevel = new ValidateLlmIntermediateModelResponse(
Expand All @@ -87,7 +87,7 @@ TComponentLibrary extends ComponentLibrary<?>> ModelData buildModelData(
final var stateExecuteDetailLevel = new PrepareAndSubmitMLRequestForLevel<>(detailLevelSchema, contextProvider,
detailLevelPhaseConfig.getModelSanitizer(), modelPromptGenerator, MultiLevelModelPromptType.GenerateDetailLevel,
componentLibrary, detailLevelPhaseConfig.getComponentLibrarySelector(), detailLevelPhaseConfig.getComponentLibrarySerializer())
//.withOverriddenModelSuccessResponse(Util.loadStringResource("generation-examples/multiLevel/example1/4-response-detail-level.json"))
.withOverriddenModelSuccessResponse(Util.loadStringResource("generation-examples/multiLevel/example1/4-response-detail-level.json"))
.withOverriddenId("executeDetailLevel");
//final var stateReturnToHighLevelIfRequired = new { ... } // TODO
final var stateValidateDetailLevel = new ValidateLlmIntermediateModelResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.rj.modelgen.llm.prompt;

import org.apache.commons.lang3.StringUtils;
import org.rj.modelgen.llm.util.Util;

import java.util.Optional;

public class PromptSubstitution {
private final String existingString;
Expand Down Expand Up @@ -31,4 +34,17 @@ public String apply(String targetString) {

return StringUtils.replace(targetString, existingString, newString);
}

@Override
public String toString() {
return String.format("%s -> %s", componentToString(existingString), componentToString(newString));
}

private String componentToString(String comp) {
if (comp == null) {
return "<null>";
}

return String.format("\"%s\"", Util.displayStringWithMaxLength(comp, 50));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected List<PromptSubstitution> generatePromptSubstitutions(ModelSchema model
substitutionData.put(StandardPromptPlaceholders.PROMPT.getValue(), request);
substitutionData.put(StandardPromptPlaceholders.SCHEMA_CONTENT.getValue(), modelSchema.getSchemaContent());
substitutionData.put(StandardPromptPlaceholders.CURRENT_STATE.getValue(), context.getLatestModelEntry()
.orElseGet(() -> ContextEntry.forModel("{}")).getContent());
.orElseGet(() -> ContextEntry.forModel(null)).getContent());

// Allow subclasses to insert additional data. Will overwrite exiting placeholders if they exist
final var substitutions = substitutionData.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@ public static int estimateTokenSize(String string) {

return StringUtils.countMatches(string, ' ') + 1;
}

public static String displayStringWithMaxLength(String str, int maxLength) {
if (str.length() > maxLength) {
return str.substring(0, maxLength) + "...";
}

return str;
}
}

0 comments on commit 69c9789

Please sign in to comment.