Skip to content

Commit

Permalink
Merge branch 'quarkiverse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
humcqc authored Jun 16, 2024
2 parents 51c8f39 + 32fcbc6 commit 6f2b938
Show file tree
Hide file tree
Showing 51 changed files with 1,533 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkiverse.langchain4j.deployment.devui;

import java.util.Collections;
import java.util.Map;

import io.quarkus.builder.item.MultiBuildItem;

public final class AdditionalDevUiCardBuildItem extends MultiBuildItem {

private final String title;
private final String icon;
private final String componentLink;
private final Map<String, Object> buildTimeData;

public AdditionalDevUiCardBuildItem(String title, String icon, String componentLink) {
this(title, icon, componentLink, Collections.emptyMap());
}

public AdditionalDevUiCardBuildItem(String title, String icon, String componentLink, Map<String, Object> buildTimeData) {
this.title = title;
this.icon = icon;
this.componentLink = componentLink;
this.buildTimeData = buildTimeData;
}

public String getTitle() {
return title;
}

public String getIcon() {
return icon;
}

public String getComponentLink() {
return componentLink;
}

public Map<String, Object> getBuildTimeData() {
return buildTimeData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ CardPageBuildItem cardPage(List<DeclarativeAiServiceBuildItem> aiServices,
List<InProcessEmbeddingBuildItem> inProcessEmbeddingModelBuildItems,
List<EmbeddingStoreBuildItem> embeddingStoreBuildItem,
List<SelectedChatModelProviderBuildItem> chatModelProviders,
Optional<InMemoryEmbeddingStoreBuildItem> inMemoryEmbeddingStoreBuildItem) {
Optional<InMemoryEmbeddingStoreBuildItem> inMemoryEmbeddingStoreBuildItem,
List<AdditionalDevUiCardBuildItem> additionalDevUiCardBuildItems) {
CardPageBuildItem card = new CardPageBuildItem();
addAiServicesPage(card, aiServices);
if (toolsMetadataBuildItem != null) {
Expand All @@ -50,6 +51,15 @@ CardPageBuildItem cardPage(List<DeclarativeAiServiceBuildItem> aiServices,
if (!chatModelProviders.isEmpty()) {
addChatPage(card, aiServices);
}

for (AdditionalDevUiCardBuildItem additionalDevUiCardBuildItem : additionalDevUiCardBuildItems) {
card.addPage(Page.webComponentPageBuilder()
.title(additionalDevUiCardBuildItem.getTitle())
.icon(additionalDevUiCardBuildItem.getIcon())
.componentLink(additionalDevUiCardBuildItem.getComponentLink()));

additionalDevUiCardBuildItem.getBuildTimeData().forEach((k, v) -> card.addBuildTimeData(k, v));
}
return card;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkiverse.langchain4j.deployment.devui;

import io.quarkiverse.langchain4j.runtime.devui.OpenWebUIJsonRPCService;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;

public final class OpenWebUIDevUIProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
void registerOpenWebUiCard(BuildProducer<JsonRPCProvidersBuildItem> jsonRPCProviders,
CuratedApplicationShutdownBuildItem closeBuildItem) {
jsonRPCProviders.produce(new JsonRPCProvidersBuildItem(OpenWebUIJsonRPCService.class));
closeBuildItem.addCloseTask(OpenWebUIJsonRPCService.CLOSE_TASK, true);
}
}
90 changes: 79 additions & 11 deletions core/deployment/src/main/resources/dev-ui/qwc-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '@vaadin/progress-bar';
import '@vaadin/text-field';
import '@vaadin/icon';
import '@vaadin/icons';
import 'qui-alert';
import { JsonRpc } from 'jsonrpc';
import { systemMessages } from 'build-time-data';

Expand Down Expand Up @@ -69,7 +70,10 @@ export class QwcChat extends LitElement {
_systemMessages: {state: true},
_systemMessageDisabled: {state: true},
_ragEnabled: {state: true},
_showToolRelatedMessages: {state: true}
_streamingChatSupported: {state: true},
_streaminChatEnabled: {state: true},
_showToolRelatedMessages: {state: true},
_observer: {state:false},
}

constructor() {
Expand All @@ -83,8 +87,29 @@ export class QwcChat extends LitElement {
this._unfilteredChatItems = [];
this._chatItems = [];
this.jsonRpc.reset({systemMessage: this._systemMessage});
this._streamingChatSupported = this.jsonRpc.isStreamingChatSupported();
this._streamingChatEnabled = this._streamingChatSupported && !this._ragEnabled;
}

_connect() {
}

_disconnect() {
if (this._observer) {
this._observer.unsubscribe();
}
}

connectedCallback() {
super.connectedCallback();
this._connect();
}

disconnectedCallback() {
this._disconnect();
super.disconnectedCallback();
}

render() {
this._filterChatItems();
return html`
Expand All @@ -96,6 +121,15 @@ export class QwcChat extends LitElement {
<div><vaadin-checkbox checked label="Enable Retrieval Augmented Generation (if a RetrievalAugmentor bean exists)"
@change="${(event) => {
this._ragEnabled = event.target.checked;
this._streamingChatEnabled = this._streamingChatEnabled && !this._ragEnabled;
this.render();
}}"/></div>
<div><vaadin-checkbox label="Enable Streaming Chat (if supported by model & rag disabled)"
class="${this._streamingChatSupported ? 'show' : 'hide'}"
?checked="${this._streamingChatEnabled}"
?disabled="${!this._streamingChatSupported || this._ragEnabled}"
@change="${(event) => {
this._streamingChatEnabled = event.target.checked;
this.render();
}}"/></div>
${this._renderSystemPane()}
Expand All @@ -119,7 +153,7 @@ export class QwcChat extends LitElement {
</vaadin-text-field>
</div>`;
}

_checkForEnterOrTab(e){
if ((e.which == 13 || e.which == 0)){
this._cementSystemMessage();
Expand Down Expand Up @@ -159,13 +193,40 @@ export class QwcChat extends LitElement {
this._cementSystemMessage();
this._addUserMessage(message);
this._showProgressBar();

this.jsonRpc.chat({message: message, ragEnabled: this._ragEnabled}).then(jsonRpcResponse => {
this._showResponse(jsonRpcResponse);
}).catch((error) => {
this._showError(error);
this._hideProgressBar();
});

if (this._streamingChatEnabled) {
var msg = "";
var index = this._addBotMessage(msg);
try {
this._observer = this.jsonRpc.streamingChat({message: message, ragEnabled: this._ragEnabled})
.onNext(jsonRpcResponse => {
if (jsonRpcResponse.result.error) {
this._showError(jsonRpcResponse.result.error);
this._hideProgressBar();
} else if (jsonRpcResponse.result.message) {
this._updateMessage(index, jsonRpcResponse.result.message);
this._hideProgressBar();
} else {
msg += jsonRpcResponse.result.token;
this._updateMessage(index, msg);
}
})
.onError((error) => {
this._showError(error);
this._hideProgressBar();
});
} catch(error) {
this._showError(error);
this._hideProgressBar();
}
} else {
this.jsonRpc.chat({message: message, ragEnabled: this._ragEnabled}).then(jsonRpcResponse => {
this._showResponse(jsonRpcResponse);
}).catch((error) => {
this._showError(error);
this._hideProgressBar();
});
}
}

}
Expand Down Expand Up @@ -248,7 +309,12 @@ status = ${item.toolExecutionResult.text}`);
}

_addBotMessage(message){
this._addMessage(message, "AI", 3);
return this._addMessage(message, "AI", 3);
}

_updateMessage(index, message) {
this._unfilteredChatItems[index].text = message;
this._unfilteredChatItems = [...this._unfilteredChatItems];
}

_addUserMessage(message){
Expand All @@ -262,7 +328,7 @@ status = ${item.toolExecutionResult.text}`);
}

_addMessage(message, user, colorIndex){
this._addMessageItem(this._createNewItem(message, user, colorIndex));
return this._addMessageItem(this._createNewItem(message, user, colorIndex));
}

_createNewItem(message, user, colorIndex) {
Expand All @@ -284,9 +350,11 @@ status = ${item.toolExecutionResult.text}`);
}

_addMessageItem(newItem) {
var newIndex = this._unfilteredChatItems.length;
this._unfilteredChatItems = [
...this._unfilteredChatItems,
newItem];
return newIndex;
}

_hideNewConversationButton(){
Expand Down
Loading

0 comments on commit 6f2b938

Please sign in to comment.