Skip to content

Commit 7eabd29

Browse files
committed
PR feedback
1 parent 6cf0c0b commit 7eabd29

File tree

6 files changed

+16
-176
lines changed

6 files changed

+16
-176
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiChatCompletionResponseHandler.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/GoogleVertexAiStreamingProcessor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.inference.services.googlevertexai;
99

1010
import org.elasticsearch.ElasticsearchStatusException;
11+
import org.elasticsearch.common.Strings;
1112
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1213
import org.elasticsearch.inference.InferenceServiceResults;
1314
import org.elasticsearch.rest.RestStatus;
@@ -44,17 +45,14 @@ protected void next(Deque<ServerSentEvent> item) throws Exception {
4445
public static Stream<StreamingChatCompletionResults.Result> parse(XContentParserConfiguration parserConfig, ServerSentEvent event) {
4546
String data = event.data();
4647
try (XContentParser jsonParser = XContentFactory.xContent(XContentType.JSON).createParser(parserConfig, data)) {
47-
moveToFirstToken(jsonParser);
48-
ensureExpectedToken(XContentParser.Token.START_OBJECT, jsonParser.currentToken(), jsonParser);
49-
5048
var chunk = GoogleVertexAiUnifiedStreamingProcessor.GoogleVertexAiChatCompletionChunkParser.parse(jsonParser);
5149

5250
return chunk.choices()
5351
.stream()
5452
.map(choice -> choice.delta())
5553
.filter(Objects::nonNull)
5654
.map(delta -> delta.content())
57-
.filter(content -> content != null && content.isEmpty() == false)
55+
.filter(content -> Strings.isNullOrEmpty(content) == false)
5856
.map(StreamingChatCompletionResults.Result::new);
5957

6058
} catch (IOException e) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/action/GoogleVertexAiActionCreator.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
import org.elasticsearch.xpack.inference.external.http.sender.Sender;
1919
import org.elasticsearch.xpack.inference.external.http.sender.UnifiedChatInput;
2020
import org.elasticsearch.xpack.inference.services.ServiceComponents;
21-
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiChatCompletionResponseHandler;
2221
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiEmbeddingsRequestManager;
2322
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiRerankRequestManager;
23+
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiResponseHandler;
2424
import org.elasticsearch.xpack.inference.services.googlevertexai.GoogleVertexAiUnifiedChatCompletionResponseHandler;
2525
import org.elasticsearch.xpack.inference.services.googlevertexai.completion.GoogleVertexAiChatCompletionModel;
2626
import org.elasticsearch.xpack.inference.services.googlevertexai.completion.GoogleVertexAiCompletionModel;
2727
import org.elasticsearch.xpack.inference.services.googlevertexai.embeddings.GoogleVertexAiEmbeddingsModel;
2828
import org.elasticsearch.xpack.inference.services.googlevertexai.request.GoogleVertexAiUnifiedChatCompletionRequest;
2929
import org.elasticsearch.xpack.inference.services.googlevertexai.rerank.GoogleVertexAiRerankModel;
30+
import org.elasticsearch.xpack.inference.services.googlevertexai.response.GoogleVertexAiCompletionResponseEntity;
3031

3132
import java.net.URISyntaxException;
3233
import java.util.Map;
@@ -41,10 +42,17 @@ public class GoogleVertexAiActionCreator implements GoogleVertexAiActionVisitor
4142

4243
private final ServiceComponents serviceComponents;
4344

44-
static final ResponseHandler UNIFIED_CHAT_COMPLETION_HANDLER = new GoogleVertexAiUnifiedChatCompletionResponseHandler(
45+
static final ResponseHandler COMPLETION_HANDLER = new GoogleVertexAiUnifiedChatCompletionResponseHandler(
4546
"Google VertexAI chat completion"
4647
);
47-
static final ResponseHandler CHAT_COMPLETION_HANDLER = new GoogleVertexAiChatCompletionResponseHandler("Google VertexAI completion");
48+
49+
static final ResponseHandler CHAT_COMPLETION_HANDLER = new GoogleVertexAiResponseHandler(
50+
"Google VertexAI completion",
51+
GoogleVertexAiCompletionResponseEntity::fromResponse,
52+
GoogleVertexAiUnifiedChatCompletionResponseHandler.GoogleVertexAiErrorResponse::fromResponse,
53+
true
54+
);
55+
4856
static final String USER_ROLE = "user";
4957

5058
public GoogleVertexAiActionCreator(Sender sender, ServiceComponents serviceComponents) {
@@ -78,7 +86,7 @@ public ExecutableAction create(GoogleVertexAiChatCompletionModel model, Map<Stri
7886
var manager = new GenericRequestManager<>(
7987
serviceComponents.threadPool(),
8088
model,
81-
UNIFIED_CHAT_COMPLETION_HANDLER,
89+
COMPLETION_HANDLER,
8290
inputs -> new GoogleVertexAiUnifiedChatCompletionRequest(new UnifiedChatInput(inputs, USER_ROLE), model),
8391
ChatCompletionInput.class
8492
);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/completion/GoogleVertexAiCompletionModel.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/action/GoogleVertexAiUnifiedChatCompletionActionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import static org.elasticsearch.xpack.inference.Utils.inferenceUtilityPool;
3939
import static org.elasticsearch.xpack.inference.Utils.mockClusterServiceEmpty;
4040
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.constructFailedToSendRequestMessage;
41-
import static org.elasticsearch.xpack.inference.services.googlevertexai.action.GoogleVertexAiActionCreator.UNIFIED_CHAT_COMPLETION_HANDLER;
41+
import static org.elasticsearch.xpack.inference.services.googlevertexai.action.GoogleVertexAiActionCreator.COMPLETION_HANDLER;
4242
import static org.elasticsearch.xpack.inference.services.googlevertexai.action.GoogleVertexAiActionCreator.USER_ROLE;
4343
import static org.hamcrest.Matchers.is;
4444
import static org.mockito.ArgumentMatchers.any;
@@ -130,7 +130,7 @@ private ExecutableAction createAction(String location, String projectId, String
130130
var manager = new GenericRequestManager<>(
131131
threadPool,
132132
model,
133-
UNIFIED_CHAT_COMPLETION_HANDLER,
133+
COMPLETION_HANDLER,
134134
inputs -> new GoogleVertexAiUnifiedChatCompletionRequest(new UnifiedChatInput(inputs, USER_ROLE), model),
135135
ChatCompletionInput.class
136136
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/completion/GoogleVertexAiCompletionModelTests.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)