impl condititionalDebugAdapter class
This commit is contained in:
parent
65d6f9d75a
commit
dc7d0a5998
4 changed files with 3312 additions and 5 deletions
|
|
@ -4,10 +4,14 @@ import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.imixs.ai.ImixsAIContextHandler;
|
||||||
|
import org.imixs.ai.workflow.ImixsAIPromptService;
|
||||||
|
import org.imixs.ai.workflow.ImixsAIResultEvent;
|
||||||
import org.imixs.ai.workflow.OpenAIAPIService;
|
import org.imixs.ai.workflow.OpenAIAPIService;
|
||||||
import org.imixs.workflow.ItemCollection;
|
import org.imixs.workflow.ItemCollection;
|
||||||
import org.imixs.workflow.engine.ConditionalExpressionEvent;
|
import org.imixs.workflow.engine.ConditionalExpressionEvent;
|
||||||
import org.imixs.workflow.engine.WorkflowService;
|
import org.imixs.workflow.engine.WorkflowService;
|
||||||
|
import org.imixs.workflow.exceptions.AdapterException;
|
||||||
import org.imixs.workflow.exceptions.PluginException;
|
import org.imixs.workflow.exceptions.PluginException;
|
||||||
import org.imixs.workflow.faces.data.WorkflowEvent;
|
import org.imixs.workflow.faces.data.WorkflowEvent;
|
||||||
|
|
||||||
|
|
@ -16,6 +20,29 @@ import jakarta.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug class to test CDI Events of type BPMNConditionEvent
|
* Debug class to test CDI Events of type BPMNConditionEvent
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Note: To run this plugin the conditional configuration should look like this
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
<imixs-ai name="CONDITION">
|
||||||
|
<debug>true</debug>
|
||||||
|
<endpoint><propertyvalue>llm.service.endpoint</propertyvalue></endpoint>
|
||||||
|
<result-event>BOOLEAN</result-event>
|
||||||
|
<PromptDefinition>
|
||||||
|
<prompt_options>{"n_predict": 16, "temperature": 0 }</prompt_options>
|
||||||
|
<prompt role="system"><![CDATA[
|
||||||
|
You are a sales expert. You evaluate the following condition to 'true' or 'false'. ]]>
|
||||||
|
</prompt>
|
||||||
|
<prompt role="user"><![CDATA[
|
||||||
|
Is Germany an EU member country? ]]>
|
||||||
|
</prompt>
|
||||||
|
</PromptDefinition>
|
||||||
|
</imixs-ai>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class ConditionalDebugAdapter implements Serializable {
|
public class ConditionalDebugAdapter implements Serializable {
|
||||||
|
|
||||||
|
|
@ -24,23 +51,46 @@ public class ConditionalDebugAdapter implements Serializable {
|
||||||
@Inject
|
@Inject
|
||||||
protected WorkflowService workflowService;
|
protected WorkflowService workflowService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ImixsAIPromptService imixsAIPromptService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected OpenAIAPIService llmService;
|
protected OpenAIAPIService llmService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ImixsAIContextHandler imixsAIContextHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method
|
* Test method
|
||||||
*
|
*
|
||||||
* @param conditionEvent
|
* @param conditionEvent
|
||||||
* @throws PluginException
|
* @throws PluginException
|
||||||
|
* @throws AdapterException
|
||||||
*/
|
*/
|
||||||
public void onConditionEvent(@Observes ConditionalExpressionEvent conditionalEvent) throws PluginException {
|
public void onConditionEvent(@Observes ConditionalExpressionEvent conditionalEvent)
|
||||||
|
throws PluginException, AdapterException {
|
||||||
|
|
||||||
List<ItemCollection> llmConditionDefinitions;
|
List<ItemCollection> llmConditionDefinitions;
|
||||||
|
boolean llmAPIDebug = false;
|
||||||
|
|
||||||
llmConditionDefinitions = workflowService.evalXMLExpressionList(
|
llmConditionDefinitions = workflowService.evalXMLExpressionList(
|
||||||
conditionalEvent.getCondition(), "imixs-ai", "CONDITION", conditionalEvent.getWorkitem(), true);
|
conditionalEvent.getCondition(), "imixs-ai", "CONDITION", conditionalEvent.getWorkitem(), true);
|
||||||
|
|
||||||
for (ItemCollection promptDefinition : llmConditionDefinitions) {
|
for (ItemCollection promptDefinition : llmConditionDefinitions) {
|
||||||
|
String llmAPIEndpoint = imixsAIPromptService.parseLLMEndpointByBPMN(promptDefinition);
|
||||||
|
String llmAPIResultEvent = promptDefinition.getItemValueString("result-event");
|
||||||
|
String llmAPIResultItem = promptDefinition.getItemValueString("result-item");
|
||||||
|
if ("true".equalsIgnoreCase(promptDefinition.getItemValueString("debug"))) {
|
||||||
|
llmAPIDebug = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get PromptDefintion template...
|
||||||
|
String prompt = "<PromptDefinition>" + promptDefinition.getItemValueString("PromptDefinition")
|
||||||
|
+ "</PromptDefinition>";
|
||||||
|
logger.info("PromptDefinition=" + prompt);
|
||||||
|
|
||||||
|
imixsAIContextHandler.setWorkItem(conditionalEvent.getWorkitem());
|
||||||
|
imixsAIContextHandler.addPromptDefinition(prompt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,4 +101,36 @@ public class ConditionalDebugAdapter implements Serializable {
|
||||||
logger.info("We observe a WorkflowEvent");
|
logger.info("We observe a WorkflowEvent");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This observer method reacts on a ImixsAI Result event and evaluates a boolean
|
||||||
|
* value
|
||||||
|
*
|
||||||
|
* Note: To run this adapter the configuration should look like this
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
<imixs-ai name="CONDITION">
|
||||||
|
<endpoint><propertyvalue>llm.service.endpoint</propertyvalue></endpoint>
|
||||||
|
<result-event>BOOLEAN</result-event>
|
||||||
|
</imixs-ai>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
public void onEvent(@Observes ImixsAIResultEvent event) {
|
||||||
|
if (event.getWorkitem() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we only adapt the result in case the eventType===JSON
|
||||||
|
if ("BOOLEAN".equalsIgnoreCase(event.getEventType())) {
|
||||||
|
// get result string
|
||||||
|
String booleanString = event.getPromptResult();
|
||||||
|
|
||||||
|
logger.info("Prompt Boolean Result= " + booleanString);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -73,7 +73,7 @@
|
||||||
<org.imixs.archive.version>3.1.3</org.imixs.archive.version>
|
<org.imixs.archive.version>3.1.3</org.imixs.archive.version>
|
||||||
<org.imixs.marty.version>5.1.0</org.imixs.marty.version>
|
<org.imixs.marty.version>5.1.0</org.imixs.marty.version>
|
||||||
<org.imixs.adapter.version>3.2.1-SNAPSHOT</org.imixs.adapter.version>
|
<org.imixs.adapter.version>3.2.1-SNAPSHOT</org.imixs.adapter.version>
|
||||||
<org.imixs.ai.version>1.1.3-SNAPSHOT</org.imixs.ai.version>
|
<org.imixs.ai.version>1.1.4-SNAPSHOT</org.imixs.ai.version>
|
||||||
<org.imixs.metrics.version>1.0.0-SNAPSHOT</org.imixs.metrics.version>
|
<org.imixs.metrics.version>1.0.0-SNAPSHOT</org.imixs.metrics.version>
|
||||||
<org.imixs.signature.version>1.0.0</org.imixs.signature.version>
|
<org.imixs.signature.version>1.0.0</org.imixs.signature.version>
|
||||||
<net.sf.saxon.version>9.9.1-4</net.sf.saxon.version>
|
<net.sf.saxon.version>9.9.1-4</net.sf.saxon.version>
|
||||||
|
|
|
||||||
3225
workflow/en/invoice-demo-c-1.0.0.bpmn
Normal file
3225
workflow/en/invoice-demo-c-1.0.0.bpmn
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1968,8 +1968,8 @@ Product Details:
|
||||||
</bpmndi:BPMNLabel>
|
</bpmndi:BPMNLabel>
|
||||||
</bpmndi:BPMNShape>
|
</bpmndi:BPMNShape>
|
||||||
<bpmndi:BPMNEdge bpmnElement="association_JGXYyg" id="BPMNEdge_bHPaEg" sourceElement="BPMNShape_0OS0TQ" targetElement="BPMNShape_3PbNFQ">
|
<bpmndi:BPMNEdge bpmnElement="association_JGXYyg" id="BPMNEdge_bHPaEg" sourceElement="BPMNShape_0OS0TQ" targetElement="BPMNShape_3PbNFQ">
|
||||||
<di:waypoint x="388.0" y="432.0"/>
|
<di:waypoint x="387.0" y="425.0"/>
|
||||||
<di:waypoint x="351.0" y="432.0"/>
|
<di:waypoint x="351.0" y="425.0"/>
|
||||||
<di:waypoint x="351.0" y="570.0"/>
|
<di:waypoint x="351.0" y="570.0"/>
|
||||||
</bpmndi:BPMNEdge>
|
</bpmndi:BPMNEdge>
|
||||||
<bpmndi:BPMNShape bpmnElement="event_y0smQw" id="BPMNShape_JqPTSA">
|
<bpmndi:BPMNShape bpmnElement="event_y0smQw" id="BPMNShape_JqPTSA">
|
||||||
|
|
@ -2079,7 +2079,7 @@ Product Details:
|
||||||
<bpmndi:BPMNShape bpmnElement="event_zsQpoQ" id="BPMNShape_4N0zng">
|
<bpmndi:BPMNShape bpmnElement="event_zsQpoQ" id="BPMNShape_4N0zng">
|
||||||
<dc:Bounds height="36.0" width="36.0" x="567.0" y="807.0"/>
|
<dc:Bounds height="36.0" width="36.0" x="567.0" y="807.0"/>
|
||||||
<bpmndi:BPMNLabel id="BPMNLabel_8IelbQ">
|
<bpmndi:BPMNLabel id="BPMNLabel_8IelbQ">
|
||||||
<dc:Bounds height="20.0" width="100.0" x="535.0" y="866.0"/>
|
<dc:Bounds height="20.0" width="100.0" x="535.0" y="846.0"/>
|
||||||
</bpmndi:BPMNLabel>
|
</bpmndi:BPMNLabel>
|
||||||
</bpmndi:BPMNShape>
|
</bpmndi:BPMNShape>
|
||||||
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_JZ6sYQ" id="BPMNEdge_zqEK5w" sourceElement="BPMNShape_4N0zng" targetElement="BPMNShape_qvXTpw">
|
<bpmndi:BPMNEdge bpmnElement="sequenceFlow_JZ6sYQ" id="BPMNEdge_zqEK5w" sourceElement="BPMNShape_4N0zng" targetElement="BPMNShape_qvXTpw">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue