Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Jan 10, 2024
1 parent 6034579 commit 6ec089e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public TransportBulkAction(
IndexingPressure indexingPressure,
SystemIndices systemIndices,
LongSupplier relativeTimeProvider,
InferenceProvider inferenceProvider) {
InferenceProvider inferenceProvider
) {
this(
BulkAction.INSTANCE,
BulkRequest::new,
Expand Down Expand Up @@ -849,45 +850,46 @@ private void performInferenceOnBulkItemRequest(
@Override
public void onResponse(List<InferenceResults> results) {

if (results == null) {
throw new IllegalArgumentException(
"No inference retrieved for model ID " + modelId + " in document " + docWriteRequest.id()
);
if (results == null) {
throw new IllegalArgumentException(
"No inference retrieved for model ID " + modelId + " in document " + docWriteRequest.id()
);
}

int i = 0;
for (InferenceResults inferenceResults : results) {
String fieldName = inferenceFieldNames.get(i++);
@SuppressWarnings("unchecked")
Map<String, Object> inferenceFieldMap = (Map<String, Object>) rootInferenceFieldMap.computeIfAbsent(
fieldName,
k -> new HashMap<String, Object>()
);

inferenceFieldMap.put(INFERENCE_FIELD, inferenceResults.asMap("output").get("output"));
inferenceFieldMap.put(TEXT_FIELD, docMap.get(fieldName));
}

docRef.close();
}

int i = 0;
for (InferenceResults inferenceResults : results) {
String fieldName = inferenceFieldNames.get(i++);
@SuppressWarnings("unchecked")
Map<String, Object> inferenceFieldMap = (Map<String, Object>) rootInferenceFieldMap.computeIfAbsent(
fieldName,
k -> new HashMap<String, Object>()
@Override
public void onFailure(Exception e) {

final String indexName = request.index();
DocWriteRequest<?> docWriteRequest = request.request();
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(
indexName,
docWriteRequest.id(),
new IllegalArgumentException("Error performing inference: " + e.getMessage(), e)
);
responses.set(request.id(), BulkItemResponse.failure(request.id(), docWriteRequest.opType(), failure));
// make sure the request gets never processed again
bulkShardRequest.items()[request.id()] = null;

inferenceFieldMap.put(INFERENCE_FIELD, inferenceResults.asMap("output").get("output"));
inferenceFieldMap.put(TEXT_FIELD, docMap.get(fieldName));
docRef.close();
}

docRef.close();
}

@Override
public void onFailure(Exception e) {

final String indexName = request.index();
DocWriteRequest<?> docWriteRequest = request.request();
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(
indexName,
docWriteRequest.id(),
new IllegalArgumentException("Error performing inference: " + e.getMessage(), e)
);
responses.set(request.id(), BulkItemResponse.failure(request.id(), docWriteRequest.opType(), failure));
// make sure the request gets never processed again
bulkShardRequest.items()[request.id()] = null;

docRef.close();
}
});
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,15 @@ private void expectInferenceRequest(String modelId, String... inferenceTexts) {
List<String> texts = (List<String>) invocation.getArguments()[1];
var listener = (ActionListener<List<InferenceResults>>) invocation.getArguments()[2];
listener.onResponse(
texts
.stream()
.map(
text -> new TestInferenceResults(
"test_field",
randomMap(
1,
10,
() -> new Tuple<>(randomAlphaOfLengthBetween(1, 10), randomFloat())
)
)
).collect(Collectors.toList()));
texts.stream()
.map(
text -> new TestInferenceResults(
"test_field",
randomMap(1, 10, () -> new Tuple<>(randomAlphaOfLengthBetween(1, 10), randomFloat()))
)
)
.collect(Collectors.toList())
);
return Void.TYPE;
}).when(inferenceProvider)
.textInference(eq(modelId), argThat(texts -> texts.containsAll(Arrays.stream(inferenceTexts).toList())), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ static class TestTransportBulkAction extends TransportBulkAction {
new IndexingPressure(Settings.EMPTY),
EmptySystemIndices.INSTANCE,
relativeTimeProvider,
null);
null
);
}
}
}

0 comments on commit 6ec089e

Please sign in to comment.