Skip to content

Commit 5e7b562

Browse files
committed
CLI and error messages
1 parent 2220e89 commit 5e7b562

15 files changed

Lines changed: 86 additions & 66 deletions

‎src/main/java/com/mindee/MindeeException.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
public class MindeeException extends RuntimeException {
77

8-
public MindeeException(String errorMessage, Throwable err) {
9-
super(errorMessage, err);
8+
public MindeeException(String message, Throwable cause) {
9+
super(message, cause);
1010
}
1111

12-
public MindeeException(String errorMessage) {
13-
super(errorMessage);
12+
public MindeeException(String message) {
13+
super(message);
1414
}
1515
}

‎src/main/java/com/mindee/v2/MindeeClient.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ private <TResponse extends CommonResponse> TResponse pollAndFetch(
280280
attempts++;
281281
}
282282

283-
ErrorResponse error = resp.getJob().getError();
284-
if (error != null) {
285-
throw new MindeeHttpExceptionV2(error.getStatus(), error.getDetail());
283+
ErrorResponse errorResponse = resp.getJob().getError();
284+
if (errorResponse != null) {
285+
throw new MindeeHttpExceptionV2(errorResponse);
286286
}
287287
throw new RuntimeException("Max retries exceeded (" + max + ").");
288288
}

‎src/main/java/com/mindee/v2/cli/BaseCommand.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import picocli.CommandLine;
88

99
/**
10-
* Abstract base class for V2 inference CLI commands.
11-
* Handles common options (path, model-id, api-key, alias, output) and output formatting.
10+
* Abstract base class for all V2 CLI commands.
11+
* Handles common options and output formatting.
1212
*/
1313
public abstract class BaseCommand implements Callable<Integer> {
14-
@CommandLine.Option(names = { "-k", "--api-key" }, description = "Mindee V2 API key.")
14+
@CommandLine.Option(
15+
names = { "-k", "--api-key" },
16+
description = "Mindee V2 API key.",
17+
defaultValue = ""
18+
)
1519
protected String apiKey;
1620

1721
/** Output format for the command. */
@@ -24,8 +28,8 @@ public enum OutputType {
2428
@CommandLine.Option(
2529
names = { "-o", "--output" },
2630
description = "Specify how to output the data.\n"
27-
+ "- summary: a basic summary (default)\n"
28-
+ "- full: detail extraction results, including options\n"
31+
+ "- summary: basic formatted response (default)\n"
32+
+ "- full: complete formatted response\n"
2933
+ "- raw: full JSON object",
3034
defaultValue = "summary"
3135
)
@@ -38,7 +42,7 @@ public enum OutputType {
3842
* @param response the response
3943
* @return the summary string
4044
*/
41-
protected abstract String getSummary(CommonResponse response);
45+
protected abstract String getSummaryOutput(CommonResponse response);
4246

4347
/**
4448
* Returns the full string for the given response.
@@ -62,7 +66,7 @@ protected void printOutput(CommonResponse response) throws Exception {
6266
System.out.println(mapper.writeValueAsString(jsonNode));
6367
break;
6468
default:
65-
System.out.println(getSummary(response));
69+
System.out.println(getSummaryOutput(response));
6670
break;
6771
}
6872
}

‎src/main/java/com/mindee/v2/cli/BaseInferenceCommand.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public abstract class BaseInferenceCommand extends BaseCommand {
2020
@Option(names = { "-m", "--model-id" }, description = "ID of the model to use", required = true)
2121
protected String modelId;
2222

23-
@Option(names = { "-a", "--alias" }, description = "Alias for the file")
23+
@Option(
24+
names = { "-a", "--alias" },
25+
description = "A free-form string to tag the request with your own identifier."
26+
)
2427
protected String alias;
2528

2629
@Option(
@@ -51,7 +54,7 @@ protected abstract CommonResponse executeRequest(
5154

5255
@Override
5356
public Integer call() throws Exception {
54-
var client = new MindeeClient(String.valueOf(apiKey));
57+
var client = new MindeeClient(apiKey);
5558
var inputSource = new LocalInputSource(file);
5659
var response = executeRequest(client, inputSource);
5760
printOutput(response);

‎src/main/java/com/mindee/v2/cli/ClassificationCommand.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import picocli.CommandLine.Command;
99

1010
/**
11-
* CLI command for the V2 classification utility.
11+
* CLI command for the V2 classification product.
1212
*/
1313
@Command(
1414
name = "classification",
15-
description = "Classification utility.",
15+
description = "Classification product.",
1616
mixinStandardHelpOptions = true
1717
)
1818
public class ClassificationCommand extends BaseInferenceCommand {
@@ -31,7 +31,7 @@ protected CommonResponse executeRequest(
3131
}
3232

3333
@Override
34-
protected String getSummary(CommonResponse response) {
34+
protected String getSummaryOutput(CommonResponse response) {
3535
return ((ClassificationResponse) response).getInference().getResult().toString();
3636
}
3737

‎src/main/java/com/mindee/v2/cli/CropCommand.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import picocli.CommandLine.Command;
99

1010
/**
11-
* CLI command for the V2 crop utility.
11+
* CLI command for the V2 crop product.
1212
*/
13-
@Command(name = "crop", description = "Crop utility.", mixinStandardHelpOptions = true)
13+
@Command(name = "crop", description = "Crop product.", mixinStandardHelpOptions = true)
1414
public class CropCommand extends BaseInferenceCommand {
1515

1616
@Override
@@ -27,7 +27,7 @@ protected CommonResponse executeRequest(
2727
}
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((CropResponse) response).getInference().getResult().toString();
3232
}
3333

‎src/main/java/com/mindee/v2/cli/ExtractionCommand.java‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111
import picocli.CommandLine.Option;
1212

1313
/**
14-
* CLI command for the V2 generic all-purpose extraction utility.
14+
* CLI command for the V2 extraction product.
1515
*/
16-
@Command(
17-
name = "extraction",
18-
description = "Generic all-purpose extraction.",
19-
mixinStandardHelpOptions = true
20-
)
16+
@Command(name = "extraction", description = "Extraction product.", mixinStandardHelpOptions = true)
2117
public class ExtractionCommand extends BaseInferenceCommand {
2218

2319
@Option(
2420
names = { "-g", "--rag" },
25-
description = "Enable RAG context. Only valid for 'extraction' product.",
21+
description = "Enable RAG context. False by default.",
2622
defaultValue = "false"
2723
)
2824
private boolean rag;
@@ -77,7 +73,7 @@ protected CommonResponse executeRequest(
7773
}
7874

7975
@Override
80-
protected String getSummary(CommonResponse response) {
76+
protected String getSummaryOutput(CommonResponse response) {
8177
return ((ExtractionResponse) response).getInference().getResult().toString();
8278
}
8379

‎src/main/java/com/mindee/v2/cli/OcrCommand.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import picocli.CommandLine.Command;
99

1010
/**
11-
* CLI command for the V2 OCR utility.
11+
* CLI command for the V2 OCR product.
1212
*/
13-
@Command(name = "ocr", description = "OCR utility.", mixinStandardHelpOptions = true)
13+
@Command(name = "ocr", description = "OCR product.", mixinStandardHelpOptions = true)
1414
public class OcrCommand extends BaseInferenceCommand {
1515

1616
@Override
@@ -27,7 +27,7 @@ protected CommonResponse executeRequest(
2727
}
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((OcrResponse) response).getInference().getResult().toString();
3232
}
3333

‎src/main/java/com/mindee/v2/cli/SearchModelsCommand.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ public enum ModelType {
3939

4040
@Override
4141
public Integer call() throws Exception {
42-
var client = new MindeeClient(String.valueOf(apiKey));
42+
var client = new MindeeClient(apiKey);
4343
var response = client
4444
.search(
4545
ModelSearchResponse.class,
46-
ModelSearchParameters.builder().name(name).modelType(String.valueOf(modelType)).build()
46+
ModelSearchParameters
47+
.builder()
48+
.name(name)
49+
.modelType(modelType != null ? modelType.name() : null)
50+
.build()
4751
);
4852
printOutput(response);
4953
return 0;
5054
}
5155

5256
@Override
53-
protected String getSummary(CommonResponse response) {
57+
protected String getSummaryOutput(CommonResponse response) {
5458
return ((ModelSearchResponse) response).getModels().toString();
5559
}
5660

‎src/main/java/com/mindee/v2/cli/SearchRagDocumentsCommand.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SearchRagDocumentsCommand extends BaseCommand {
2727
private String filename;
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((RagDocumentSearchResponse) response).getRagDocuments().toString();
3232
}
3333

@@ -38,11 +38,14 @@ protected String getFullOutput(CommonResponse response) {
3838

3939
@Override
4040
public Integer call() throws Exception {
41-
var client = new MindeeClient(String.valueOf(apiKey));
41+
var client = new MindeeClient(apiKey);
4242
var response = client
4343
.search(
4444
RagDocumentSearchResponse.class,
45-
RagDocumentSearchParameters.builder(modelId).filename(filename).build()
45+
RagDocumentSearchParameters
46+
.builder(modelId)
47+
.filename(filename != null ? filename : null)
48+
.build()
4649
);
4750
printOutput(response);
4851
return 0;

0 commit comments

Comments
 (0)