Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[awscurl] Allows override stream parameter for dataset #1895

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions awscurl/src/main/java/ai/djl/awscurl/AwsCurl.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,20 @@ private void addToDataSet(String data) {
if (element.isJsonObject()) {
JsonObject obj = element.getAsJsonObject();
JsonObject param = obj.getAsJsonObject("parameters");
JsonObject targetParam = extraParameters;
if (extraParameters.has("parameters")) {
targetParam = extraParameters.getAsJsonObject("parameters");
}
if (param == null) {
obj.add("parameters", extraParameters);
obj.add("parameters", targetParam);
} else {
for (Map.Entry<String, JsonElement> entry : extraParameters.entrySet()) {
for (Map.Entry<String, JsonElement> entry : targetParam.entrySet()) {
param.add(entry.getKey(), entry.getValue());
}
}
if (extraParameters.has("stream")) {
obj.add("stream", extraParameters.get("stream"));
}
data = JsonUtils.GSON.toJson(obj);
}
}
Expand Down Expand Up @@ -650,7 +657,7 @@ static Options getOptions() {
Option.builder()
.longOpt("extra-parameters")
.hasArg()
.argName("extra-parameters")
.argName("EXTRA-PARAMETERS")
.desc("extra parameters for json dataset")
.build());
options.addOption(
Expand Down
13 changes: 13 additions & 0 deletions awscurl/src/test/java/ai/djl/awscurl/AwsCurlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ public void testDataset() {
ret = AwsCurl.run(args);
Assert.assertFalse(ret.hasError());

args =
new String[] {
"http://localhost:18080/invocations",
"-H",
"Content-Type: application/json",
"--dataset",
"src/test/resources/prompts",
"--extra-parameters",
"{\"parameters\": {\"top_k\": 25}, \"stream\": true}"
};
ret = AwsCurl.run(args);
Assert.assertFalse(ret.hasError());

args =
new String[] {
"http://localhost:18080/invocations",
Expand Down
Loading