Skip to content

Commit

Permalink
CLI UI: add mermaid diagram (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi authored Oct 11, 2023
1 parent 462c7e4 commit 69ce6e9
Show file tree
Hide file tree
Showing 14 changed files with 740 additions and 31,312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package ai.langstream.cli.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -67,6 +68,8 @@ public static class Gateway {
String type;
List<String> parameters;
Map<String, Object> authentication;

@JsonProperty("chat-options")
Map<String, Object> chatOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -60,7 +61,8 @@ public abstract class BaseCmd implements Runnable {
public enum Formats {
raw,
json,
yaml
yaml,
mermaid
}

protected static final ObjectMapper yamlConfigReader = new ObjectMapper(new YAMLFactory());
Expand Down Expand Up @@ -572,4 +574,15 @@ protected String getAppDescriptionOrLoad(String application) {
return applicationDescriptions.computeIfAbsent(
application, app -> getClient().applications().get(application, false));
}

protected void ensureFormatIn(Formats value, Formats... allowed) {
final List<Formats> asList = Arrays.stream(allowed).collect(Collectors.toList());
if (!asList.contains(value)) {
throw new IllegalArgumentException(
String.format(
"Format %s is not allowed. Allowed formats are: %s",
value,
asList.stream().map(Enum::name).collect(Collectors.joining(","))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public static class DeployApplicationCmd extends AbstractDeployApplicationCmd {

@CommandLine.Option(
names = {"-o"},
description = "Output format for dry-run mode.")
private Formats format = Formats.raw;
description =
"Output format for dry-run mode. Formats are: yaml, json. Default value is yaml.")
private Formats format = Formats.yaml;

@Override
String applicationId() {
Expand Down Expand Up @@ -98,6 +99,7 @@ boolean isDryRun() {

@Override
Formats format() {
ensureFormatIn(format, Formats.json, Formats.yaml);
return format;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ public class GetApplicationCmd extends BaseApplicationCmd {
@CommandLine.Parameters(description = "ID of the application")
private String applicationId;

public enum GetAppFormats {
raw,
json,
yaml,
mermaid
}

@CommandLine.Option(
names = {"-o"},
description = "Output format")
private Formats format = Formats.raw;
description =
"Output format. Formats are: yaml, json, raw, mermaid. Default value is raw.")
private GetAppFormats format = GetAppFormats.raw;

@CommandLine.Option(
names = {"-s", "--stats"},
Expand All @@ -38,8 +46,12 @@ public class GetApplicationCmd extends BaseApplicationCmd {
@SneakyThrows
public void run() {
final String body = getClient().applications().get(applicationId, stats);
if (format == GetAppFormats.mermaid) {
log(MermaidAppDiagramGenerator.generate(body));
return;
}
print(
format,
Formats.valueOf(format.name()),
body,
ListApplicationCmd.COLUMNS_FOR_RAW,
ListApplicationCmd.getRawFormatValuesSupplier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public class ListApplicationCmd extends BaseApplicationCmd {

@CommandLine.Option(
names = {"-o"},
description = "Output format")
description = "Output format. Formats are: yaml, json, raw. Default value is raw.")
private Formats format = Formats.raw;

@Override
@SneakyThrows
public void run() {
ensureFormatIn(format, Formats.raw, Formats.json, Formats.yaml);
final String body = getClient().applications().list();
print(format, body, COLUMNS_FOR_RAW, getRawFormatValuesSupplier());
}
Expand Down
Loading

0 comments on commit 69ce6e9

Please sign in to comment.