Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
issue #610
  • Loading branch information
rsoika committed Oct 14, 2024
1 parent c285e37 commit 6426689
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 49 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@
</dl>

<!-- Imixs AI Life-Answering Block -->
<h:panelGroup layout="block" id="imixs_ai_life_stream" style="display:none;">
<pre style="overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;">
<div class="imixs-ai-loader"></div><span>...</span><h:outputText id="aiResultStream" value="#{aiController.streamResult}" escape="false" />
</pre>
<h:panelGroup layout="block" id="imixs_ai_life_stream" styleClass="imixs-ai-chat-history"
style="display:none;margin-top:5px;">

<div class="imixs-ai-chat-entry">
<div class="imixs-ai-chat-header">
<div class="imixs-ai-loader"></div>
<span>#{message.ai}</span>
</div>
<div class="imixs-ai-chat-content">
<div class="imixs-ai-answer"></div>
<pre
style="overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;">...<h:outputText id="aiResultStream" value="#{aiController.streamResult}" escape="false" /></pre>
</div>
</div>
</h:panelGroup>

<!-- Imixs AI Chat history-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,15 @@ public void onWorkflowEvent(@Observes WorkflowEvent workflowEvent) {
*/
public void sendAsync() throws PluginException {
ItemCollection workitem = workflowController.getWorkitem();
question = workitem.getItemValueString("ai.chat.prompt");
question = workitem.getItemValueString("ai.chat.prompt").trim();

if (question.isEmpty()) {
// no op
return;
}
logger.fine("question: " + question);
String prompt = buildContextPrompt(question);
JsonObject jsonPrompt = openAIAPIService.buildJsonPromptObject(prompt, true, null);

// starting async http request...
streamingFuture = CompletableFuture.runAsync(() -> {
try {
Expand Down Expand Up @@ -256,13 +260,16 @@ private String buildContextPrompt(String question) {
ItemCollection workitem = workflowController.getWorkitem();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");

String prompt = "[INST]";
// String prompt = "[INST]";
String prompt = "<s>";

prompt = "Geschäftsprozess: " + workitem.getWorkflowGroup() + "\n";
prompt += "Geschäftsprozess: " + workitem.getWorkflowGroup() + "\n";
prompt += "Erstellt: " + dateFormat.format(workitem.getItemValueDate(WorkflowKernel.CREATED)) + " von "
+ userController.getUserName(workitem.getItemValueString("$creator")) + " \n";
prompt += "Aktueller Status: " + workitem.getItemValueString(WorkflowKernel.WORKFLOWSTATUS) + "\n";

prompt += "\nVerlauf an Aktivitäten in diesem Geschäftsprozess: \n\n";

// chronical
List<Integer> years = chronicleController.getYears();
Collections.reverse(years);
Expand All @@ -272,6 +279,8 @@ private String buildContextPrompt(String question) {
for (int month : months) {
List<ChronicleEntity> chronicleEntries = chronicleController.getChroniclePerMonth(year, month);

Collections.reverse(chronicleEntries);

// prompt += "\n" + year + "/" + month + "\n\n";
for (ChronicleEntity entry : chronicleEntries) {
String user = userController.getUserName(entry.getUser());
Expand All @@ -281,7 +290,7 @@ private String buildContextPrompt(String question) {
// Date / User
prompt += dateFormat.format(entry.getDate()) + " - " + user + ": ";
String type = event.getItemValueString("type");
Date date = event.getItemValueDate("date");

String message = event.getItemValueString("message");
if ("comment".equals(type)) {
prompt += "Kommentar: " + message + "\n";
Expand All @@ -300,12 +309,18 @@ private String buildContextPrompt(String question) {
}
}
}
if ("imixs-ai".equals(type)) {
prompt += "Chat: " + message + "\n";
}
}
}
}
}

prompt += "[/INST]</s>\n[INST] " + question + "[/INST]";
// prompt += "[/INST]</s>\n[INST] " + question + "[/INST]";
prompt += "</s>\n[INST] " + question + "[/INST]";

System.out.println(prompt);
return prompt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ public int compare(List<?> entry1, List<?> entry2) {
addChronicleEntry(originChronicleList, entry);
}

/* collect Imixs-AI chat history */
if (workflowController.getWorkitem().hasItem(AIController.AI_CHAT_HISTORY)) {
List<ItemCollection> aiChatHistory = ChildItemController.explodeChildList(workflowController.getWorkitem(),
AIController.AI_CHAT_HISTORY);
// change order
Collections.reverse(aiChatHistory);
for (ItemCollection aiEntry : aiChatHistory) {
ItemCollection entry = new ItemCollection();
entry.replaceItemValue("date", aiEntry.getItemValueDate("date"));
entry.replaceItemValue("user", aiEntry.getItemValueString("user"));
String message = "Question: \n" + aiEntry.getItemValueString("question");
message += "\nAnswer: \n" + aiEntry.getItemValueString("answer");
entry.replaceItemValue("message", message);
entry.replaceItemValue("type", "imixs-ai");
addChronicleEntry(originChronicleList, entry);
}
}

/* collect Attachments */
List<ItemCollection> dmsList = dmsController.getDmsList();
for (ItemCollection dmsEntry : dmsList) {
Expand Down

0 comments on commit 6426689

Please sign in to comment.