-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from jmartisk/devui
Dev UI for Langchain4j
- Loading branch information
Showing
21 changed files
with
705 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ployment/src/main/java/io/quarkiverse/langchain4j/deployment/EmbeddingModelBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkiverse.langchain4j.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* Marker that an embedding model was registered in the CDI container. | ||
*/ | ||
public final class EmbeddingModelBuildItem extends MultiBuildItem { | ||
} |
9 changes: 9 additions & 0 deletions
9
...ployment/src/main/java/io/quarkiverse/langchain4j/deployment/EmbeddingStoreBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkiverse.langchain4j.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* Marker that an embedding store was registered in the CDI container. | ||
*/ | ||
public final class EmbeddingStoreBuildItem extends MultiBuildItem { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...eployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolsMetadataBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkiverse.langchain4j.deployment; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.quarkiverse.langchain4j.runtime.tool.ToolMethodCreateInfo; | ||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Holds metadata about tools discovered at build time | ||
*/ | ||
public final class ToolsMetadataBuildItem extends SimpleBuildItem { | ||
|
||
Map<String, List<ToolMethodCreateInfo>> metadata; | ||
|
||
public ToolsMetadataBuildItem(Map<String, List<ToolMethodCreateInfo>> metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
public Map<String, List<ToolMethodCreateInfo>> getMetadata() { | ||
return metadata; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/devui/AiServiceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkiverse.langchain4j.deployment.devui; | ||
|
||
import java.util.List; | ||
|
||
public class AiServiceInfo { | ||
|
||
private String clazz; | ||
private List<String> tools; | ||
|
||
public AiServiceInfo(String clazz, List<String> tools) { | ||
this.clazz = clazz; | ||
this.tools = tools; | ||
} | ||
|
||
public List<String> getTools() { | ||
return tools; | ||
} | ||
|
||
public String getClazz() { | ||
return clazz; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
.../src/main/java/io/quarkiverse/langchain4j/deployment/devui/Langchain4jDevUIProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package io.quarkiverse.langchain4j.deployment.devui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.quarkiverse.langchain4j.deployment.DeclarativeAiServiceBuildItem; | ||
import io.quarkiverse.langchain4j.deployment.EmbeddingModelBuildItem; | ||
import io.quarkiverse.langchain4j.deployment.EmbeddingStoreBuildItem; | ||
import io.quarkiverse.langchain4j.deployment.ToolsMetadataBuildItem; | ||
import io.quarkiverse.langchain4j.runtime.devui.EmbeddingStoreJsonRPCService; | ||
import io.quarkiverse.langchain4j.runtime.tool.ToolMethodCreateInfo; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.devui.spi.page.Page; | ||
|
||
public class Langchain4jDevUIProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
CardPageBuildItem cardPage(List<DeclarativeAiServiceBuildItem> aiServices, | ||
ToolsMetadataBuildItem toolsMetadataBuildItem, | ||
List<EmbeddingModelBuildItem> embeddingModelBuildItem, | ||
List<EmbeddingStoreBuildItem> embeddingStoreBuildItem) { | ||
CardPageBuildItem card = new CardPageBuildItem(); | ||
addAiServicesPage(card, aiServices); | ||
addToolsPage(card, toolsMetadataBuildItem); | ||
// for now, add the embedding store page only if there is a single embedding model and a single embedding store | ||
// if we allow more in the future, we need a way to specify which ones to use for the page | ||
if (embeddingModelBuildItem.size() == 1 && embeddingStoreBuildItem.size() == 1) { | ||
addEmbeddingStorePage(card); | ||
} | ||
return card; | ||
} | ||
|
||
private void addEmbeddingStorePage(CardPageBuildItem card) { | ||
card.addPage(Page.webComponentPageBuilder().title("Embedding store") | ||
.componentLink("qwc-embedding-store.js") | ||
.icon("font-awesome-solid:database")); | ||
} | ||
|
||
private void addAiServicesPage(CardPageBuildItem card, List<DeclarativeAiServiceBuildItem> aiServices) { | ||
List<AiServiceInfo> infos = new ArrayList<>(); | ||
for (DeclarativeAiServiceBuildItem aiService : aiServices) { | ||
List<String> tools = aiService.getToolDotNames().stream().map(dotName -> dotName.toString()).toList(); | ||
infos.add(new AiServiceInfo(aiService.getServiceClassInfo().name().toString(), tools)); | ||
} | ||
|
||
card.addBuildTimeData("aiservices", infos); | ||
card.addPage(Page.webComponentPageBuilder().title("AI Services") | ||
.componentLink("qwc-aiservices.js") | ||
.staticLabel(String.valueOf(aiServices.size())) | ||
.icon("font-awesome-solid:robot")); | ||
} | ||
|
||
private void addToolsPage(CardPageBuildItem card, ToolsMetadataBuildItem metadataBuildItem) { | ||
List<ToolMethodInfo> infos = new ArrayList<>(); | ||
Map<String, List<ToolMethodCreateInfo>> metadata = metadataBuildItem.getMetadata(); | ||
for (Map.Entry<String, List<ToolMethodCreateInfo>> toolClassEntry : metadata.entrySet()) { | ||
for (ToolMethodCreateInfo toolMethodCreateInfo : toolClassEntry.getValue()) { | ||
infos.add(new ToolMethodInfo(toolClassEntry.getKey(), | ||
toolMethodCreateInfo.getMethodName(), | ||
toolMethodCreateInfo.getToolSpecification().description())); | ||
} | ||
} | ||
card.addBuildTimeData("tools", infos); | ||
card.addPage(Page.webComponentPageBuilder().title("Tools") | ||
.componentLink("qwc-tools.js") | ||
.staticLabel(String.valueOf(infos.size())) | ||
.icon("font-awesome-solid:toolbox")); | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
void jsonRpcProviders(BuildProducer<JsonRPCProvidersBuildItem> producers, | ||
List<EmbeddingModelBuildItem> embeddingModelBuildItem, | ||
List<EmbeddingStoreBuildItem> embeddingStoreBuildItem) { | ||
if (embeddingModelBuildItem.size() == 1 && embeddingStoreBuildItem.size() == 1) { | ||
producers.produce(new JsonRPCProvidersBuildItem(EmbeddingStoreJsonRPCService.class)); | ||
} | ||
|
||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../deployment/src/main/java/io/quarkiverse/langchain4j/deployment/devui/ToolMethodInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkiverse.langchain4j.deployment.devui; | ||
|
||
public class ToolMethodInfo { | ||
|
||
private String className; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
public ToolMethodInfo(String className, String name, String description) { | ||
this.className = className; | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
core/deployment/src/main/resources/dev-ui/qwc-aiservices.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { LitElement, html, css} from 'lit'; | ||
import { JsonRpc } from 'jsonrpc'; | ||
import '@vaadin/icon'; | ||
import '@vaadin/button'; | ||
import '@vaadin/text-field'; | ||
import '@vaadin/text-area'; | ||
import '@vaadin/form-layout'; | ||
import '@vaadin/progress-bar'; | ||
import '@vaadin/checkbox'; | ||
import '@vaadin/grid'; | ||
import 'qui-alert'; | ||
import { columnBodyRenderer } from '@vaadin/grid/lit.js'; | ||
import '@vaadin/grid/vaadin-grid-sort-column.js'; | ||
|
||
import {aiservices} from 'build-time-data'; | ||
|
||
|
||
export class QwcAiservices extends LitElement { | ||
|
||
static styles = css` | ||
.button { | ||
cursor: pointer; | ||
} | ||
.clearIcon { | ||
color: orange; | ||
} | ||
.message { | ||
padding: 15px; | ||
text-align: center; | ||
margin-left: 20%; | ||
margin-right: 20%; | ||
border: 2px solid orange; | ||
border-radius: 10px; | ||
font-size: large; | ||
} | ||
`; | ||
|
||
static properties = { | ||
"_aiservices": {state: true}, | ||
"_message": {state: true} | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this._aiservices = aiservices; | ||
} | ||
|
||
render() { | ||
if (this._aiservices) { | ||
return this._renderAiServiceTable(); | ||
} else { | ||
return html`<span>Loading AI services...</span>`; | ||
} | ||
} | ||
|
||
_renderAiServiceTable() { | ||
return html` | ||
${this._message} | ||
<vaadin-grid .items="${this._aiservices}" class="datatable" theme="no-border"> | ||
<vaadin-grid-column auto-width | ||
header="Name" | ||
${columnBodyRenderer(this._nameRenderer, [])}> | ||
</vaadin-grid-column> | ||
<vaadin-grid-column auto-width | ||
header="Tools" | ||
${columnBodyRenderer(this._toolsRenderer, [])}> | ||
</vaadin-grid-column> | ||
</vaadin-grid>`; | ||
} | ||
|
||
_nameRenderer(aiservice) { | ||
return html`${aiservice.clazz}`; | ||
} | ||
|
||
_toolsRenderer(aiservice) { | ||
if (aiservice.tools && aiservice.tools.length > 0) { | ||
return html`<vaadin-vertical-layout> | ||
${aiservice.tools.map(tool => | ||
html`<div><code>${tool}</code></div>` | ||
)}</vaadin-vertical-layout>`; | ||
} | ||
} | ||
|
||
} | ||
customElements.define('qwc-aiservices', QwcAiservices); |
Oops, something went wrong.