Skip to content

Commit

Permalink
impl async function
Browse files Browse the repository at this point in the history
Issue #610
  • Loading branch information
rsoika committed Oct 14, 2024
1 parent 75afd89 commit 77ef9d9
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ hourly=Stündlich
type=Typ
summary=Zusammenfassung
ai=KI
ai.prompt=Wie kann ich Ihnen helfen?

####################
# Month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ hourly=Hourly
type=Type
summary=Summary
ai=AI
ai.prompt=How can I help you?

####################
# Month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,41 @@
.imixs-llm:focus,
.imixs-date.imixs-llm:focus {
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 0 8px rgba(244, 160, 97, 0.55) !important;
}




.imixs-ai-loader {
border: 6px solid #f3f3f3;
border-top-color: rgb(243, 243, 243);
border-top-style: solid;
border-top-width: 6px;
border-radius: 50%;
border-top: 6px solid #78b8ce;
width: 30px;
height: 30px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(360deg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<f:subview xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:i="http://xmlns.jcp.org/jsf/composite/imixs">

<!-- Integration of Imixs-AI
-->
<dl>
<dt style="clear: left;">
<h:outputText value="Prompt:" />
</dt>
<dd>
<f:ajax render="chatlist">
<h:inputTextarea required="false" value="#{workflowController.workitem.item['ai.chat.prompt']}"
id="description_id" style="height: 5em; width: 95%">
</h:inputTextarea>
<h:commandButton value="#{message.send}" actionListener="#{aiController.sendAsync}" />
</f:ajax>
</dd>
</dl>

<h:panelGroup layout="block" id="chatlist" style="margin-bottom:10px;">
Chat History....
<br />
<ui:repeat var="answer" value="#{aiController.chatHistory}">
#{answer}
<hr />
</ui:repeat>
</h:panelGroup>

<h:commandScript name="refreshStockData" render="chatlist" />
<h:outputScript>
console.log('ich mache irgendwas');
if (refreshStockData) {
console.log('die methode scheint es zu geben');
}
setInterval(refreshStockData, 500); // Refresh every 500ms
</h:outputScript>

</f:subview>
Original file line number Diff line number Diff line change
@@ -1,30 +1,77 @@
<f:subview xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:i="http://xmlns.jcp.org/jsf/composite/imixs">
xmlns:a="http://xmlns.jcp.org/jsf/passthrough" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:i="http://xmlns.jcp.org/jsf/composite/imixs">

<!-- Integration of Imixs-AI
-->
<dl>
<dt style="clear: left;">
<h:outputText value="Prompt:" />
</dt>

<dd>
<f:ajax render="chatlist">
<h:inputTextarea required="false" value="#{workflowController.workitem.item['ai.chat.prompt']}"
id="description_id" style="height: 5em; width: 95%">
</h:inputTextarea>
<h:commandButton value="#{message.send}" actionListener="#{aiController.send}" />
</f:ajax>
<h:inputTextarea required="false" value="#{workflowController.workitem.item['ai.chat.prompt']}"
a:placeholder="#{message['ai.prompt']}" id="promptInput" style="height: 5em; width: 95%">
</h:inputTextarea>
<h:commandButton value="#{message.send}" actionListener="#{aiController.sendAsync}">
<f:ajax execute="promptInput" render="@none" onevent="handleSendEvent" />
</h:commandButton>
</dd>
</dl>

<h:panelGroup layout="block" id="chatlist" style="margin-bottom:10px;">
Chat History....
<br />
<ui:repeat var="answer" value="#{aiController.chatHistory}">
#{answer}
<!-- 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>

<!-- Imixs AI Chat history-->
<h:panelGroup layout="block" id="imixs_ai_chatlist" style="margin-bottom:10px;">
<ui:repeat var="aiResultEntry" value="#{aiController.aiChatHistory}">
#{aiResultEntry}
<hr />
</ui:repeat>
</h:panelGroup>

<h:commandScript name="refreshAILifeResult" render="aiResultStream" onevent="handleRefreshEvent" />
<h:commandScript name="refreshAIChatHistory" render="imixs_ai_chatlist" />
<script type="text/javascript">
/*<![CDATA[*/
var refreshInterval;
function handleSendEvent(data) {
if (data.status === "begin") {
console.log('streaming started....');
startRefreshing();
}
}
function handleRefreshEvent(data) {
if (data.status === 'success') {
console.log('handle refreshEvent: ' + data.responseText);
if (data.responseText && data.responseText.indexOf('imixs.ai.stream.completed') > -1) {
stopRefreshing();
}
}
}
function startRefreshing() {
console.log('Start Refreshing...');
refreshInterval = setInterval(refreshAILifeResult, 100);
// show imixs_ai_life_stream
lifeStreamBlock = document.querySelector('[id$=":imixs_ai_life_stream"]');
if (lifeStreamBlock) {
lifeStreamBlock.style.display = '';
}

}
function stopRefreshing() {
console.log('Stop Refreshing!');
clearInterval(refreshInterval);
refreshAIChatHistory();
// hide imixs_ai_life_stream
lifeStreamBlock = document.querySelector('[id$=":imixs_ai_life_stream"]');
if (lifeStreamBlock) {
lifeStreamBlock.style.display = 'none';
}
}
/*]]>*/
</script>

</f:subview>
Loading

0 comments on commit 77ef9d9

Please sign in to comment.