Skip to content

Commit 2220e89

Browse files
committed
will it blend?
1 parent d9a6c9f commit 2220e89

10 files changed

Lines changed: 167 additions & 130 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.mindee.v2.cli.ExtractionCommand;
88
import com.mindee.v2.cli.OcrCommand;
99
import com.mindee.v2.cli.SearchModelsCommand;
10+
import com.mindee.v2.cli.SearchRagDocumentsCommand;
1011
import com.mindee.v2.cli.SplitCommand;
1112
import java.lang.reflect.Method;
1213
import picocli.CommandLine;
@@ -42,6 +43,7 @@ public static void main(String[] args) {
4243

4344
// V2 commands at root
4445
rootCmd.addSubcommand("search-models", new CommandLine(new SearchModelsCommand()));
46+
rootCmd.addSubcommand("search-rag-docs", new CommandLine(new SearchRagDocumentsCommand()));
4547
rootCmd.addSubcommand("classification", new CommandLine(new ClassificationCommand()));
4648
rootCmd.addSubcommand("crop", new CommandLine(new CropCommand()));
4749
rootCmd.addSubcommand("extraction", new CommandLine(new ExtractionCommand()));

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.mindee.v2.parsing.search.BaseSearchResponse;
1515
import com.mindee.v2.parsing.search.SearchResponse;
1616
import com.mindee.v2.product.extraction.ExtractionResponse;
17+
import com.mindee.v2.search.models.ModelSearchParameters;
1718
import java.io.IOException;
1819
import java.util.concurrent.CancellationException;
1920

@@ -213,7 +214,7 @@ public <TSearchResponse extends BaseSearchResponse> TSearchResponse search(
213214
*/
214215
@Deprecated
215216
public SearchResponse searchModels() {
216-
return searchModels(null, null);
217+
return search(SearchResponse.class, null);
217218
}
218219

219220
/**
@@ -225,7 +226,7 @@ public SearchResponse searchModels() {
225226
*/
226227
@Deprecated
227228
public SearchResponse searchModels(String modelName) {
228-
return searchModels(modelName, null);
229+
return search(SearchResponse.class, ModelSearchParameters.builder().name(modelName).build());
229230
}
230231

231232
/**
@@ -238,7 +239,10 @@ public SearchResponse searchModels(String modelName) {
238239
*/
239240
@Deprecated
240241
public SearchResponse searchModels(String modelName, String modelType) {
241-
return mindeeApi.reqGetSearchModels(modelName, modelType);
242+
return search(
243+
SearchResponse.class,
244+
ModelSearchParameters.builder().name(modelName).modelType(modelType).build()
245+
);
242246
}
243247

244248
/**
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mindee.v2.cli;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.SerializationFeature;
5+
import com.mindee.v2.parsing.CommonResponse;
6+
import java.util.concurrent.Callable;
7+
import picocli.CommandLine;
8+
9+
/**
10+
* Abstract base class for V2 inference CLI commands.
11+
* Handles common options (path, model-id, api-key, alias, output) and output formatting.
12+
*/
13+
public abstract class BaseCommand implements Callable<Integer> {
14+
@CommandLine.Option(names = { "-k", "--api-key" }, description = "Mindee V2 API key.")
15+
protected String apiKey;
16+
17+
/** Output format for the command. */
18+
public enum OutputType {
19+
summary,
20+
full,
21+
raw
22+
}
23+
24+
@CommandLine.Option(
25+
names = { "-o", "--output" },
26+
description = "Specify how to output the data.\n"
27+
+ "- summary: a basic summary (default)\n"
28+
+ "- full: detail extraction results, including options\n"
29+
+ "- raw: full JSON object",
30+
defaultValue = "summary"
31+
)
32+
protected OutputType output;
33+
34+
/**
35+
* Returns the summary string for the given response.
36+
* Override in each command.
37+
*
38+
* @param response the response
39+
* @return the summary string
40+
*/
41+
protected abstract String getSummary(CommonResponse response);
42+
43+
/**
44+
* Returns the full string for the given response.
45+
*
46+
* @param response the product response
47+
* @return the full output string
48+
*/
49+
protected abstract String getFullOutput(CommonResponse response);
50+
51+
/**
52+
* Prints the output to the console, taking into account the output type.
53+
*/
54+
protected void printOutput(CommonResponse response) throws Exception {
55+
switch (output) {
56+
case full:
57+
System.out.println(getFullOutput(response));
58+
break;
59+
case raw:
60+
var mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
61+
var jsonNode = mapper.readTree(response.getRawResponse());
62+
System.out.println(mapper.writeValueAsString(jsonNode));
63+
break;
64+
default:
65+
System.out.println(getSummary(response));
66+
break;
67+
}
68+
}
69+
}
Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
package com.mindee.v2.cli;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.fasterxml.jackson.databind.SerializationFeature;
53
import com.mindee.input.LocalInputSource;
64
import com.mindee.v2.MindeeClient;
75
import com.mindee.v2.parsing.CommonResponse;
86
import java.io.File;
97
import java.util.List;
10-
import java.util.concurrent.Callable;
118
import picocli.CommandLine.Option;
129
import picocli.CommandLine.Parameters;
1310

1411
/**
1512
* Abstract base class for V2 inference CLI commands.
1613
* Handles common options (path, model-id, api-key, alias, output) and output formatting.
1714
*/
18-
public abstract class BaseInferenceCommand implements Callable<Integer> {
15+
public abstract class BaseInferenceCommand extends BaseCommand {
1916

2017
@Parameters(index = "0", paramLabel = "<path>", description = "The path of the file to parse")
2118
protected File file;
2219

2320
@Option(names = { "-m", "--model-id" }, description = "ID of the model to use", required = true)
2421
protected String modelId;
2522

26-
@Option(names = { "-k", "--api-key" }, description = "Mindee V2 API key.")
27-
protected String apiKey;
28-
2923
@Option(names = { "-a", "--alias" }, description = "Alias for the file")
3024
protected String alias;
3125

@@ -35,23 +29,6 @@ public abstract class BaseInferenceCommand implements Callable<Integer> {
3529
)
3630
private List<String> webhookIds;
3731

38-
/** Output format for the command. */
39-
public enum OutputType {
40-
summary,
41-
full,
42-
raw
43-
}
44-
45-
@Option(
46-
names = { "-o", "--output" },
47-
description = "Specify how to output the data.\n"
48-
+ "- summary: a basic summary (default)\n"
49-
+ "- full: detail extraction results, including options\n"
50-
+ "- raw: full JSON object",
51-
defaultValue = "summary"
52-
)
53-
protected OutputType output;
54-
5532
/**
5633
* @return The properly formatted webhook IDs.
5734
*/
@@ -72,48 +49,12 @@ protected abstract CommonResponse executeRequest(
7249
LocalInputSource inputSource
7350
) throws Exception;
7451

75-
/**
76-
* Returns the summary (result-only) string for the given response.
77-
* Override in each product command.
78-
*
79-
* @param response the product response
80-
* @return the summary string
81-
*/
82-
protected abstract String getSummary(CommonResponse response);
83-
84-
/**
85-
* Returns the full (inference + options + result) string for the given response.
86-
* Defaults to the same as {@link #getSummary}; override for richer output.
87-
*
88-
* @param response the product response
89-
* @return the full output string
90-
*/
91-
protected String getFullOutput(CommonResponse response) {
92-
return getSummary(response);
93-
}
94-
9552
@Override
9653
public Integer call() throws Exception {
97-
var client = new MindeeClient(apiKey != null ? apiKey : "");
54+
var client = new MindeeClient(String.valueOf(apiKey));
9855
var inputSource = new LocalInputSource(file);
9956
var response = executeRequest(client, inputSource);
10057
printOutput(response);
10158
return 0;
10259
}
103-
104-
private void printOutput(CommonResponse response) throws Exception {
105-
switch (output) {
106-
case full:
107-
System.out.println(getFullOutput(response));
108-
break;
109-
case raw:
110-
var mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
111-
var jsonNode = mapper.readTree(response.getRawResponse());
112-
System.out.println(mapper.writeValueAsString(jsonNode));
113-
break;
114-
default:
115-
System.out.println(getSummary(response));
116-
break;
117-
}
118-
}
11960
}
Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.mindee.v2.cli;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.fasterxml.jackson.databind.SerializationFeature;
53
import com.mindee.v2.MindeeClient;
6-
import java.util.concurrent.Callable;
4+
import com.mindee.v2.parsing.CommonResponse;
5+
import com.mindee.v2.search.models.ModelSearchParameters;
6+
import com.mindee.v2.search.models.ModelSearchResponse;
77
import picocli.CommandLine.Command;
88
import picocli.CommandLine.Option;
99

@@ -15,41 +15,47 @@
1515
description = "Search available models.",
1616
mixinStandardHelpOptions = true
1717
)
18-
public class SearchModelsCommand implements Callable<Integer> {
19-
20-
@Option(names = { "-k", "--api-key" }, description = "Mindee V2 API key.")
21-
private String apiKey;
18+
public class SearchModelsCommand extends BaseCommand {
2219

2320
@Option(
2421
names = { "-n", "--name" },
2522
description = "Filter by model name partial match (case insensitive)."
2623
)
2724
private String name;
2825

29-
@Option(
30-
names = { "-m", "--model-type" },
31-
description = "Filter by exact model type (case sensitive)."
32-
)
33-
private String modelType;
26+
public enum ModelType {
27+
extraction,
28+
crop,
29+
classification,
30+
ocr,
31+
split
32+
}
3433

3534
@Option(
36-
names = { "-r", "--raw-json" },
37-
description = "Whether to output the raw JSON response.",
38-
defaultValue = "false"
35+
names = { "-m", "--model-type" },
36+
description = "Filter by exact model type.%nAvailable options: ${COMPLETION-CANDIDATES}"
3937
)
40-
private boolean rawJson;
38+
private ModelType modelType;
4139

4240
@Override
4341
public Integer call() throws Exception {
44-
var client = new MindeeClient(apiKey != null ? apiKey : "");
45-
var response = client.searchModels(name, modelType);
46-
if (rawJson) {
47-
var mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
48-
var jsonNode = mapper.readTree(response.getRawResponse());
49-
System.out.println(mapper.writeValueAsString(jsonNode));
50-
} else {
51-
System.out.println(response);
52-
}
42+
var client = new MindeeClient(String.valueOf(apiKey));
43+
var response = client
44+
.search(
45+
ModelSearchResponse.class,
46+
ModelSearchParameters.builder().name(name).modelType(String.valueOf(modelType)).build()
47+
);
48+
printOutput(response);
5349
return 0;
5450
}
51+
52+
@Override
53+
protected String getSummary(CommonResponse response) {
54+
return ((ModelSearchResponse) response).getModels().toString();
55+
}
56+
57+
@Override
58+
protected String getFullOutput(CommonResponse response) {
59+
return response.toString();
60+
}
5561
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.mindee.v2.cli;
2+
3+
import com.mindee.v2.MindeeClient;
4+
import com.mindee.v2.parsing.CommonResponse;
5+
import com.mindee.v2.search.ragdocuments.RagDocumentSearchParameters;
6+
import com.mindee.v2.search.ragdocuments.RagDocumentSearchResponse;
7+
import picocli.CommandLine.Command;
8+
import picocli.CommandLine.Option;
9+
10+
/**
11+
* CLI command for searching available V2 RAG documents.
12+
*/
13+
@Command(
14+
name = "search-rag-docs",
15+
description = "Search available RAG documents for a given model.",
16+
mixinStandardHelpOptions = true
17+
)
18+
public class SearchRagDocumentsCommand extends BaseCommand {
19+
20+
@Option(names = { "-m", "--model-id" }, description = "Filter by model ID.", required = true)
21+
private String modelId;
22+
23+
@Option(
24+
names = { "-f", "--filename" },
25+
description = "Filter by model name partial match (case insensitive)."
26+
)
27+
private String filename;
28+
29+
@Override
30+
protected String getSummary(CommonResponse response) {
31+
return ((RagDocumentSearchResponse) response).getRagDocuments().toString();
32+
}
33+
34+
@Override
35+
protected String getFullOutput(CommonResponse response) {
36+
return response.toString();
37+
}
38+
39+
@Override
40+
public Integer call() throws Exception {
41+
var client = new MindeeClient(String.valueOf(apiKey));
42+
var response = client
43+
.search(
44+
RagDocumentSearchResponse.class,
45+
RagDocumentSearchParameters.builder(modelId).filename(filename).build()
46+
);
47+
printOutput(response);
48+
return 0;
49+
}
50+
}

0 commit comments

Comments
 (0)